From 8b0aa4fd84d2bcba0b4845847631ddb386e5a0db Mon Sep 17 00:00:00 2001 From: plugwash Date: Sun, 20 Nov 2022 21:25:30 +0000 Subject: [PATCH] Fix memory reporting with sysinfo 0.16 (#142) sysinfo 0.16 changed the units for reporting memory from kilobytes to bytes, this commit updates the reported units to match. I also added TB to the list of possible units. Computers with terabytes of memory do exist nowadays. Co-authored-by: Peter Michael Green --- src/feature/si.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/feature/si.rs b/src/feature/si.rs index 94ff40ac..aecd2e9c 100644 --- a/src/feature/si.rs +++ b/src/feature/si.rs @@ -301,9 +301,11 @@ fn check_user(_process: &Process, _user: &User) -> bool { #[cfg(feature = "si")] fn suffix(val: usize) -> &'static str { match val { - 0 => "KB", - 1 => "MB", - 2 => "GB", + 0 => "B", + 1 => "KB", + 2 => "MB", + 3 => "GB", + 4 => "TB", _ => "xB", } } @@ -354,10 +356,12 @@ mod test { #[test] fn suffix_works() { - assert_eq!("KB", suffix(0)); - assert_eq!("MB", suffix(1)); - assert_eq!("GB", suffix(2)); - assert_eq!("xB", suffix(3)); + assert_eq!("B", suffix(0)); + assert_eq!("KB", suffix(1)); + assert_eq!("MB", suffix(2)); + assert_eq!("GB", suffix(3)); + assert_eq!("TB", suffix(4)); + assert_eq!("xB", suffix(5)); } #[test]