Skip to content

Commit

Permalink
Implement Windows calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceg committed Aug 15, 2023
1 parent 0819473 commit ae6505d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/windows/process.rs
Expand Up @@ -212,6 +212,7 @@ struct CPUsageCalculationValues {
old_process_user_cpu: u64,
old_system_sys_cpu: u64,
old_system_user_cpu: u64,
nb_cpus: u64,
}

impl CPUsageCalculationValues {
Expand All @@ -221,8 +222,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

Check failure on line 230 in src/windows/process.rs

View workflow job for this annotation

GitHub Actions / Check nightly / x86_64-pc-windows-msvc

floating point arithmetic is not allowed in constant functions

Check failure on line 230 in src/windows/process.rs

View workflow job for this annotation

GitHub Actions / Check nightly / x86_64-pc-windows-msvc

floating point arithmetic is not allowed in constant functions

Check failure on line 230 in src/windows/process.rs

View workflow job for this annotation

GitHub Actions / Check 1.63.0 / x86_64-pc-windows-msvc

floating point arithmetic is not allowed in constant functions

Check failure on line 230 in src/windows/process.rs

View workflow job for this annotation

GitHub Actions / Check 1.63.0 / x86_64-pc-windows-msvc

floating point arithmetic is not allowed in constant functions

Check failure on line 230 in src/windows/process.rs

View workflow job for this annotation

GitHub Actions / Check stable / x86_64-pc-windows-msvc

floating point arithmetic is not allowed in constant functions

Check failure on line 230 in src/windows/process.rs

View workflow job for this annotation

GitHub Actions / Check stable / x86_64-pc-windows-msvc

floating point arithmetic is not allowed in constant functions
.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<bool> = Lazy::new(|| unsafe {
let mut version_info: RTL_OSVERSIONINFOEXW = MaybeUninit::zeroed().assume_init();
Expand Down Expand Up @@ -600,7 +611,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 {
Expand Down Expand Up @@ -1112,6 +1123,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;

Expand Down

0 comments on commit ae6505d

Please sign in to comment.