Skip to content

Commit 78c8329

Browse files
committed
fix(perf): run with --scope to allow perf to trace the benchmark process
1 parent bfe766f commit 78c8329

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/run/runner/wall_time/executor.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ impl WallTimeExecutor {
3434
.into_iter()
3535
.map(|(k, v)| (k.into(), v)),
3636
)
37-
.map(|(env, value)| format!("{env}={value}"))
37+
.map(|(env, value)| {
38+
// Properly quote the value to handle special characters
39+
let escaped_value = value.replace("\\", "\\\\").replace("\"", "\\\"");
40+
format!("export {env}=\"{escaped_value}\"")
41+
})
3842
.collect::<Vec<_>>()
3943
.join("\n");
4044

@@ -49,8 +53,10 @@ impl WallTimeExecutor {
4953

5054
let uid = nix::unistd::Uid::current().as_raw();
5155
let gid = nix::unistd::Gid::current().as_raw();
56+
57+
// Note: We're using --scope so that perf is able to capture the events of the benchmark process.
5258
let cmd = format!(
53-
"systemd-run {quiet_flag} --pipe --collect --wait --slice=codspeed.slice --same-dir --uid={uid} --gid={gid} --property=EnvironmentFile={} -- sh -c '{}'",
59+
"systemd-run {quiet_flag} --scope --slice=codspeed.slice --same-dir --uid={uid} --gid={gid} -- sh -c 'source {} && {}'",
5460
env_file.path().display(),
5561
bench_cmd.replace("'", "\"")
5662
);

src/run/runner/wall_time/perf/helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::collections::HashMap;
2-
3-
use anyhow::{anyhow, bail};
1+
use crate::prelude::*;
42
use linux_perf_data::{PerfFileReader, PerfFileRecord, linux_perf_event_reader::EventRecord};
3+
use std::collections::HashMap;
54

65
/// Tries to find the pid of the sampled process within a perf.data file.
76
pub fn find_pid<P: AsRef<std::path::Path>>(perf_file: P) -> anyhow::Result<i32> {
@@ -48,6 +47,7 @@ pub fn find_pid<P: AsRef<std::path::Path>>(perf_file: P) -> anyhow::Result<i32>
4847
}
4948
}
5049
}
50+
debug!("Pid frequency: {pid_freq:?}");
5151

5252
// Choose the pid with the highest frequency. However, we can only use a pid if more than N% of the
5353
// events are from that pid.

src/run/runner/wall_time/perf/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ impl PerfRunner {
251251
let perf_map_pids = futures::future::try_join_all(copy_tasks)
252252
.await?
253253
.into_iter()
254-
.filter_map(Result::ok)
254+
.filter_map(|result| {
255+
debug!("Copy task result: {result:?}");
256+
result.ok()
257+
})
255258
.collect::<HashSet<_>>();
256259
harvest_perf_maps_for_pids(profile_folder, &perf_map_pids).await?;
257260

0 commit comments

Comments
 (0)