-
Notifications
You must be signed in to change notification settings - Fork 1.2k
subsystem-bench: cache misses profiling #2893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
240185d
81ed8ac
550420a
cf2a144
f11656a
ea265fd
24f0983
0ab0143
9fbfccb
d2a5dc5
a2267b4
84c4e2b
e7a2d4b
b38a990
a6caa23
20ceaa7
d15fd83
0cfb180
36e0de3
03d6f27
503ccfb
5a3b421
e0da4c4
d9cde05
18b7161
5da8447
219a05c
4b61166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| //! A tool for running subsystem benchmark tests designed for development and | ||
| //! CI regression testing. | ||
|
|
||
| use clap::Parser; | ||
| use color_eyre::eyre; | ||
| use pyroscope::PyroscopeAgent; | ||
|
|
@@ -90,12 +91,21 @@ struct BenchCli { | |
| /// Pyroscope Sample Rate | ||
| pub pyroscope_sample_rate: u32, | ||
|
|
||
| #[clap(long, default_value_t = false)] | ||
| /// Enable Cache Misses Profiling with Valgrind. Linux only, Valgrind must be in the PATH | ||
| pub cache_misses: bool, | ||
|
|
||
| #[command(subcommand)] | ||
| pub objective: cli::TestObjective, | ||
| } | ||
|
|
||
| impl BenchCli { | ||
| fn launch(self) -> eyre::Result<()> { | ||
| let is_valgrind = is_valgrind_mode(); | ||
| if !is_valgrind && self.cache_misses { | ||
| return valgrind_init() | ||
| } | ||
|
|
||
| let agent_running = if self.profile { | ||
| let agent = PyroscopeAgent::builder(self.pyroscope_url.as_str(), "subsystem-bench") | ||
| .backend(pprof_backend(PprofConfig::new().sample_rate(self.pyroscope_sample_rate))) | ||
|
|
@@ -185,10 +195,18 @@ impl BenchCli { | |
|
|
||
| let mut state = TestState::new(&test_config); | ||
| let (mut env, _protocol_config) = prepare_test(test_config, &mut state); | ||
| // test_config.write_to_disk(); | ||
|
|
||
| if is_valgrind { | ||
| valgrind_start(); | ||
| } | ||
|
|
||
| env.runtime() | ||
| .block_on(availability::benchmark_availability_read(&mut env, state)); | ||
|
|
||
| if is_valgrind { | ||
| valgrind_stop(); | ||
| } | ||
|
|
||
| if let Some(agent_running) = agent_running { | ||
| let agent_ready = agent_running.stop()?; | ||
| agent_ready.shutdown(); | ||
|
|
@@ -198,6 +216,52 @@ impl BenchCli { | |
| } | ||
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| fn is_valgrind_mode() -> bool { | ||
|
||
| !matches!(crabgrind::run_mode(), crabgrind::RunMode::Native) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn is_valgrind_mode() -> bool { | ||
| false | ||
| } | ||
|
|
||
| /// Start collecting cache misses data | ||
| #[cfg(target_os = "linux")] | ||
| fn valgrind_start() { | ||
| crabgrind::cachegrind::start_instrumentation(); | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn valgrind_start() {} | ||
|
|
||
| /// Stop collecting cache misses data | ||
| #[cfg(target_os = "linux")] | ||
| fn valgrind_stop() { | ||
| crabgrind::cachegrind::stop_instrumentation(); | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn valgrind_stop() {} | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| fn valgrind_init() -> eyre::Result<()> { | ||
| use std::os::unix::process::CommandExt; | ||
| std::process::Command::new("valgrind") | ||
|
||
| .arg("--tool=cachegrind") | ||
| .arg("--cache-sim=yes") | ||
| .arg("--instr-at-start=no") | ||
| .args(std::env::args()) | ||
| .exec(); | ||
|
|
||
| return Ok(()) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn valgrind_init() -> eyre::Result<()> { | ||
| return Err(eyre::eyre!("Valgrind can be executed only on linux")); | ||
| } | ||
|
|
||
| fn main() -> eyre::Result<()> { | ||
| color_eyre::install()?; | ||
| env_logger::builder() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.