diff --git a/Cargo.toml b/Cargo.toml index 22b529c9..e5a998b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ object = "0.36.7" linux-perf-data = "0.11.0" debugid = "0.8.0" memmap2 = "0.9.5" -nix = { version = "0.29.0", features = ["fs"] } +nix = { version = "0.29.0", features = ["fs", "user"] } futures = "0.3.31" [target.'cfg(target_os = "linux")'.dependencies] diff --git a/src/run/runner/wall_time/perf/mod.rs b/src/run/runner/wall_time/perf/mod.rs index 0bc1c1c3..cff9b2ac 100644 --- a/src/run/runner/wall_time/perf/mod.rs +++ b/src/run/runner/wall_time/perf/mod.rs @@ -108,13 +108,16 @@ impl PerfRunner { "" } }; + let user = nix::unistd::User::from_uid(nix::unistd::Uid::current())?.unwrap(); cmd.args([ "-c", &format!( - "perf record {quiet_flag} --user-callchains --freq=999 --switch-output --control=fifo:{},{} --delay=-1 -g --call-graph={cg_mode} --output={} -- {bench_cmd}", + "perf record {quiet_flag} --user-callchains --freq=999 --switch-output --control=fifo:{},{} --delay=-1 -g --call-graph={cg_mode} --output={} -- \ + sudo systemd-run --scope --slice=codspeed.slice --same-dir -- runuser -u {} -- {bench_cmd}", perf_fifo.ctl_fifo_path.to_string_lossy(), perf_fifo.ack_fifo_path.to_string_lossy(), - perf_file.path().to_string_lossy() + perf_file.path().to_string_lossy(), + user.name ), ]); debug!("cmd: {:?}", cmd);