Skip to content

Commit 5caa771

Browse files
committed
refactor: use helper to check if running with codspeed runner
1 parent 72f283d commit 5caa771

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

crates/codspeed/src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ pub fn get_formated_function_path(function_path: impl Into<String>) -> String {
3838
function_path.replace(" :: ", "::")
3939
}
4040

41+
pub fn running_with_codspeed_runner() -> bool {
42+
std::env::var("CODSPEED_ENV").is_ok()
43+
}
44+
4145
#[cfg(test)]
4246
mod tests {
4347
use super::*;

crates/codspeed/src/walltime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn collect_raw_walltime_results(
5858
max_time_ns: Option<u128>,
5959
times_ns: Vec<u128>,
6060
) {
61-
if std::env::var("CODSPEED_ENV").is_err() {
61+
if !crate::utils::running_with_codspeed_runner() {
6262
return;
6363
}
6464
let workspace_root = std::env::var("CODSPEED_CARGO_WORKSPACE_ROOT").map(PathBuf::from);

crates/criterion_compat/criterion_fork/src/analysis/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub(crate) fn common<M: Measurement, T: ?Sized>(
257257
}
258258
}
259259

260-
if criterion.should_save_baseline() && std::env::var("CODSPEED_ENV").is_ok() {
260+
if criterion.should_save_baseline() && ::codspeed::utils::running_with_codspeed_runner() {
261261
codspeed::collect_walltime_results(id, criterion, &iters, avg_times);
262262
}
263263
}
@@ -301,7 +301,7 @@ mod codspeed {
301301
pid: std::process::id(),
302302
uri: uri.clone(),
303303
}) {
304-
if std::env::var("CODSPEED_ENV").is_ok() {
304+
if codspeed::utils::running_with_codspeed_runner() {
305305
eprintln!("Failed to send benchmark URI to runner: {error:?}");
306306
}
307307
}

crates/criterion_compat/criterion_fork/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ macro_rules! criterion_group {
6868
let mut criterion: $crate::Criterion<_> = $config
6969
.configure_from_args();
7070
$(
71-
if std::env::var("CODSPEED_ENV").is_ok() {
71+
if codspeed::utils::running_with_codspeed_runner() {
7272
criterion.set_current_file($crate::abs_file!());
7373
criterion.set_macro_group(format!("{}::{}", stringify!($name), stringify!($target)));
7474
}

crates/divan_compat/divan_fork/src/divan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ mod codspeed {
432432
pid: std::process::id(),
433433
uri: uri.clone(),
434434
}) {
435-
if std::env::var("CODSPEED_ENV").is_ok() {
435+
if codspeed::utils::running_with_codspeed_runner() {
436436
eprintln!("Failed to send benchmark URI to runner: {error:?}");
437437
}
438438
}

0 commit comments

Comments
 (0)