Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/run/runner/executor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use async_trait::async_trait;

use super::helpers::env::BASE_INJECTED_ENV;
use super::interfaces::{ExecutorName, RunData};
use crate::prelude::*;
use crate::run::instruments::mongo_tracer::MongoTracer;
use crate::run::{check_system::SystemInfo, config::Config};
use async_trait::async_trait;
use std::collections::HashMap;
use std::path::Path;

#[async_trait(?Send)]
pub trait Executor {
Expand Down Expand Up @@ -32,4 +34,17 @@ pub trait Executor {
system_info: &SystemInfo,
run_data: &RunData,
) -> Result<()>;

/// Gets the base environment for the command
///
/// Later on, we will want to refactor this and create the cmd directly in a trait function
fn get_cmd_base_envs(&self, profile_folder: &Path) -> HashMap<&str, String> {
let mut hashmap = BASE_INJECTED_ENV.clone();
hashmap.insert("CODSPEED_RUNNER_MODE", self.name().to_string());
hashmap.insert(
"CODSPEED_PROFILE_FOLDER",
profile_folder.to_str().unwrap().to_string(),
);
hashmap
}
}
4 changes: 3 additions & 1 deletion src/run/runner/valgrind/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ impl Executor for ValgrindExecutor {
run_data: &RunData,
mongo_tracer: &Option<MongoTracer>,
) -> Result<()> {
let base_env = self.get_cmd_base_envs(&run_data.profile_folder);

//TODO: add valgrind version check
measure::measure(config, &run_data.profile_folder, mongo_tracer)?;
measure::measure(&base_env, config, &run_data.profile_folder, mongo_tracer)?;

Ok(())
}
Expand Down
29 changes: 15 additions & 14 deletions src/run/runner/valgrind/measure.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::prelude::*;
use crate::run::runner::helpers::env::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::valgrind::helpers::ignored_objects_path::get_objects_path_to_ignore;
use crate::run::runner::valgrind::helpers::introspected_nodejs::setup_introspected_nodejs;
use crate::run::{config::Config, instruments::mongo_tracer::MongoTracer};
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::env;
use std::fs::canonicalize;
use std::path::Path;
Expand Down Expand Up @@ -42,27 +42,28 @@ lazy_static! {
}

pub fn measure(
base_env: &HashMap<&str, String>,
config: &Config,
profile_folder: &Path,
mongo_tracer: &Option<MongoTracer>,
) -> Result<()> {
// Create the command
let mut cmd = Command::new("setarch");
cmd.envs(base_env);
cmd.arg(ARCH).arg("-R");
// Configure the environment
cmd.envs(BASE_INJECTED_ENV.iter())
.env(
"PATH",
format!(
"{}:{}",
setup_introspected_nodejs()
.map_err(|e| anyhow!("failed to setup NodeJS introspection. {}", e))?
.to_str()
.unwrap(),
env::var("PATH").unwrap_or_default(),
),
)
.env("PYTHONMALLOC", "malloc");
cmd.env(
"PATH",
format!(
"{}:{}",
setup_introspected_nodejs()
.map_err(|e| anyhow!("failed to setup NodeJS introspection. {}", e))?
.to_str()
.unwrap(),
env::var("PATH").unwrap_or_default(),
),
)
.env("PYTHONMALLOC", "malloc");

if let Some(cwd) = &config.working_directory {
let abs_cwd = canonicalize(cwd)?;
Expand Down
9 changes: 1 addition & 8 deletions src/run/runner/wall_time/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::prelude::*;

use crate::run::instruments::mongo_tracer::MongoTracer;
use crate::run::runner::executor::Executor;
use crate::run::runner::helpers::env::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};
Expand Down Expand Up @@ -38,13 +37,7 @@ impl Executor for WallTimeExecutor {
_mongo_tracer: &Option<MongoTracer>,
) -> Result<()> {
let mut cmd = Command::new("sh");

cmd.env("CODSPEED_RUNNER_MODE", &self.name().to_string())
.env(
"CODSPEED_PROFILE_FOLDER",
run_data.profile_folder.to_str().unwrap(),
)
.envs(BASE_INJECTED_ENV.iter());
cmd.envs(self.get_cmd_base_envs(&run_data.profile_folder));

if let Some(cwd) = &config.working_directory {
let abs_cwd = canonicalize(cwd)?;
Expand Down
Loading