Skip to content

Commit fc71ca0

Browse files
committed
feat(executor): add cmd base env to all executors
1 parent 80ef05d commit fc71ca0

4 files changed

Lines changed: 36 additions & 25 deletions

File tree

src/run/runner/executor.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use async_trait::async_trait;
2-
1+
use super::helpers::env::BASE_INJECTED_ENV;
32
use super::interfaces::{ExecutorName, RunData};
43
use crate::prelude::*;
54
use crate::run::instruments::mongo_tracer::MongoTracer;
65
use crate::run::{check_system::SystemInfo, config::Config};
6+
use async_trait::async_trait;
7+
use std::collections::HashMap;
8+
use std::path::Path;
79

810
#[async_trait(?Send)]
911
pub trait Executor {
@@ -32,4 +34,17 @@ pub trait Executor {
3234
system_info: &SystemInfo,
3335
run_data: &RunData,
3436
) -> Result<()>;
37+
38+
/// Gets the base environment for the command
39+
///
40+
/// Later on, we will want to refactor this and create the cmd directly in a trait function
41+
fn get_cmd_base_envs(&self, profile_folder: &Path) -> HashMap<&str, String> {
42+
let mut hashmap = BASE_INJECTED_ENV.clone();
43+
hashmap.insert("CODSPEED_RUNNER_MODE", self.name().to_string());
44+
hashmap.insert(
45+
"CODSPEED_PROFILE_FOLDER",
46+
profile_folder.to_str().unwrap().to_string(),
47+
);
48+
hashmap
49+
}
3550
}

src/run/runner/valgrind/executor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ impl Executor for ValgrindExecutor {
3636
run_data: &RunData,
3737
mongo_tracer: &Option<MongoTracer>,
3838
) -> Result<()> {
39+
let base_env = self.get_cmd_base_envs(&run_data.profile_folder);
40+
3941
//TODO: add valgrind version check
40-
measure::measure(config, &run_data.profile_folder, mongo_tracer)?;
42+
measure::measure(&base_env, config, &run_data.profile_folder, mongo_tracer)?;
4143

4244
Ok(())
4345
}

src/run/runner/valgrind/measure.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::prelude::*;
2-
use crate::run::runner::helpers::env::BASE_INJECTED_ENV;
32
use crate::run::runner::helpers::get_bench_command::get_bench_command;
43
use crate::run::runner::helpers::run_command_with_log_pipe::run_command_with_log_pipe;
54
use crate::run::runner::valgrind::helpers::ignored_objects_path::get_objects_path_to_ignore;
65
use crate::run::runner::valgrind::helpers::introspected_nodejs::setup_introspected_nodejs;
76
use crate::run::{config::Config, instruments::mongo_tracer::MongoTracer};
87
use lazy_static::lazy_static;
8+
use std::collections::HashMap;
99
use std::env;
1010
use std::fs::canonicalize;
1111
use std::path::Path;
@@ -42,27 +42,28 @@ lazy_static! {
4242
}
4343

4444
pub fn measure(
45+
base_env: &HashMap<&str, String>,
4546
config: &Config,
4647
profile_folder: &Path,
4748
mongo_tracer: &Option<MongoTracer>,
4849
) -> Result<()> {
4950
// Create the command
5051
let mut cmd = Command::new("setarch");
52+
cmd.envs(base_env);
5153
cmd.arg(ARCH).arg("-R");
5254
// Configure the environment
53-
cmd.envs(BASE_INJECTED_ENV.iter())
54-
.env(
55-
"PATH",
56-
format!(
57-
"{}:{}",
58-
setup_introspected_nodejs()
59-
.map_err(|e| anyhow!("failed to setup NodeJS introspection. {}", e))?
60-
.to_str()
61-
.unwrap(),
62-
env::var("PATH").unwrap_or_default(),
63-
),
64-
)
65-
.env("PYTHONMALLOC", "malloc");
55+
cmd.env(
56+
"PATH",
57+
format!(
58+
"{}:{}",
59+
setup_introspected_nodejs()
60+
.map_err(|e| anyhow!("failed to setup NodeJS introspection. {}", e))?
61+
.to_str()
62+
.unwrap(),
63+
env::var("PATH").unwrap_or_default(),
64+
),
65+
)
66+
.env("PYTHONMALLOC", "malloc");
6667

6768
if let Some(cwd) = &config.working_directory {
6869
let abs_cwd = canonicalize(cwd)?;

src/run/runner/wall_time/executor.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::prelude::*;
22

33
use crate::run::instruments::mongo_tracer::MongoTracer;
44
use crate::run::runner::executor::Executor;
5-
use crate::run::runner::helpers::env::BASE_INJECTED_ENV;
65
use crate::run::runner::helpers::get_bench_command::get_bench_command;
76
use crate::run::runner::helpers::run_command_with_log_pipe::run_command_with_log_pipe;
87
use crate::run::runner::{ExecutorName, RunData};
@@ -38,13 +37,7 @@ impl Executor for WallTimeExecutor {
3837
_mongo_tracer: &Option<MongoTracer>,
3938
) -> Result<()> {
4039
let mut cmd = Command::new("sh");
41-
42-
cmd.env("CODSPEED_RUNNER_MODE", &self.name().to_string())
43-
.env(
44-
"CODSPEED_PROFILE_FOLDER",
45-
run_data.profile_folder.to_str().unwrap(),
46-
)
47-
.envs(BASE_INJECTED_ENV.iter());
40+
cmd.envs(self.get_cmd_base_envs(&run_data.profile_folder));
4841

4942
if let Some(cwd) = &config.working_directory {
5043
let abs_cwd = canonicalize(cwd)?;

0 commit comments

Comments
 (0)