mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-11-29 10:04:18 +01:00
fix: sort disk I/O by original rates instead of readable strings (#1833)
This commit is contained in:
parent
e1dc3f27e7
commit
256c5aba68
@ -9,7 +9,6 @@ use crate::collection::batteries;
|
||||
use crate::{
|
||||
app::AppConfigFields,
|
||||
collection::{Data, cpu, disks, memory::MemData, network},
|
||||
dec_bytes_per_second_string,
|
||||
utils::data_units::DataUnit,
|
||||
widgets::{DiskWidgetData, TempWidgetData},
|
||||
};
|
||||
@ -246,21 +245,22 @@ impl StoredData {
|
||||
}
|
||||
};
|
||||
|
||||
let (mut io_read, mut io_write) = ("N/A".into(), "N/A".into());
|
||||
let (mut io_read_rate_bytes, mut io_write_rate_bytes) = (None, None);
|
||||
if let Some(Some(io_device)) = io_device {
|
||||
if let Some(prev_io) = self.prev_io.get_mut(itx) {
|
||||
let r_rate = ((io_device.read_bytes.saturating_sub(prev_io.0)) as f64
|
||||
/ time_since_last_harvest)
|
||||
.round() as u64;
|
||||
io_read_rate_bytes = Some(
|
||||
((io_device.read_bytes.saturating_sub(prev_io.0)) as f64
|
||||
/ time_since_last_harvest)
|
||||
.round() as u64,
|
||||
);
|
||||
|
||||
let w_rate = ((io_device.write_bytes.saturating_sub(prev_io.1)) as f64
|
||||
/ time_since_last_harvest)
|
||||
.round() as u64;
|
||||
io_write_rate_bytes = Some(
|
||||
((io_device.write_bytes.saturating_sub(prev_io.1)) as f64
|
||||
/ time_since_last_harvest)
|
||||
.round() as u64,
|
||||
);
|
||||
|
||||
*prev_io = (io_device.read_bytes, io_device.write_bytes);
|
||||
|
||||
io_read = dec_bytes_per_second_string(r_rate).into();
|
||||
io_write = dec_bytes_per_second_string(w_rate).into();
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,8 +276,8 @@ impl StoredData {
|
||||
used_bytes: device.used_space,
|
||||
total_bytes: device.total_space,
|
||||
summed_total_bytes,
|
||||
io_read,
|
||||
io_write,
|
||||
io_read_rate_bytes,
|
||||
io_write_rate_bytes,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,10 @@ use crate::{
|
||||
SortDataTable, SortDataTableProps, SortOrder, SortsRow,
|
||||
},
|
||||
options::config::style::Styles,
|
||||
utils::{data_units::get_decimal_bytes, general::sort_partial_fn},
|
||||
utils::{
|
||||
conversion::dec_bytes_per_second_string, data_units::get_decimal_bytes,
|
||||
general::sort_partial_fn,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@ -20,8 +23,8 @@ pub struct DiskWidgetData {
|
||||
pub used_bytes: Option<u64>,
|
||||
pub total_bytes: Option<u64>,
|
||||
pub summed_total_bytes: Option<u64>,
|
||||
pub io_read: Cow<'static, str>,
|
||||
pub io_write: Cow<'static, str>,
|
||||
pub io_read_rate_bytes: Option<u64>,
|
||||
pub io_write_rate_bytes: Option<u64>,
|
||||
}
|
||||
|
||||
impl DiskWidgetData {
|
||||
@ -79,6 +82,18 @@ impl DiskWidgetData {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn io_read(&self) -> Cow<'static, str> {
|
||||
self.io_read_rate_bytes.map_or("N/A".into(), |r_rate| {
|
||||
dec_bytes_per_second_string(r_rate).into()
|
||||
})
|
||||
}
|
||||
|
||||
fn io_write(&self) -> Cow<'static, str> {
|
||||
self.io_write_rate_bytes.map_or("N/A".into(), |w_rate| {
|
||||
dec_bytes_per_second_string(w_rate).into()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -177,8 +192,8 @@ impl DataToCell<DiskColumn> for DiskWidgetData {
|
||||
DiskColumn::UsedPercent => percent_string(self.used_percent()),
|
||||
DiskColumn::FreePercent => percent_string(self.free_percent()),
|
||||
DiskColumn::Total => self.total_space(),
|
||||
DiskColumn::IoRead => self.io_read.clone(),
|
||||
DiskColumn::IoWrite => self.io_write.clone(),
|
||||
DiskColumn::IoRead => self.io_read(),
|
||||
DiskColumn::IoWrite => self.io_write(),
|
||||
};
|
||||
|
||||
Some(text)
|
||||
@ -235,10 +250,14 @@ impl SortsRow for DiskColumn {
|
||||
data.sort_by(|a, b| sort_partial_fn(descending)(&a.total_bytes, &b.total_bytes));
|
||||
}
|
||||
DiskColumn::IoRead => {
|
||||
data.sort_by(|a, b| sort_partial_fn(descending)(&a.io_read, &b.io_read));
|
||||
data.sort_by(|a, b| {
|
||||
sort_partial_fn(descending)(&a.io_read_rate_bytes, &b.io_read_rate_bytes)
|
||||
});
|
||||
}
|
||||
DiskColumn::IoWrite => {
|
||||
data.sort_by(|a, b| sort_partial_fn(descending)(&a.io_write, &b.io_write));
|
||||
data.sort_by(|a, b| {
|
||||
sort_partial_fn(descending)(&a.io_write_rate_bytes, &b.io_write_rate_bytes)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user