diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/data_collection.rs | 46 | ||||
-rw-r--r-- | src/app/data_collection/processes.rs | 11 |
2 files changed, 43 insertions, 14 deletions
diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index 64a1f024..b44d02d9 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -33,7 +33,7 @@ pub struct Data { pub list_of_temperature_sensor: Vec<temperature::TempData>, pub network: Vec<network::NetworkData>, pub list_of_processes: Vec<processes::ProcessData>, // Only need to keep a list of processes... - pub list_of_disks: Vec<disks::DiskData>, // Only need to keep a list of disks and their data + pub list_of_disks: Vec<disks::DiskData>, // Only need to keep a list of disks and their data } pub struct DataState { @@ -105,7 +105,10 @@ impl DataState { .await, &mut self.data.network, ); - push_if_valid(&cpu::get_cpu_data_list(&self.sys), &mut self.data.list_of_cpu_packages); + push_if_valid( + &cpu::get_cpu_data_list(&self.sys), + &mut self.data.list_of_cpu_packages, + ); push_if_valid(&mem::get_mem_data_list().await, &mut self.data.memory); push_if_valid(&mem::get_swap_data_list().await, &mut self.data.swap); @@ -120,8 +123,14 @@ impl DataState { &mut self.data.list_of_processes, ); - set_if_valid(&disks::get_disk_usage_list().await, &mut self.data.list_of_disks); - push_if_valid(&disks::get_io_usage_list(false).await, &mut self.data.list_of_io); + set_if_valid( + &disks::get_disk_usage_list().await, + &mut self.data.list_of_disks, + ); + push_if_valid( + &disks::get_io_usage_list(false).await, + &mut self.data.list_of_io, + ); set_if_valid( &temperature::get_temperature_data(&self.sys, &self.temperature_type).await, &mut self.data.list_of_temperature_sensor, @@ -139,7 +148,9 @@ impl DataState { let stale_list: Vec<_> = self .prev_pid_stats .iter() - .filter(|&(_, &v)| current_instant.duration_since(v.1).as_secs() > self.stale_max_seconds) + .filter(|&(_, &v)| { + current_instant.duration_since(v.1).as_secs() > self.stale_max_seconds + }) .map(|(k, _)| k.clone()) .collect(); for stale in stale_list { @@ -151,7 +162,10 @@ impl DataState { .list_of_cpu_packages .iter() .cloned() - .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) + .filter(|entry| { + current_instant.duration_since(entry.instant).as_secs() + <= self.stale_max_seconds + }) .collect::<Vec<_>>(); self.data.memory = self @@ -159,7 +173,10 @@ impl DataState { .memory .iter() .cloned() - .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) + .filter(|entry| { + current_instant.duration_since(entry.instant).as_secs() + <= self.stale_max_seconds + }) .collect::<Vec<_>>(); self.data.swap = self @@ -167,7 +184,10 @@ impl DataState { .swap .iter() .cloned() - .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) + .filter(|entry| { + current_instant.duration_since(entry.instant).as_secs() + <= self.stale_max_seconds + }) .collect::<Vec<_>>(); self.data.network = self @@ -175,7 +195,10 @@ impl DataState { .network .iter() .cloned() - .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) + .filter(|entry| { + current_instant.duration_since(entry.instant).as_secs() + <= self.stale_max_seconds + }) .collect::<Vec<_>>(); self.data.list_of_io = self @@ -183,7 +206,10 @@ impl DataState { .list_of_io .iter() .cloned() - .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) + .filter(|entry| { + current_instant.duration_since(entry.instant).as_secs() + <= self.stale_max_seconds + }) .collect::<Vec<_>>(); self.last_clean = current_instant; diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index a8916a8e..6a3ebe80 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -25,6 +25,7 @@ pub struct ProcessData { pub mem_usage_percent: Option<f64>, pub mem_usage_kb: Option<u64>, pub command: String, + pub pid_vec: Option<Vec<u32>>, // Note that this is literally never unless we are in grouping mode. This is to save rewriting time. } fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error::Result<(f64, f64)> { @@ -174,6 +175,7 @@ fn convert_ps( mem_usage_percent: None, mem_usage_kb: None, cpu_usage_percent: 0_f64, + pid_vec: None, }); } @@ -187,6 +189,7 @@ fn convert_ps( mem_usage_percent, mem_usage_kb: None, cpu_usage_percent: linux_cpu_usage(pid, cpu_usage, cpu_percentage, prev_pid_stats, use_current_cpu_total)?, + pid_vec: None, }) } @@ -248,6 +251,7 @@ pub fn get_sorted_processes_list( mem_usage_percent: None, mem_usage_kb: Some(process_val.memory()), cpu_usage_percent: f64::from(process_val.cpu_usage()), + pid_vec: None, }); } } @@ -256,18 +260,17 @@ pub fn get_sorted_processes_list( } pub fn sort_processes(process_vector: &mut Vec<ProcessData>, sorting_method: &ProcessSorting, reverse_order: bool) { + // Always sort alphabetically first! + process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, false)); + match sorting_method { - // Always sort alphabetically first! ProcessSorting::CPU => { - process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, false)); process_vector.sort_by(|a, b| get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order)); } ProcessSorting::MEM => { - process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, false)); process_vector.sort_by(|a, b| get_ordering(a.mem_usage_percent, b.mem_usage_percent, reverse_order)); } ProcessSorting::PID => { - process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, false)); process_vector.sort_by(|a, b| get_ordering(a.pid, b.pid, reverse_order)); } ProcessSorting::NAME => process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order)), |