diff options
Diffstat (limited to 'src/gatherer.rs')
-rw-r--r-- | src/gatherer.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/gatherer.rs b/src/gatherer.rs index 53e46f1..c03a0a5 100644 --- a/src/gatherer.rs +++ b/src/gatherer.rs @@ -12,7 +12,7 @@ use time::OffsetDateTime; use crate::{ db::DbMeminfo, - griph::{self, Style}, + griph::{self, Style, TwoLineOrder}, AwakeState, }; @@ -159,6 +159,9 @@ pub fn make_net_graph(state: &AwakeState) { .map(|m| m.map(|n| n.tx_bytes_per_sec() as usize / 125).unwrap_or(0)) .collect(); + let rx_sum = rx_zeroed.iter().fold(0, |acc, x| acc + x); + let tx_sum = tx_zeroed.iter().fold(0, |acc, x| acc + x); + // Mixing the TX/RX delta so we can pick a range. let mut mixed = vec![0; 512]; mixed[..256].copy_from_slice(&rx_zeroed); @@ -166,12 +169,20 @@ pub fn make_net_graph(state: &AwakeState) { mixed.sort(); let kinda_highest = mixed[511 - 32]; - let high_bound = (kinda_highest as f32 / 256.0).ceil().max(1.0) as usize * 256; + let high_bound = (kinda_highest as f32 / 64.0).ceil().max(1.0) as usize * 64; state .netinfo_upper_bound .store(high_bound, Ordering::Release); - let gif = griph::make_2line(0, high_bound, &tx_deltas, &rx_deltas); + let order = if tx_sum > rx_sum { + TwoLineOrder::SeriesAFirst + } else { + TwoLineOrder::SeriesBFirst + }; + + tracing::debug!("tx_sum = {tx_sum} // rx_sum = {rx_sum} // order = {order:?}"); + + let gif = griph::make_2line(0, high_bound, &tx_deltas, &rx_deltas, order); let path = state.cache_path.join("current_hostnetinfo.gif"); gif.save(path).unwrap(); |