More clippy fixing.

This commit is contained in:
ClementTsang 2020-02-10 19:44:26 -05:00
parent f21c06f8ed
commit a7025aca4a
5 changed files with 28 additions and 29 deletions

View File

@ -97,19 +97,19 @@ impl DataCollection {
let mut new_entry = TimedData::default(); let mut new_entry = TimedData::default();
// Network // Network
self.eat_network(&harvested_data, &harvested_time, &mut new_entry); self.eat_network(&harvested_data, harvested_time, &mut new_entry);
// Memory and Swap // Memory and Swap
self.eat_memory_and_swap(&harvested_data, &harvested_time, &mut new_entry); self.eat_memory_and_swap(&harvested_data, harvested_time, &mut new_entry);
// CPU // CPU
self.eat_cpu(&harvested_data, &harvested_time, &mut new_entry); self.eat_cpu(&harvested_data, harvested_time, &mut new_entry);
// Temp // Temp
self.eat_temp(&harvested_data); self.eat_temp(&harvested_data);
// Disks // Disks
self.eat_disks(&harvested_data, &harvested_time); self.eat_disks(&harvested_data, harvested_time);
// Processes // Processes
self.eat_proc(&harvested_data); self.eat_proc(&harvested_data);
@ -120,14 +120,14 @@ impl DataCollection {
} }
fn eat_memory_and_swap( fn eat_memory_and_swap(
&mut self, harvested_data: &Data, harvested_time: &Instant, new_entry: &mut TimedData, &mut self, harvested_data: &Data, harvested_time: Instant, new_entry: &mut TimedData,
) { ) {
// Memory // Memory
let mem_percent = harvested_data.memory.mem_used_in_mb as f64 let mem_percent = harvested_data.memory.mem_used_in_mb as f64
/ harvested_data.memory.mem_total_in_mb as f64 / harvested_data.memory.mem_total_in_mb as f64
* 100.0; * 100.0;
let mem_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { let mem_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() {
generate_joining_points(&time, last_pt.mem_data.0, &harvested_time, mem_percent) generate_joining_points(*time, last_pt.mem_data.0, harvested_time, mem_percent)
} else { } else {
Vec::new() Vec::new()
}; };
@ -140,7 +140,7 @@ impl DataCollection {
/ harvested_data.swap.mem_total_in_mb as f64 / harvested_data.swap.mem_total_in_mb as f64
* 100.0; * 100.0;
let swap_joining_pt = if let Some((time, last_pt)) = self.timed_data_vec.last() { let swap_joining_pt = if let Some((time, last_pt)) = self.timed_data_vec.last() {
generate_joining_points(&time, last_pt.swap_data.0, &harvested_time, swap_percent) generate_joining_points(*time, last_pt.swap_data.0, harvested_time, swap_percent)
} else { } else {
Vec::new() Vec::new()
}; };
@ -154,7 +154,7 @@ impl DataCollection {
} }
fn eat_network( fn eat_network(
&mut self, harvested_data: &Data, harvested_time: &Instant, new_entry: &mut TimedData, &mut self, harvested_data: &Data, harvested_time: Instant, new_entry: &mut TimedData,
) { ) {
// RX // RX
let logged_rx_val = if harvested_data.network.rx as f64 > 0.0 { let logged_rx_val = if harvested_data.network.rx as f64 > 0.0 {
@ -164,7 +164,7 @@ impl DataCollection {
}; };
let rx_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { let rx_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() {
generate_joining_points(&time, last_pt.rx_data.0, &harvested_time, logged_rx_val) generate_joining_points(*time, last_pt.rx_data.0, harvested_time, logged_rx_val)
} else { } else {
Vec::new() Vec::new()
}; };
@ -179,7 +179,7 @@ impl DataCollection {
}; };
let tx_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { let tx_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() {
generate_joining_points(&time, last_pt.tx_data.0, &harvested_time, logged_tx_val) generate_joining_points(*time, last_pt.tx_data.0, harvested_time, logged_tx_val)
} else { } else {
Vec::new() Vec::new()
}; };
@ -191,7 +191,7 @@ impl DataCollection {
} }
fn eat_cpu( fn eat_cpu(
&mut self, harvested_data: &Data, harvested_time: &Instant, new_entry: &mut TimedData, &mut self, harvested_data: &Data, harvested_time: Instant, new_entry: &mut TimedData,
) { ) {
// Note this only pre-calculates the data points - the names will be // Note this only pre-calculates the data points - the names will be
// within the local copy of cpu_harvest. Since it's all sequential // within the local copy of cpu_harvest. Since it's all sequential
@ -199,9 +199,9 @@ impl DataCollection {
for (itx, cpu) in harvested_data.cpu.iter().enumerate() { for (itx, cpu) in harvested_data.cpu.iter().enumerate() {
let cpu_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { let cpu_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() {
generate_joining_points( generate_joining_points(
&time, *time,
last_pt.cpu_data[itx].0, last_pt.cpu_data[itx].0,
&harvested_time, harvested_time,
cpu.cpu_usage, cpu.cpu_usage,
) )
} else { } else {
@ -220,7 +220,7 @@ impl DataCollection {
self.temp_harvest = harvested_data.temperature_sensors.clone(); self.temp_harvest = harvested_data.temperature_sensors.clone();
} }
fn eat_disks(&mut self, harvested_data: &Data, harvested_time: &Instant) { fn eat_disks(&mut self, harvested_data: &Data, harvested_time: Instant) {
// TODO: [PO] To implement // TODO: [PO] To implement
let time_since_last_harvest = harvested_time let time_since_last_harvest = harvested_time
@ -262,12 +262,12 @@ impl DataCollection {
} }
pub fn generate_joining_points( pub fn generate_joining_points(
start_x: &Instant, start_y: f64, end_x: &Instant, end_y: f64, start_x: Instant, start_y: f64, end_x: Instant, end_y: f64,
) -> Vec<(TimeOffset, Value)> { ) -> Vec<(TimeOffset, Value)> {
let mut points: Vec<(TimeOffset, Value)> = Vec::new(); let mut points: Vec<(TimeOffset, Value)> = Vec::new();
// Convert time floats first: // Convert time floats first:
let tmp_time_diff = (*end_x).duration_since(*start_x).as_millis() as f64; let tmp_time_diff = (end_x).duration_since(start_x).as_millis() as f64;
let time_difference = if tmp_time_diff == 0.0 { let time_difference = if tmp_time_diff == 0.0 {
0.001 0.001
} else { } else {

View File

@ -118,10 +118,10 @@ impl DataState {
// Network // Network
self.data.network = network::get_network_data( self.data.network = network::get_network_data(
&self.sys, &self.sys,
&self.data.last_collection_time, self.data.last_collection_time,
&mut self.data.network.total_rx, &mut self.data.network.total_rx,
&mut self.data.network.total_tx, &mut self.data.network.total_tx,
&current_instant, current_instant,
) )
.await; .await;
@ -160,7 +160,7 @@ impl DataState {
&mut self.prev_pid_stats, &mut self.prev_pid_stats,
self.use_current_cpu_total, self.use_current_cpu_total,
self.mem_total_kb, self.mem_total_kb,
&current_instant, current_instant,
), ),
&mut self.data.list_of_processes, &mut self.data.list_of_processes,
); );

View File

@ -20,8 +20,8 @@ impl NetworkHarvest {
} }
pub async fn get_network_data( pub async fn get_network_data(
sys: &System, prev_net_access_time: &Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64, sys: &System, prev_net_access_time: Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64,
curr_time: &Instant, curr_time: Instant,
) -> NetworkHarvest { ) -> NetworkHarvest {
let mut io_data = net::io_counters(); let mut io_data = net::io_counters();
let mut total_rx: u64 = 0; let mut total_rx: u64 = 0;
@ -42,9 +42,7 @@ pub async fn get_network_data(
} }
} }
let elapsed_time = curr_time let elapsed_time = curr_time.duration_since(prev_net_access_time).as_secs_f64();
.duration_since(*prev_net_access_time)
.as_secs_f64();
let rx = ((total_rx - *prev_net_rx) as f64 / elapsed_time) as u64; let rx = ((total_rx - *prev_net_rx) as f64 / elapsed_time) as u64;
let tx = ((total_tx - *prev_net_tx) as f64 / elapsed_time) as u64; let tx = ((total_tx - *prev_net_tx) as f64 / elapsed_time) as u64;

View File

@ -119,13 +119,13 @@ fn linux_cpu_usage<S: core::hash::BuildHasher>(
pid: u32, cpu_usage: f64, cpu_percentage: f64, pid: u32, cpu_usage: f64, cpu_percentage: f64,
prev_pid_stats: &HashMap<String, (f64, Instant), S>, prev_pid_stats: &HashMap<String, (f64, Instant), S>,
new_pid_stats: &mut HashMap<String, (f64, Instant), S>, use_current_cpu_total: bool, new_pid_stats: &mut HashMap<String, (f64, Instant), S>, use_current_cpu_total: bool,
curr_time: &Instant, curr_time: Instant,
) -> std::io::Result<f64> { ) -> std::io::Result<f64> {
// Based heavily on https://stackoverflow.com/a/23376195 and https://stackoverflow.com/a/1424556 // Based heavily on https://stackoverflow.com/a/23376195 and https://stackoverflow.com/a/1424556
let before_proc_val: f64 = if prev_pid_stats.contains_key(&pid.to_string()) { let before_proc_val: f64 = if prev_pid_stats.contains_key(&pid.to_string()) {
prev_pid_stats prev_pid_stats
.get(&pid.to_string()) .get(&pid.to_string())
.unwrap_or(&(0_f64, *curr_time)) .unwrap_or(&(0_f64, curr_time))
.0 .0
} else { } else {
0_f64 0_f64
@ -141,7 +141,7 @@ fn linux_cpu_usage<S: core::hash::BuildHasher>(
(after_proc_val - before_proc_val) / cpu_usage * 100_f64 (after_proc_val - before_proc_val) / cpu_usage * 100_f64
);*/ );*/
new_pid_stats.insert(pid.to_string(), (after_proc_val, *curr_time)); new_pid_stats.insert(pid.to_string(), (after_proc_val, curr_time));
if use_current_cpu_total { if use_current_cpu_total {
Ok((after_proc_val - before_proc_val) / cpu_usage * 100_f64) Ok((after_proc_val - before_proc_val) / cpu_usage * 100_f64)
} else { } else {
@ -153,7 +153,7 @@ fn convert_ps<S: core::hash::BuildHasher>(
process: &str, cpu_usage: f64, cpu_percentage: f64, process: &str, cpu_usage: f64, cpu_percentage: f64,
prev_pid_stats: &HashMap<String, (f64, Instant), S>, prev_pid_stats: &HashMap<String, (f64, Instant), S>,
new_pid_stats: &mut HashMap<String, (f64, Instant), S>, use_current_cpu_total: bool, new_pid_stats: &mut HashMap<String, (f64, Instant), S>, use_current_cpu_total: bool,
curr_time: &Instant, curr_time: Instant,
) -> std::io::Result<ProcessHarvest> { ) -> std::io::Result<ProcessHarvest> {
if process.trim().to_string().is_empty() { if process.trim().to_string().is_empty() {
return Ok(ProcessHarvest { return Ok(ProcessHarvest {
@ -195,7 +195,7 @@ fn convert_ps<S: core::hash::BuildHasher>(
pub fn get_sorted_processes_list( pub fn get_sorted_processes_list(
sys: &System, prev_idle: &mut f64, prev_non_idle: &mut f64, sys: &System, prev_idle: &mut f64, prev_non_idle: &mut f64,
prev_pid_stats: &mut HashMap<String, (f64, Instant), RandomState>, use_current_cpu_total: bool, prev_pid_stats: &mut HashMap<String, (f64, Instant), RandomState>, use_current_cpu_total: bool,
mem_total_kb: u64, curr_time: &Instant, mem_total_kb: u64, curr_time: Instant,
) -> crate::utils::error::Result<Vec<ProcessHarvest>> { ) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
let mut process_vector: Vec<ProcessHarvest> = Vec::new(); let mut process_vector: Vec<ProcessHarvest> = Vec::new();

View File

@ -116,6 +116,7 @@ fn get_matches() -> clap::ArgMatches<'static> {
.get_matches() .get_matches()
} }
#[allow(deprecated)]
fn main() -> error::Result<()> { fn main() -> error::Result<()> {
create_logger()?; create_logger()?;
let matches = get_matches(); let matches = get_matches();