From a965e53c6cc7931d50c1fb7b50a5fd364482bfa4 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:15:11 -0400 Subject: [PATCH] fix wrong unit being used for memory in sysinfo data (#824) * fix wrong unit being used for memory in sysinfo data * update sysinfo to 0.26.4 for unsupported reasons w/ ntapi --- Cargo.lock | 19 ++++++++++++++----- Cargo.toml | 2 +- .../data_harvester/memory/general/sysinfo.rs | 4 ++-- .../data_harvester/processes/macos_freebsd.rs | 2 +- src/app/data_harvester/processes/windows.rs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0364edd7..df094d40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -775,7 +775,7 @@ dependencies = [ "lazy_static", "libc", "mach", - "ntapi", + "ntapi 0.3.7", "smol", "winapi", ] @@ -1000,7 +1000,7 @@ dependencies = [ "libc", "log", "miow", - "ntapi", + "ntapi 0.3.7", "winapi", ] @@ -1064,6 +1064,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ntapi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc" +dependencies = [ + "winapi", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1536,14 +1545,14 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.26.2" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae2421f3e16b3afd4aa692d23b83d0ba42ee9b0081d5deeb7d21428d7195fb1" +checksum = "7890fff842b8db56f2033ebee8f6efe1921475c3830c115995552914fb967580" dependencies = [ "cfg-if", "core-foundation-sys 0.8.3", "libc", - "ntapi", + "ntapi 0.4.0", "once_cell", "rayon", "winapi", diff --git a/Cargo.toml b/Cargo.toml index f5f1a767..8af54df2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ once_cell = "1.5.2" regex = "1.5.5" serde = { version = "1.0.136", features = ["derive"] } starship-battery = { version = "0.7.9", optional = true } -sysinfo = "0.26.2" +sysinfo = "0.26.4" thiserror = "1.0.30" time = { version = "0.3.9", features = ["formatting", "macros"] } toml = "0.5.9" diff --git a/src/app/data_harvester/memory/general/sysinfo.rs b/src/app/data_harvester/memory/general/sysinfo.rs index 761757e1..da4bd812 100644 --- a/src/app/data_harvester/memory/general/sysinfo.rs +++ b/src/app/data_harvester/memory/general/sysinfo.rs @@ -20,7 +20,7 @@ pub async fn get_mem_data( } pub async fn get_ram_data(sys: &System) -> crate::utils::error::Result> { - let (mem_total_in_kib, mem_used_in_kib) = (sys.total_memory(), sys.used_memory()); + let (mem_total_in_kib, mem_used_in_kib) = (sys.total_memory() / 1024, sys.used_memory()) / 1024; Ok(Some(MemHarvest { mem_total_in_kib, @@ -34,7 +34,7 @@ pub async fn get_ram_data(sys: &System) -> crate::utils::error::Result crate::utils::error::Result> { - let (mem_total_in_kib, mem_used_in_kib) = (sys.total_swap(), sys.used_swap()); + let (mem_total_in_kib, mem_used_in_kib) = (sys.total_swap() / 1024, sys.used_swap() / 1024); Ok(Some(MemHarvest { mem_total_in_kib, diff --git a/src/app/data_harvester/processes/macos_freebsd.rs b/src/app/data_harvester/processes/macos_freebsd.rs index cff6dab1..39b57e05 100644 --- a/src/app/data_harvester/processes/macos_freebsd.rs +++ b/src/app/data_harvester/processes/macos_freebsd.rs @@ -76,7 +76,7 @@ pub fn get_process_data( } else { 0.0 }, - mem_usage_bytes: process_val.memory() * 1024, + mem_usage_bytes: process_val.memory(), cpu_usage_percent: process_cpu_usage, read_bytes_per_sec: disk_usage.read_bytes, write_bytes_per_sec: disk_usage.written_bytes, diff --git a/src/app/data_harvester/processes/windows.rs b/src/app/data_harvester/processes/windows.rs index 36907b11..4df40983 100644 --- a/src/app/data_harvester/processes/windows.rs +++ b/src/app/data_harvester/processes/windows.rs @@ -66,7 +66,7 @@ pub fn get_process_data( } else { 0.0 }, - mem_usage_bytes: process_val.memory() * 1024, + mem_usage_bytes: process_val.memory(), cpu_usage_percent: process_cpu_usage, read_bytes_per_sec: disk_usage.read_bytes, write_bytes_per_sec: disk_usage.written_bytes,