diff --git a/src/data_collection.rs b/src/data_collection.rs index 7320a4f0..e97b34bc 100644 --- a/src/data_collection.rs +++ b/src/data_collection.rs @@ -412,10 +412,7 @@ impl DataCollector { self.data.cache = memory::get_cache_usage(&self.sys.system); } - self.data.swap = memory::get_swap_usage( - #[cfg(not(target_os = "windows"))] - &self.sys.system, - ); + self.data.swap = memory::get_swap_usage(&self.sys.system); #[cfg(feature = "zfs")] { diff --git a/src/data_collection/memory.rs b/src/data_collection/memory.rs index dee65d8d..98cfebda 100644 --- a/src/data_collection/memory.rs +++ b/src/data_collection/memory.rs @@ -2,18 +2,15 @@ #[cfg(not(target_os = "windows"))] pub(crate) use self::sysinfo::get_cache_usage; -pub(crate) use self::sysinfo::get_ram_usage; +pub(crate) use self::sysinfo::{get_ram_usage, get_swap_usage}; pub mod sysinfo; -cfg_if::cfg_if! { - if #[cfg(target_os = "windows")] { - pub mod windows; - pub(crate) use self::windows::get_swap_usage; - } else { - pub(crate) use self::sysinfo::get_swap_usage; - - } -} +// cfg_if::cfg_if! { +// if #[cfg(target_os = "windows")] { +// mod windows; +// pub(crate) use self::windows::get_committed_usage; +// } +// } #[cfg(feature = "zfs")] pub mod arc; diff --git a/src/data_collection/memory/sysinfo.rs b/src/data_collection/memory/sysinfo.rs index 86ef5381..330bb9b0 100644 --- a/src/data_collection/memory/sysinfo.rs +++ b/src/data_collection/memory/sysinfo.rs @@ -21,7 +21,6 @@ pub(crate) fn get_ram_usage(sys: &System) -> Option { } /// Returns SWAP usage. -#[cfg(not(target_os = "windows"))] pub(crate) fn get_swap_usage(sys: &System) -> Option { let mem_used = sys.used_swap(); let mem_total = sys.total_swap(); diff --git a/src/data_collection/memory/windows.rs b/src/data_collection/memory/windows.rs index ba56df18..70792079 100644 --- a/src/data_collection/memory/windows.rs +++ b/src/data_collection/memory/windows.rs @@ -4,24 +4,26 @@ use windows::Win32::System::ProcessStatus::{GetPerformanceInfo, PERFORMANCE_INFO use crate::data_collection::memory::MemHarvest; -// TODO: Note this actually calculates the total *committed* usage. Rename and change label for accuracy! +const PERFORMANCE_INFORMATION_SIZE: u32 = size_of::() as _; + /// Get the committed memory usage. /// /// Code based on [sysinfo's](https://github.com/GuillaumeGomez/sysinfo/blob/6f8178495adcf3ca4696a9ec548586cf6a621bc8/src/windows/system.rs#L169). -pub(crate) fn get_swap_usage() -> Option { +pub(crate) fn get_committed_usage() -> Option { // SAFETY: The safety invariant is that we only touch what's in `perf_info` if it succeeds, and that // the bindings are "safe" to use with how we call them. unsafe { let mut perf_info: PERFORMANCE_INFORMATION = zeroed(); - if GetPerformanceInfo(&mut perf_info, size_of::() as u32).is_ok() { - // Saturating sub by perf_info.PhysicalTotal for what sysinfo does. - let swap_total = perf_info.PageSize.saturating_mul(perf_info.CommitLimit) as u64; - let swap_used = perf_info.PageSize.saturating_mul(perf_info.CommitTotal) as u64; + if GetPerformanceInfo(&mut perf_info, PERFORMANCE_INFORMATION_SIZE).is_ok() { + let page_size = perf_info.PageSize; + + let committed_total = page_size.saturating_mul(perf_info.CommitLimit) as u64; + let committed_used = page_size.saturating_mul(perf_info.CommitTotal) as u64; Some(MemHarvest { - used_bytes: swap_used, - total_bytes: swap_total, - use_percent: Some(swap_used as f64 / swap_total as f64 * 100.0), + used_bytes: committed_used, + total_bytes: committed_total, + use_percent: Some(committed_used as f64 / committed_total as f64 * 100.0), }) } else { None