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 f17aae6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,15 @@ pub struct Process {
old_written_bytes: u64,
read_bytes: u64,
written_bytes: u64,
nb_cpus: u64,
}

struct CPUsageCalculationValues {
old_process_sys_cpu: u64,
old_process_user_cpu: u64,
old_system_sys_cpu: u64,
old_system_user_cpu: u64,
nb_cpus: u64,
}

impl CPUsageCalculationValues {
Expand All @@ -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<bool> = Lazy::new(|| unsafe {
let mut version_info: RTL_OSVERSIONINFOEXW = MaybeUninit::zeroed().assume_init();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit f17aae6

Please sign in to comment.