bug: fix is_nan being incorrectly used to check for division by zero (#905)

This commit is contained in:
Clement Tsang 2022-11-20 03:05:45 -05:00 committed by GitHub
parent 63df220a38
commit abff6e4a7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -50,11 +50,12 @@ where
};
let pcu = {
let p = process_val.cpu_usage() as f64 / num_processors;
if p.is_nan() {
process_val.cpu_usage() as f64
let usage = process_val.cpu_usage() as f64;
let res = usage / num_processors;
if res.is_finite() {
res
} else {
p
usage
}
};
let process_cpu_usage = if use_current_cpu_total && cpu_usage > 0.0 {

View file

@ -42,11 +42,12 @@ pub fn get_process_data(
};
let pcu = {
let p = process_val.cpu_usage() as f64 / num_processors;
if p.is_nan() {
process_val.cpu_usage() as f64
let usage = process_val.cpu_usage() as f64;
let res = usage / num_processors;
if res.is_finite() {
res
} else {
p
usage
}
};
let process_cpu_usage = if use_current_cpu_total && cpu_usage > 0.0 {