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
52 changes: 50 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codspeed-runner"
version = "4.2.1"
version = "4.3.0-beta.0"
edition = "2024"
repository = "https://github.com/CodSpeedHQ/runner"
publish = false
Expand Down Expand Up @@ -60,6 +60,7 @@ shellexpand = { version = "3.1.1", features = ["tilde"] }
addr2line = "0.25"
gimli = "0.32"
open = "5.3.2"
tabled = "0.17"

[target.'cfg(target_os = "linux")'.dependencies]
procfs = "0.17.0"
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use log::log_enabled;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const MONGODB_TRACER_VERSION: &str = "cs-mongo-tracer-v0.2.0";

const VALGRIND_CODSPEED_BASE_VERSION: &str = "3.24.0";
const VALGRIND_CODSPEED_BASE_VERSION: &str = "3.25.1";
lazy_static! {
pub static ref VALGRIND_CODSPEED_VERSION: String =
format!("{VALGRIND_CODSPEED_BASE_VERSION}.codspeed");
pub static ref VALGRIND_CODSPEED_DEB_VERSION: String =
format!("{VALGRIND_CODSPEED_BASE_VERSION}-0codspeed1");
format!("{VALGRIND_CODSPEED_BASE_VERSION}-3codspeed1");
}

#[tokio::main(flavor = "current_thread")]
Expand Down
78 changes: 72 additions & 6 deletions src/run/poll_results.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::time::Duration;

use console::style;
use tabled::settings::Style;
use tabled::{Table, Tabled};
use tokio::time::{Instant, sleep};

use crate::api_client::{
Expand All @@ -14,6 +16,26 @@ use super::run_environment::RunEnvironmentProvider;
const RUN_PROCESSING_MAX_DURATION: Duration = Duration::from_secs(60 * 5); // 5 minutes
const POLLING_INTERVAL: Duration = Duration::from_secs(1);

#[derive(Tabled)]
struct BenchmarkRow {
#[tabled(rename = "Benchmark")]
name: String,
#[tabled(rename = "Time")]
time: String,
}

fn build_benchmark_table(results: &[crate::api_client::FetchLocalRunBenchmarkResult]) -> String {
let table_rows: Vec<BenchmarkRow> = results
.iter()
.map(|result| BenchmarkRow {
name: result.benchmark.name.clone(),
time: helpers::format_duration(result.time, Some(2)),
})
.collect();

Table::new(&table_rows).with(Style::modern()).to_string()
}

#[allow(clippy::borrowed_box)]
pub async fn poll_results(
api_client: &CodSpeedAPIClient,
Expand Down Expand Up @@ -100,21 +122,65 @@ pub async fn poll_results(

if !response.run.results.is_empty() {
start_group!("Benchmark results");
for result in response.run.results {
let benchmark_name = result.benchmark.name;
let time = helpers::format_duration(result.time, Some(2));

info!("{}: {}", benchmark_name, style(time).bold());
let table = build_benchmark_table(&response.run.results);
info!("\n{table}");

if output_json {
if output_json {
for result in response.run.results {
log_json!(format!(
"{{\"event\": \"benchmark_ran\", \"name\": \"{}\", \"time\": \"{}\"}}",
benchmark_name, result.time,
result.benchmark.name, result.time,
));
}
}

end_group!();
}

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use crate::api_client::{FetchLocalRunBenchmark, FetchLocalRunBenchmarkResult};

#[test]
fn test_benchmark_table_formatting() {
let results = vec![
FetchLocalRunBenchmarkResult {
benchmark: FetchLocalRunBenchmark {
name: "benchmark_fast".to_string(),
},
time: 0.001234, // 1.23 ms
},
FetchLocalRunBenchmarkResult {
benchmark: FetchLocalRunBenchmark {
name: "benchmark_slow".to_string(),
},
time: 1.5678, // 1.57 s
},
FetchLocalRunBenchmarkResult {
benchmark: FetchLocalRunBenchmark {
name: "benchmark_medium".to_string(),
},
time: 0.000567, // 567 µs
},
];

let table = build_benchmark_table(&results);

insta::assert_snapshot!(table, @r###"
┌──────────────────┬───────────┐
│ Benchmark │ Time │
├──────────────────┼───────────┤
│ benchmark_fast │ 1.23 ms │
├──────────────────┼───────────┤
│ benchmark_slow │ 1.57 s │
├──────────────────┼───────────┤
│ benchmark_medium │ 567.00 µs │
└──────────────────┴───────────┘
"###);
}
}
1 change: 1 addition & 0 deletions src/run/runner/valgrind/measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lazy_static! {
"-q",
"--tool=callgrind",
"--trace-children=yes",
"--read-inline-info=yes",
"--cache-sim=yes",
"--I1=32768,8,64",
"--D1=32768,8,64",
Expand Down
8 changes: 4 additions & 4 deletions src/run/runner/valgrind/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod tests {
};
assert_snapshot!(
get_codspeed_valgrind_filename(&system_info).unwrap(),
@"valgrind_3.24.0-0codspeed1_ubuntu-22.04_amd64.deb"
@"valgrind_3.25.1-3codspeed1_ubuntu-22.04_amd64.deb"
);
}

Expand All @@ -117,7 +117,7 @@ mod tests {
};
assert_snapshot!(
get_codspeed_valgrind_filename(&system_info).unwrap(),
@"valgrind_3.24.0-0codspeed1_ubuntu-24.04_amd64.deb"
@"valgrind_3.25.1-3codspeed1_ubuntu-24.04_amd64.deb"
);
}

Expand All @@ -131,7 +131,7 @@ mod tests {
};
assert_snapshot!(
get_codspeed_valgrind_filename(&system_info).unwrap(),
@"valgrind_3.24.0-0codspeed1_ubuntu-22.04_amd64.deb"
@"valgrind_3.25.1-3codspeed1_ubuntu-22.04_amd64.deb"
);
}

Expand All @@ -145,7 +145,7 @@ mod tests {
};
assert_snapshot!(
get_codspeed_valgrind_filename(&system_info).unwrap(),
@"valgrind_3.24.0-0codspeed1_ubuntu-22.04_arm64.deb"
@"valgrind_3.25.1-3codspeed1_ubuntu-22.04_arm64.deb"
);
}
}