mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-12 23:47:17 +00:00
bug: disk displays nothing on if IO fails to match
Obvious on macOS.
This commit is contained in:
parent
7b5685bf44
commit
137e3cea5f
1 changed files with 33 additions and 16 deletions
|
@ -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;
|
||||
let io_device = if cfg!(target_os = "macos") {
|
||||
// Must trim one level further!
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue