Skip to content

Commit

Permalink
Refactor average_runtime to average_runtime_delta
Browse files Browse the repository at this point in the history
  • Loading branch information
jfernandez committed Feb 13, 2024
1 parent eb10053 commit 419bd06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/bpf_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ pub struct BpfProgram {
}

impl BpfProgram {
pub fn average_runtime(&self) -> u64 {
if self.run_cnt == 0 {

pub fn average_runtime_delta(&self) -> u64 {
if self.run_cnt_delta() == 0 {
return 0;
}

self.run_time_ns / self.run_cnt
self.runtime_delta() / self.run_cnt_delta()
}

pub fn runtime_delta(&self) -> u64 {
Expand Down Expand Up @@ -73,7 +74,7 @@ mod tests {
use super::*;

#[test]
fn test_average_runtime() {
fn test_average_runtime_delta() {
let prog = BpfProgram {
id: "test".to_string(),
bpf_type: "test".to_string(),
Expand All @@ -86,7 +87,7 @@ mod tests {
timestamp_ns: 2000,
num_cpus: 4,
};
assert_eq!(prog.average_runtime(), 100);
assert_eq!(prog.average_runtime_delta(), 100);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl From<&BpfProgram> for Row<'_> {
Cell::from(bpf_program.id.to_string()),
Cell::from(bpf_program.bpf_type.to_string()),
Cell::from(bpf_program.name.to_string()),
Cell::from(bpf_program.average_runtime().to_string()),
Cell::from(bpf_program.average_runtime_delta().to_string()),
Cell::from(bpf_program.events_per_second().to_string()),
Cell::from(round_to_first_non_zero(bpf_program.cpu_time_percent()).to_string()),
];
Expand Down

0 comments on commit 419bd06

Please sign in to comment.