From f17aae686342aa893aa5bbf360331eccbebc03db Mon Sep 17 00:00:00 2001 From: Bruce Guenter Date: Tue, 15 Aug 2023 10:19:40 -0600 Subject: [PATCH] Implement Windows calculation --- src/windows/process.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/windows/process.rs b/src/windows/process.rs index 9c1371fe0..8d3a4f7bc 100644 --- a/src/windows/process.rs +++ b/src/windows/process.rs @@ -205,6 +205,7 @@ pub struct Process { old_written_bytes: u64, read_bytes: u64, written_bytes: u64, + nb_cpus: u64, } struct CPUsageCalculationValues { @@ -212,6 +213,7 @@ struct CPUsageCalculationValues { old_process_user_cpu: u64, old_system_sys_cpu: u64, old_system_user_cpu: u64, + nb_cpus: u64, } impl CPUsageCalculationValues { @@ -221,8 +223,18 @@ impl CPUsageCalculationValues { old_process_user_cpu: 0, old_system_sys_cpu: 0, old_system_user_cpu: 0, + nb_cpus: 0, } } + + const fn total_accumulated_cpu_usage(&self) -> f32 { + self.old_process_user_cpu + .saturating_add(self.old_process_sys_cpu) as f32 + / self + .old_system_user_cpu + .saturating_add(self.old_system_sys_cpu) as f32 + * self.nb_cpus as f32 + } } static WINDOWS_8_1_OR_NEWER: Lazy = Lazy::new(|| unsafe { let mut version_info: RTL_OSVERSIONINFOEXW = MaybeUninit::zeroed().assume_init(); @@ -600,7 +612,7 @@ impl ProcessExt for Process { } fn total_accumulated_cpu_usage(&self) -> f32 { - FIXME + self.cpu_calc_values.total_accumulated_cpu_usage() } fn disk_usage(&self) -> DiskUsage { @@ -1112,6 +1124,7 @@ pub(crate) fn compute_cpu_usage(p: &mut Process, nb_cpus: u64) { p.cpu_calc_values.old_process_sys_cpu = sys; p.cpu_calc_values.old_system_user_cpu = global_user_time; p.cpu_calc_values.old_system_sys_cpu = global_kernel_time; + p.cpu_calc_values.nb_cpus = nb_cpus; let denominator = delta_global_user_time.saturating_add(delta_global_kernel_time) as f32;