Skip to content

Commit

Permalink
Add a column to display total avg runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
jfernandez committed Feb 14, 2024
1 parent d9729f0 commit abfb507
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
31 changes: 28 additions & 3 deletions src/bpf_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ pub struct BpfProgram {

impl BpfProgram {

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

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

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

self.run_time_ns / self.run_cnt
}

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

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

#[test]
fn test_total_average_runtime_ns() {
let prog = BpfProgram {
id: "test".to_string(),
bpf_type: "test".to_string(),
name: "test".to_string(),
prev_runtime_ns: 100,
run_time_ns: 1000,
prev_run_cnt: 1,
run_cnt: 5,
prev_timestamp_ns: 1000,
timestamp_ns: 2000,
num_cpus: 4,
};
assert_eq!(prog.total_average_runtime_ns(), 200);
}

#[test]
Expand Down
19 changes: 11 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ 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_delta().to_string()),
Cell::from(bpf_program.period_average_runtime_ns().to_string()),
Cell::from(bpf_program.total_average_runtime_ns().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 Expand Up @@ -198,7 +199,8 @@ fn ui(f: &mut Frame, app: &mut App) {
"ID",
"Type",
"Name",
"Avg Runtime (ns)",
"Period Avg Runtime (ns)",
"Total Avg Runtime (ns)",
"Events per second",
"CPU %",
]
Expand All @@ -214,12 +216,13 @@ fn ui(f: &mut Frame, app: &mut App) {
let rows: Vec<Row> = items.iter().map(|item| item.into()).collect();

let widths = [
Constraint::Percentage(15),
Constraint::Percentage(25),
Constraint::Percentage(15),
Constraint::Percentage(15),
Constraint::Percentage(15),
Constraint::Percentage(15),
Constraint::Percentage(5),
Constraint::Percentage(17),
Constraint::Percentage(17),
Constraint::Percentage(17),
Constraint::Percentage(17),
Constraint::Percentage(17),
Constraint::Percentage(10),
];

let t = Table::new(rows, widths)
Expand Down

0 comments on commit abfb507

Please sign in to comment.