diff --git a/Cargo.lock b/Cargo.lock index 07fa5ac4..5860cd48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,6 +211,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "bytecount" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" + [[package]] name = "byteorder" version = "1.5.0" @@ -286,7 +292,7 @@ version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.96", @@ -300,7 +306,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "codspeed-runner" -version = "4.2.1" +version = "4.3.0-beta.0" dependencies = [ "addr2line 0.25.1", "anyhow", @@ -345,6 +351,7 @@ dependencies = [ "shellexpand", "simplelog", "sysinfo", + "tabled", "temp-env", "tempfile", "test-with", @@ -798,6 +805,12 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -1515,6 +1528,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "papergrid" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2b0f8def1f117e13c895f3eda65a7b5650688da29d6ad04635f61bc7b92eebd" +dependencies = [ + "bytecount", + "fnv", + "unicode-width", +] + [[package]] name = "parking_lot" version = "0.11.2" @@ -2329,6 +2353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", + "quote", "unicode-ident", ] @@ -2396,6 +2421,29 @@ dependencies = [ "libc", ] +[[package]] +name = "tabled" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6709222f3973137427ce50559cd564dc187a95b9cfe01613d2f4e93610e510a" +dependencies = [ + "papergrid", + "tabled_derive", +] + +[[package]] +name = "tabled_derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "931be476627d4c54070a1f3a9739ccbfec9b36b39815106a20cce2243bbcefe1" +dependencies = [ + "heck 0.4.1", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "task-local-extensions" version = "0.1.4" diff --git a/Cargo.toml b/Cargo.toml index f7770a32..9f5767e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 @@ -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" diff --git a/src/main.rs b/src/main.rs index 27099496..a77b2379 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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")] diff --git a/src/run/poll_results.rs b/src/run/poll_results.rs index 255c5019..06319cfd 100644 --- a/src/run/poll_results.rs +++ b/src/run/poll_results.rs @@ -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::{ @@ -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 = 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, @@ -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 │ + └──────────────────┴───────────┘ + "###); + } +} diff --git a/src/run/runner/valgrind/measure.rs b/src/run/runner/valgrind/measure.rs index 460010a2..bd274418 100644 --- a/src/run/runner/valgrind/measure.rs +++ b/src/run/runner/valgrind/measure.rs @@ -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", diff --git a/src/run/runner/valgrind/setup.rs b/src/run/runner/valgrind/setup.rs index 1c08e636..24d9a579 100644 --- a/src/run/runner/valgrind/setup.rs +++ b/src/run/runner/valgrind/setup.rs @@ -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" ); } @@ -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" ); } @@ -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" ); } @@ -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" ); } }