summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-05-11 22:34:35 -0400
committerGitHub <noreply@github.com>2020-05-11 22:34:35 -0400
commit137e3cea5fb9c4a20604f5ab02f13979d949500a (patch)
treee5ec019ed35d92d69aca88d426875c23394fb1a0
parent7b5685bf446e6e80c15d9629810788d670ec4684 (diff)
bug: disk displays nothing on if IO fails to match
Obvious on macOS.
-rw-r--r--src/app/data_farmer.rs51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index d9829896..cf2b3fbc 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -1,3 +1,4 @@
+use lazy_static::lazy_static;
/// In charge of cleaning, processing, and managing data. I couldn't think of
/// a better name for the file. Since I called data collection "harvesting",
/// then this is the farmer I guess.
@@ -12,12 +13,12 @@
/// call the purging function. Failure to do so *will* result in a growing
/// memory usage and higher CPU usage - you will be trying to process more and
/// more points as this is used!
-use std::time::Instant;
-use std::vec::Vec;
+use std::{time::Instant, vec::Vec};
use crate::data_harvester::{
battery_harvester, cpu, disks, mem, network, processes, temperature, Data,
};
+use regex::Regex;
pub type TimeOffset = f64;
pub type Value = f64;
@@ -230,22 +231,38 @@ impl DataCollection {
for (itx, device) in disks.iter().enumerate() {
if let Some(trim) = device.name.split('/').last() {
- let io_device = io.get(trim);
- if let Some(io) = io_device {
- let io_r_pt = io.read_bytes;
- let io_w_pt = io.write_bytes;
-
- if self.io_labels_and_prev.len() <= itx {
- self.io_labels_and_prev.push(((0, 0), (io_r_pt, io_w_pt)));
- } else if let Some((io_curr, io_prev)) = self.io_labels_and_prev.get_mut(itx) {
- let r_rate =
- ((io_r_pt - io_prev.0) as f64 / time_since_last_harvest).round() as u64;
- let w_rate =
- ((io_w_pt - io_prev.1) as f64 / time_since_last_harvest).round() as u64;
-
- *io_curr = (r_rate, w_rate);
- *io_prev = (io_r_pt, io_w_pt);
+ let io_device = if cfg!(target_os = "macos") {
+ // Must trim one level further!
+
+ lazy_static! {
+ static ref DISK_REGEX: Regex = Regex::new(r"disk\d+").unwrap();
+ }
+ if let Some(disk_trim) = DISK_REGEX.find(trim) {
+ io.get(disk_trim.as_str())
+ } else {
+ None
}
+ } else {
+ io.get(trim)
+ };
+ let (io_r_pt, io_w_pt) = if let Some(io) = io_device {
+ (io.read_bytes, io.write_bytes)
+ } else {
+ (0, 0)
+ };
+
+ if self.io_labels_and_prev.len() <= itx {
+ self.io_labels_and_prev.push(((0, 0), (io_r_pt, io_w_pt)));
+ } else if let Some((io_curr, io_prev)) = self.io_labels_and_prev.get_mut(itx) {
+ let r_rate = ((io_r_pt.saturating_sub(io_prev.0)) as f64
+ / time_since_last_harvest)
+ .round() as u64;
+ let w_rate = ((io_w_pt.saturating_sub(io_prev.1)) as f64
+ / time_since_last_harvest)
+ .round() as u64;
+
+ *io_curr = (r_rate, w_rate);
+ *io_prev = (io_r_pt, io_w_pt);
}
}
}