summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClementTsang <clementjhtsang@gmail.com>2019-09-15 00:06:57 -0400
committerClementTsang <clementjhtsang@gmail.com>2019-09-15 00:06:57 -0400
commit282acd1395fb521be3ca94c7731abfdfa2c9ae0c (patch)
tree1539d67a995ba268ec1d70f3fb615fbe3c7c1d18 /src/app
parent2435b9d90ce8029dd731238972f3610a56b6c3f9 (diff)
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.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_collection.rs1
-rw-r--r--src/app/data_collection/disks.rs20
-rw-r--r--src/app/data_collection/processes.rs32
3 files changed, 30 insertions, 23 deletions
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<Vec<DiskData>, 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::<heim_common::units::information::megabyte>(),
- used_space : usage.used().get::<heim_common::units::information::megabyte>(),
- total_space : usage.total().get::<heim_common::units::information::megabyte>(),
- 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::<heim_common::units::information::megabyte>(),
+ used_space : usage.used().get::<heim_common::units::information::megabyte>(),
+ total_space : usage.total().get::<heim_common::units::information::megabyte>(),
+ 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::<Vec<&str>>()[0];
let val = first_line.split_whitespace().collect::<Vec<&str>>();
- 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)