diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2021-06-26 02:34:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 02:34:32 -0400 |
commit | 1598654bef13e7cc100430fc9de4b59265e65ffd (patch) | |
tree | 9eb75d7559d80bad80ea3c6dba5afc4809fd2020 /src/app | |
parent | 4569532fb1bb083efdb426ab9b48e5063c9aefc4 (diff) |
bug: Divide Windows process cpu usage by number of processors (#525)
Fixes a bug displaying the CPU usage of a process in Windows due to not dividing by the number of processors.
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/data_harvester/processes/macos.rs | 8 | ||||
-rw-r--r-- | src/app/data_harvester/processes/windows.rs | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/app/data_harvester/processes/macos.rs b/src/app/data_harvester/processes/macos.rs index 4290834e..f0c3980d 100644 --- a/src/app/data_harvester/processes/macos.rs +++ b/src/app/data_harvester/processes/macos.rs @@ -40,7 +40,7 @@ pub fn get_process_data( let mut process_vector: Vec<ProcessHarvest> = Vec::new(); let process_hashmap = sys.get_processes(); let cpu_usage = sys.get_global_processor_info().get_cpu_usage() as f64 / 100.0; - let num_cpus = sys.get_processors().len() as f64; + let num_processors = sys.get_processors().len() as f64; for process_val in process_hashmap.values() { let name = if process_val.name().is_empty() { let process_cmd = process_val.cmd(); @@ -72,7 +72,7 @@ pub fn get_process_data( }; let pcu = { - let p = process_val.cpu_usage() as f64 / num_cpus; + let p = process_val.cpu_usage() as f64 / num_processors; if p.is_nan() { process_val.cpu_usage() as f64 } else { @@ -117,10 +117,10 @@ pub fn get_process_data( let cpu_usages = get_macos_process_cpu_usage(&cpu_usage_unknown_pids)?; for process in &mut process_vector { if cpu_usages.contains_key(&process.pid) { - process.cpu_usage_percent = if num_cpus == 0.0 { + process.cpu_usage_percent = if num_processors == 0.0 { *cpu_usages.get(&process.pid).unwrap() } else { - *cpu_usages.get(&process.pid).unwrap() / num_cpus + *cpu_usages.get(&process.pid).unwrap() / num_processors }; } } diff --git a/src/app/data_harvester/processes/windows.rs b/src/app/data_harvester/processes/windows.rs index e7e76004..08cde500 100644 --- a/src/app/data_harvester/processes/windows.rs +++ b/src/app/data_harvester/processes/windows.rs @@ -9,6 +9,7 @@ pub fn get_process_data( let mut process_vector: Vec<ProcessHarvest> = Vec::new(); let process_hashmap = sys.get_processes(); let cpu_usage = sys.get_global_processor_info().get_cpu_usage() as f64 / 100.0; + let num_processors = sys.get_processors().len() as f64; for process_val in process_hashmap.values() { let name = if process_val.name().is_empty() { let process_cmd = process_val.cmd(); @@ -39,7 +40,14 @@ pub fn get_process_data( } }; - let pcu = process_val.cpu_usage() as f64; + let pcu = { + let p = process_val.cpu_usage() as f64 / num_processors; + if p.is_nan() { + process_val.cpu_usage() as f64 + } else { + p + } + }; let process_cpu_usage = if use_current_cpu_total && cpu_usage > 0.0 { pcu / cpu_usage } else { |