-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathexecutor.rs
More file actions
103 lines (86 loc) · 2.87 KB
/
executor.rs
File metadata and controls
103 lines (86 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use super::perf::PerfRunner;
use crate::prelude::*;
use crate::run::instruments::mongo_tracer::MongoTracer;
use crate::run::runner::executor::Executor;
use crate::run::runner::helpers::env::get_base_injected_env;
use crate::run::runner::helpers::get_bench_command::get_bench_command;
use crate::run::runner::helpers::run_command_with_log_pipe::run_command_with_log_pipe;
use crate::run::runner::{ExecutorName, RunData, RunnerMode};
use crate::run::{check_system::SystemInfo, config::Config};
use async_trait::async_trait;
use std::fs::canonicalize;
use std::process::Command;
pub struct WallTimeExecutor {
perf: Option<PerfRunner>,
}
impl WallTimeExecutor {
pub fn new() -> Self {
let use_perf = if cfg!(target_os = "linux") {
std::env::var("CODSPEED_USE_PERF").is_ok()
} else {
false
};
debug!("Running the cmd with perf: {}", use_perf);
Self {
perf: use_perf.then(PerfRunner::new),
}
}
}
#[async_trait(?Send)]
impl Executor for WallTimeExecutor {
fn name(&self) -> ExecutorName {
ExecutorName::WallTime
}
async fn setup(&self, _system_info: &SystemInfo) -> Result<()> {
if self.perf.is_some() {
PerfRunner::setup_environment()?;
}
Ok(())
}
async fn run(
&self,
config: &Config,
_system_info: &SystemInfo,
run_data: &RunData,
_mongo_tracer: &Option<MongoTracer>,
) -> Result<()> {
// IMPORTANT: Don't use `sh` here! We will use this pid to send signals to the
// spawned child process which won't work if we use a different shell.
let mut cmd = Command::new("bash");
cmd.envs(get_base_injected_env(
RunnerMode::Walltime,
&run_data.profile_folder,
));
if let Some(cwd) = &config.working_directory {
let abs_cwd = canonicalize(cwd)?;
cmd.current_dir(abs_cwd);
}
let bench_cmd = get_bench_command(config)?;
let status = if let Some(perf) = &self.perf {
perf.run(cmd, &bench_cmd).await
} else {
cmd.args(["-c", &bench_cmd]);
debug!("cmd: {:?}", cmd);
run_command_with_log_pipe(cmd).await
};
let status =
status.map_err(|e| anyhow!("failed to execute the benchmark process. {}", e))?;
debug!("cmd exit status: {:?}", status);
if !status.success() {
bail!("failed to execute the benchmark process: {}", status);
}
Ok(())
}
async fn teardown(
&self,
_config: &Config,
_system_info: &SystemInfo,
run_data: &RunData,
) -> Result<()> {
debug!("Copying files to the profile folder");
if let Some(perf) = &self.perf {
perf.save_files_to(&run_data.profile_folder).await?;
}
Ok(())
}
}