MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / perform_with_valgrind

Function perform_with_valgrind

crates/exec-harness/src/analysis/mod.rs:44–76  ·  view source on GitHub ↗

Executes the given benchmark commands using a preload based trick to handle valgrind control. This function is only supported on Unix-like platforms, as it relies on the `LD_PRELOAD` environment variable and Unix file permissions for shared libraries. It will not work on non-Unix platforms or with statically linked binaries.

(commands: Vec<BenchmarkCommand>)

Source from the content-addressed store, hash-verified

42/// `LD_PRELOAD` environment variable and Unix file permissions for shared libraries.
43/// It will not work on non-Unix platforms or with statically linked binaries.
44pub fn perform_with_valgrind(commands: Vec<BenchmarkCommand>) -> Result<()> {
45 let preload_lib_path = preload_lib_file::get_preload_lib_path()?;
46
47 for benchmark_cmd in commands {
48 // Check if the executable will honor LD_PRELOAD before running
49 ld_preload_check::check_ld_preload_compatible(&benchmark_cmd.command[0])?;
50
51 let name_and_uri = uri::generate_name_and_uri(&benchmark_cmd.name, &benchmark_cmd.command);
52 name_and_uri.print_executing();
53
54 let mut cmd = Command::new(&benchmark_cmd.command[0]);
55 cmd.args(&benchmark_cmd.command[1..]);
56 // Use LD_PRELOAD to inject instrumentation into the child process
57 cmd.env("LD_PRELOAD", preload_lib_path);
58 // Make sure python processes output perf maps. This is usually done by `pytest-codspeed`
59 cmd.env("PYTHONPERFSUPPORT", "1");
60 cmd.env(constants::URI_ENV, &name_and_uri.uri);
61
62 crate::node::set_node_options(&mut cmd);
63
64 let mut child = cmd.spawn().context("Failed to spawn command")?;
65
66 let status = child.wait().context("Failed to execute command")?;
67
68 bail_if_command_spawned_subprocesses_under_valgrind(child.id())?;
69
70 if !status.success() {
71 bail!("Command exited with non-zero status: {status}");
72 }
73 }
74
75 Ok(())
76}
77
78/// Checks if the benchmark process spawned subprocesses under valgrind by looking for <pid>.out
79/// files in the profile folder.

Callers 1

execute_benchmarksFunction · 0.85

Calls 9

get_preload_lib_pathFunction · 0.85
generate_name_and_uriFunction · 0.85
set_node_optionsFunction · 0.85
print_executingMethod · 0.80
argsMethod · 0.80
envMethod · 0.80
idMethod · 0.80

Tested by

no test coverage detected