Skip to content

Commit

Permalink
Update CPU time % calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jfernandez committed Feb 14, 2024
1 parent abfb507 commit 1fbe596
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/bpf_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl BpfProgram {
if self.run_time_ns == 0 {
return 0.0;
}
(self.runtime_delta() as f64 / self.num_cpus as f64) / self.timestamp_delta() as f64 * 100.0
self.runtime_delta() as f64 / self.timestamp_delta() as f64 * 100.0
}
}

Expand Down Expand Up @@ -197,8 +197,8 @@ mod tests {
timestamp_ns: 2000,
num_cpus: 4,
};
// Calculate expected value: ((200 - 100) / 4) / (2000 - 1000) * 100 = 2.5
let expected = 2.5;
// Calculate expected value: (200 - 100) / (2000 - 1000) * 100 = 10.0
let expected = 10.0;
assert_eq!(prog.cpu_time_percent(), expected);
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn ui(f: &mut Frame, app: &mut App) {
"Period Avg Runtime (ns)",
"Total Avg Runtime (ns)",
"Events per second",
"CPU %",
"Total CPU %",
]
.iter()
.map(|h| Cell::from(*h).style(Style::default()));
Expand Down

0 comments on commit 1fbe596

Please sign in to comment.