Skip to content
Closed
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
21 changes: 21 additions & 0 deletions src/run_environment/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub trait RunEnvironmentProvider {
instruments: config.instruments.get_active_instrument_names(),
executor: executor_name,
exclude_allocations: config.exclude_allocations,
isolation: get_runner_isolation(),
system_info: system_info.clone(),
},
run_environment: self.get_run_environment(),
Expand All @@ -158,6 +159,13 @@ pub trait RunEnvironmentProvider {
}
}

fn get_runner_isolation() -> Option<String> {
std::env::var("CODSPEED_RUNNER_ISOLATION")
.ok()
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty())
}

fn get_commit_hash_default_impl(repository_root_path: &str) -> Result<String> {
let repo = Repository::open(repository_root_path).context(format!(
"Failed to open repository at path: {repository_root_path}"
Expand All @@ -182,4 +190,17 @@ mod tests {
// ensure that the commit hash is correct, thus it has 40 characters
assert_eq!(commit_hash.len(), 40);
}

#[test]
fn test_get_runner_isolation() {
temp_env::with_var("CODSPEED_RUNNER_ISOLATION", Some(" strict "), || {
assert_eq!(get_runner_isolation(), Some("strict".into()));
});
temp_env::with_var("CODSPEED_RUNNER_ISOLATION", Some(" "), || {
assert_eq!(get_runner_isolation(), None);
});
temp_env::with_var_unset("CODSPEED_RUNNER_ISOLATION", || {
assert_eq!(get_runner_isolation(), None);
});
}
}
4 changes: 4 additions & 0 deletions src/upload/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pub struct Runner {
/// byte-identical to legacy runs that predate this field.
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub exclude_allocations: bool,
/// Isolation level of the machine running the benchmarks, as reported by
/// the environment through `CODSPEED_RUNNER_ISOLATION`.
#[serde(skip_serializing_if = "Option::is_none")]
pub isolation: Option<String>,
#[serde(flatten)]
pub system_info: SystemInfo,
}
Expand Down
2 changes: 2 additions & 0 deletions src/upload/upload_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod tests {
instruments: vec![InstrumentName::MongoDB],
executor: ExecutorName::Valgrind,
exclude_allocations: false,
isolation: None,
system_info: SystemInfo::test(),
},
run_environment: RunEnvironment::GithubActions,
Expand Down Expand Up @@ -108,6 +109,7 @@ mod tests {
instruments: vec![],
executor: ExecutorName::Valgrind,
exclude_allocations: false,
isolation: None,
system_info: SystemInfo {
os: crate::system::SupportedOs::Linux(
crate::system::LinuxDistribution::Other {
Expand Down
Loading