From 282acd1395fb521be3ca94c7731abfdfa2c9ae0c Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sun, 15 Sep 2019 00:06:57 -0400 Subject: Made charting look better, switched back to braille markers (its the only way I could make it look good), and dealt with some issues regarding the display of networking. --- src/app/data_collection.rs | 1 - src/app/data_collection/disks.rs | 20 +++++++++++--------- src/app/data_collection/processes.rs | 32 +++++++++++++++++++------------- 3 files changed, 30 insertions(+), 23 deletions(-) (limited to 'src/app') diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index 4b7a04e9..4e45b719 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -103,7 +103,6 @@ impl DataState { } // Filter out stale timed entries - // TODO: ideally make this a generic function! let current_instant = std::time::Instant::now(); self.data.list_of_cpu_packages = self .data diff --git a/src/app/data_collection/disks.rs b/src/app/data_collection/disks.rs index ad897aed..1700ddbb 100644 --- a/src/app/data_collection/disks.rs +++ b/src/app/data_collection/disks.rs @@ -56,16 +56,18 @@ pub async fn get_disk_usage_list() -> Result, heim::Error> { let mut partitions_stream = heim::disk::partitions_physical(); while let Some(part) = partitions_stream.next().await { - let partition = part?; // TODO: Change this? We don't want to error out immediately... - let usage = heim::disk::usage(partition.mount_point().to_path_buf()).await?; + if let Ok(part) = part { + let partition = part; + let usage = heim::disk::usage(partition.mount_point().to_path_buf()).await?; - vec_disks.push(DiskData { - free_space : usage.free().get::(), - used_space : usage.used().get::(), - total_space : usage.total().get::(), - mount_point : Box::from(partition.mount_point().to_str().unwrap_or("Name Unavailable")), - name : Box::from(partition.device().unwrap_or_else(|| std::ffi::OsStr::new("Name Unavailable")).to_str().unwrap_or("Name Unavailable")), - }); + vec_disks.push(DiskData { + free_space : usage.free().get::(), + used_space : usage.used().get::(), + total_space : usage.total().get::(), + mount_point : Box::from(partition.mount_point().to_str().unwrap_or("Name Unavailable")), + name : Box::from(partition.device().unwrap_or_else(|| std::ffi::OsStr::new("Name Unavailable")).to_str().unwrap_or("Name Unavailable")), + }); + } } vec_disks.sort_by(|a, b| { diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index 2ef587bb..b1d495bf 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -39,15 +39,20 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64 let first_line = stat_results.split('\n').collect::>()[0]; let val = first_line.split_whitespace().collect::>(); - let user : f64 = val[1].parse::<_>().unwrap_or(-1_f64); // TODO: Better checking - let nice : f64 = val[2].parse::<_>().unwrap_or(-1_f64); - let system : f64 = val[3].parse::<_>().unwrap_or(-1_f64); - let idle : f64 = val[4].parse::<_>().unwrap_or(-1_f64); - let iowait : f64 = val[5].parse::<_>().unwrap_or(-1_f64); - let irq : f64 = val[6].parse::<_>().unwrap_or(-1_f64); - let softirq : f64 = val[7].parse::<_>().unwrap_or(-1_f64); - let steal : f64 = val[8].parse::<_>().unwrap_or(-1_f64); - let guest : f64 = val[9].parse::<_>().unwrap_or(-1_f64); + // SC in case that the parsing will fail due to length: + if val.len() <= 10 { + return Ok(1.0); // TODO: This is not the greatest... + } + + let user : f64 = val[1].parse::<_>().unwrap_or(0_f64); + let nice : f64 = val[2].parse::<_>().unwrap_or(0_f64); + let system : f64 = val[3].parse::<_>().unwrap_or(0_f64); + let idle : f64 = val[4].parse::<_>().unwrap_or(0_f64); + let iowait : f64 = val[5].parse::<_>().unwrap_or(0_f64); + let irq : f64 = val[6].parse::<_>().unwrap_or(0_f64); + let softirq : f64 = val[7].parse::<_>().unwrap_or(0_f64); + let steal : f64 = val[8].parse::<_>().unwrap_or(0_f64); + let guest : f64 = val[9].parse::<_>().unwrap_or(0_f64); let idle = idle + iowait; let non_idle = user + nice + system + irq + softirq + steal + guest; @@ -204,12 +209,13 @@ pub async fn get_sorted_processes_list(prev_idle : &mut f64, prev_non_idle : &mu } } else if cfg!(target_os = "macos") { - // macOS - dbg!("Mac"); // TODO: Remove + // TODO: macOS + debug!("Mac"); } else { - dbg!("Else"); // TODO: Remove - // Solaris: https://stackoverflow.com/a/4453581 + // TODO: Others? + debug!("Else"); + // Solaris: https://stackoverflow.com/a/4453581 } Ok(process_vector) -- cgit v1.2.3