diff --git a/Cargo.toml b/Cargo.toml index 9d3242ef..0224e58e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ clap = "2.33.0" crossterm = "0.14" failure = "0.1.6" fern = "0.5" -futures-timer = "0.3" -futures-preview = "0.3.0-alpha.18" -heim = "0.0.8" +futures-timer = "2.0.2" +futures = "0.3.1" +heim = "0.0.9" log = "0.4" rayon = "1.3" regex = "1.3.1" diff --git a/src/app/data_collection/disks.rs b/src/app/data_collection/disks.rs index 1bacc54e..c49350a7 100644 --- a/src/app/data_collection/disks.rs +++ b/src/app/data_collection/disks.rs @@ -1,4 +1,4 @@ -use futures::StreamExt; +use futures::stream::StreamExt; use heim::units::information; use std::time::Instant; diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index c3154b0b..3eb7a698 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -26,8 +26,8 @@ pub struct ProcessData { pub command: String, } -fn vangelis_cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> std::io::Result<(f64, f64)> { - // Named after this SO answer: https://stackoverflow.com/a/23376195 +fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> std::io::Result<(f64, f64)> { + // From SO answer: https://stackoverflow.com/a/23376195 let mut path = std::path::PathBuf::new(); path.push("/proc"); path.push("stat"); @@ -36,7 +36,7 @@ fn vangelis_cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) let first_line = stat_results.split('\n').collect::>()[0]; // TODO: Consider grabbing by number of threads instead, and summing the total? - // ie: 4 threads, so: (prev - curr) / cpu_0 + ... + (prev - curr) / cpu_n instead? This might be how top does it? + // ie: 4 threads, so: (prev - cur) / cpu_0 + ... + (prev - cur) / cpu_n instead? This might be how top does it? let val = first_line.split_whitespace().collect::>(); // SC in case that the parsing will fail due to length: @@ -179,7 +179,7 @@ pub async fn get_sorted_processes_list( let ps_result = Command::new("ps").args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"]).output()?; let ps_stdout = String::from_utf8_lossy(&ps_result.stdout); let split_string = ps_stdout.split('\n'); - if let Ok((cpu_usage, cpu_percentage)) = vangelis_cpu_usage_calculation(prev_idle, prev_non_idle) { + if let Ok((cpu_usage, cpu_percentage)) = cpu_usage_calculation(prev_idle, prev_non_idle) { let process_stream = split_string.collect::>(); for process in process_stream {