Skip to content

fix: do not display error when sending benchmark uri #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
4 changes: 4 additions & 0 deletions crates/codspeed/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ pub fn get_formated_function_path(function_path: impl Into<String>) -> String {
function_path.replace(" :: ", "::")
}

pub fn running_with_codspeed_runner() -> bool {
std::env::var("CODSPEED_ENV").is_ok()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/codspeed/src/walltime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn collect_raw_walltime_results(
max_time_ns: Option<u128>,
times_ns: Vec<u128>,
) {
if std::env::var("CODSPEED_ENV").is_err() {
if !crate::utils::running_with_codspeed_runner() {
return;
}
let workspace_root = std::env::var("CODSPEED_CARGO_WORKSPACE_ROOT").map(PathBuf::from);
Expand Down
6 changes: 4 additions & 2 deletions crates/criterion_compat/criterion_fork/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub(crate) fn common<M: Measurement, T: ?Sized>(
}
}

if criterion.should_save_baseline() && std::env::var("CODSPEED_ENV").is_ok() {
if criterion.should_save_baseline() && ::codspeed::utils::running_with_codspeed_runner() {
codspeed::collect_walltime_results(id, criterion, &iters, avg_times);
}
}
Expand Down Expand Up @@ -301,7 +301,9 @@ mod codspeed {
pid: std::process::id(),
uri: uri.clone(),
}) {
eprintln!("Failed to send benchmark URI to runner: {}", error);
if codspeed::utils::running_with_codspeed_runner() {
eprintln!("Failed to send benchmark URI to runner: {error:?}");
}
}

let avg_iter_per_round = iters.iter().sum::<f64>() / iters.len() as f64;
Expand Down
2 changes: 1 addition & 1 deletion crates/criterion_compat/criterion_fork/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ macro_rules! criterion_group {
let mut criterion: $crate::Criterion<_> = $config
.configure_from_args();
$(
if std::env::var("CODSPEED_ENV").is_ok() {
if codspeed::utils::running_with_codspeed_runner() {
criterion.set_current_file($crate::abs_file!());
criterion.set_macro_group(format!("{}::{}", stringify!($name), stringify!($target)));
}
Expand Down
4 changes: 3 additions & 1 deletion crates/divan_compat/divan_fork/src/divan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ mod codspeed {
pid: std::process::id(),
uri: uri.clone(),
}) {
eprintln!("Failed to send benchmark URI to runner: {}", error);
if codspeed::utils::running_with_codspeed_runner() {
eprintln!("Failed to send benchmark URI to runner: {error:?}");
}
}

::codspeed::walltime::collect_raw_walltime_results(
Expand Down
Loading