Skip to content

Commit cbba43e

Browse files
committed
fix: use systemd-run for non-perf runs
1 parent 555b799 commit cbba43e

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

src/run/runner/wall_time/executor.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use super::perf::PerfRunner;
22
use crate::prelude::*;
33
use crate::run::instruments::mongo_tracer::MongoTracer;
44
use crate::run::runner::executor::Executor;
5+
use crate::run::runner::helpers::env::get_base_injected_env;
56
use crate::run::runner::helpers::get_bench_command::get_bench_command;
67
use crate::run::runner::helpers::run_command_with_log_pipe::run_command_with_log_pipe;
78
use crate::run::runner::{ExecutorName, RunData};
9+
use crate::run::RunnerMode;
810
use crate::run::{check_system::SystemInfo, config::Config};
911
use async_trait::async_trait;
1012
use std::fs::canonicalize;
@@ -27,6 +29,18 @@ impl WallTimeExecutor {
2729
perf: use_perf.then(PerfRunner::new),
2830
}
2931
}
32+
33+
fn walltime_bench_cmd(config: &Config, run_data: &RunData) -> Result<String> {
34+
let bench_cmd = get_bench_command(config)?;
35+
36+
let setenv = get_base_injected_env(RunnerMode::Walltime, &run_data.profile_folder)
37+
.into_iter()
38+
.map(|(env, value)| format!("--setenv={env}={value}"))
39+
.join(" ");
40+
let uid = nix::unistd::Uid::current().as_raw();
41+
let gid = nix::unistd::Gid::current().as_raw();
42+
Ok(format!("sudo systemd-run --scope --slice=codspeed.slice --same-dir --uid={uid} --gid={gid} {setenv} -- {bench_cmd}"))
43+
}
3044
}
3145

3246
#[async_trait(?Send)]
@@ -50,18 +64,16 @@ impl Executor for WallTimeExecutor {
5064
run_data: &RunData,
5165
_mongo_tracer: &Option<MongoTracer>,
5266
) -> Result<()> {
53-
// IMPORTANT: Don't use `sh` here! We will use this pid to send signals to the
54-
// spawned child process which won't work if we use a different shell.
55-
let mut cmd = Command::new("bash");
67+
let mut cmd = Command::new("sh");
5668

5769
if let Some(cwd) = &config.working_directory {
5870
let abs_cwd = canonicalize(cwd)?;
5971
cmd.current_dir(abs_cwd);
6072
}
6173

62-
let bench_cmd = get_bench_command(config)?;
74+
let bench_cmd = Self::walltime_bench_cmd(config, run_data)?;
6375
let status = if let Some(perf) = &self.perf {
64-
perf.run(cmd, &bench_cmd, run_data).await
76+
perf.run(cmd, &bench_cmd).await
6577
} else {
6678
cmd.args(["-c", &bench_cmd]);
6779
debug!("cmd: {:?}", cmd);

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#![cfg_attr(not(unix), allow(dead_code, unused_mut))]
22

33
use crate::prelude::*;
4-
use crate::run::runner::helpers::env::get_base_injected_env;
54
use crate::run::runner::helpers::run_command_with_log_pipe::run_command_with_log_pipe_and_callback;
65
use crate::run::runner::helpers::setup::run_with_sudo;
76
use crate::run::runner::valgrind::helpers::ignored_objects_path::get_objects_path_to_ignore;
87
use crate::run::runner::valgrind::helpers::perf_maps::harvest_perf_maps_for_pids;
9-
use crate::run::runner::RunData;
10-
use crate::run::RunnerMode;
118
use anyhow::Context;
129
use fifo::{PerfFifo, RunnerFifo};
1310
use futures::stream::FuturesUnordered;
@@ -121,12 +118,7 @@ impl PerfRunner {
121118
}
122119
}
123120

124-
pub async fn run(
125-
&self,
126-
mut cmd: Command,
127-
bench_cmd: &str,
128-
run_data: &RunData,
129-
) -> anyhow::Result<ExitStatus> {
121+
pub async fn run(&self, mut cmd: Command, bench_cmd: &str) -> anyhow::Result<ExitStatus> {
130122
let perf_fifo = PerfFifo::new()?;
131123
let runner_fifo = RunnerFifo::new()?;
132124

@@ -163,18 +155,10 @@ impl PerfRunner {
163155
}
164156
};
165157

166-
let setenv = get_base_injected_env(RunnerMode::Walltime, &run_data.profile_folder)
167-
.into_iter()
168-
.map(|(env, value)| format!("--setenv={env}={value}"))
169-
.join(" ");
170-
171-
let uid = nix::unistd::Uid::current().as_raw();
172-
let gid = nix::unistd::Gid::current().as_raw();
173158
cmd.args([
174159
"-c",
175160
&format!(
176-
"sudo perf record {quiet_flag} --user-callchains --freq=999 --switch-output --control=fifo:{},{} --delay=-1 -g --call-graph={cg_mode} --output={} -- \
177-
systemd-run --scope --slice=codspeed.slice --same-dir --uid={uid} --gid={gid} {setenv} -- {bench_cmd}",
161+
"sudo perf record {quiet_flag} --user-callchains --freq=999 --switch-output --control=fifo:{},{} --delay=-1 -g --call-graph={cg_mode} --output={} -- {bench_cmd}",
178162
perf_fifo.ctl_fifo_path.to_string_lossy(),
179163
perf_fifo.ack_fifo_path.to_string_lossy(),
180164
perf_file.path().to_string_lossy(),

0 commit comments

Comments
 (0)