Skip to content

Commit

Permalink
Fix memory reporting with sysinfo 0.16 (#142)
Browse files Browse the repository at this point in the history
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 <plugwash@debian.org>
  • Loading branch information
plugwash and Peter Michael Green committed Nov 20, 2022
1 parent a157623 commit 8b0aa4f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/feature/si.rs
Expand Up @@ -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",
}
}
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8b0aa4f

Please sign in to comment.