Skip to content

Commit

Permalink
Remove num_cpus dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jfernandez committed Feb 14, 2024
1 parent 194603c commit 72783a4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ regex = "1.8.1"
anyhow = "1.0.71"
ratatui = { version = "0.26.1", default-features = false, features = ['crossterm'] }
nix = "0.27.1"
num_cpus = "1.16.0"

[profile.release]
debug = false
8 changes: 0 additions & 8 deletions src/bpf_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct BpfProgram {
pub run_cnt: u64,
pub prev_timestamp_ns: u128,
pub timestamp_ns: u128,
pub num_cpus: usize,
}

impl BpfProgram {
Expand Down Expand Up @@ -93,7 +92,6 @@ mod tests {
run_cnt: 2,
prev_timestamp_ns: 1000,
timestamp_ns: 2000,
num_cpus: 4,
};
assert_eq!(prog.period_average_runtime_ns(), 100);
}
Expand All @@ -110,7 +108,6 @@ mod tests {
run_cnt: 5,
prev_timestamp_ns: 1000,
timestamp_ns: 2000,
num_cpus: 4,
};
assert_eq!(prog.total_average_runtime_ns(), 200);
}
Expand All @@ -127,7 +124,6 @@ mod tests {
run_cnt: 2,
prev_timestamp_ns: 1000,
timestamp_ns: 2000,
num_cpus: 4,
};
assert_eq!(prog.runtime_delta(), 100);
}
Expand All @@ -144,7 +140,6 @@ mod tests {
run_cnt: 8,
prev_timestamp_ns: 1000,
timestamp_ns: 2000,
num_cpus: 4,
};
assert_eq!(prog.run_cnt_delta(), 3);
}
Expand All @@ -161,7 +156,6 @@ mod tests {
run_cnt: 2,
prev_timestamp_ns: 1000,
timestamp_ns: 3000,
num_cpus: 4,
};
assert_eq!(prog.timestamp_delta(), 2000);
}
Expand All @@ -178,7 +172,6 @@ mod tests {
run_cnt: 50,
prev_timestamp_ns: 1_000_000_000,
timestamp_ns: 2_000_000_000,
num_cpus: 4,
};
assert_eq!(prog.events_per_second(), 40);
}
Expand All @@ -195,7 +188,6 @@ mod tests {
run_cnt: 2,
prev_timestamp_ns: 1000,
timestamp_ns: 2000,
num_cpus: 4,
};
// Calculate expected value: (200 - 100) / (2000 - 1000) * 100 = 10.0
let expected = 10.0;
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl App {
}
}

pub fn start_background_thread(&self, num_cpus: usize) {
pub fn start_background_thread(&self) {
let items_clone = Arc::clone(&self.items);

thread::spawn(move || loop {
Expand Down Expand Up @@ -102,7 +102,6 @@ impl App {
run_cnt: prog.run_cnt,
prev_timestamp_ns: 0,
timestamp_ns,
num_cpus
};

if let Some(prev_bpf_program) = map.get(&bpf_program.id) {
Expand Down Expand Up @@ -145,11 +144,9 @@ fn main() -> Result<()> {
let mut terminal = Terminal::new(backend)?;
terminal.clear()?;

let num_cpus = num_cpus::get();

// create app and run it
let app = App::new();
app.start_background_thread(num_cpus);
app.start_background_thread();
let res = run_app(&mut terminal, app);

// // restore terminal
Expand Down

0 comments on commit 72783a4

Please sign in to comment.