Skip to content

Commit 8cd6fe8

Browse files
committed
feat: improve results display when running locally
1 parent 4134736 commit 8cd6fe8

3 files changed

Lines changed: 76 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ shellexpand = { version = "3.1.1", features = ["tilde"] }
6060
addr2line = "0.25"
6161
gimli = "0.32"
6262
open = "5.3.2"
63+
tabled = "0.17"
6364

6465
[target.'cfg(target_os = "linux")'.dependencies]
6566
procfs = "0.17.0"

src/run/poll_results.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::time::Duration;
22

33
use console::style;
4+
use tabled::{Table, Tabled};
45
use tokio::time::{Instant, sleep};
56

67
use crate::api_client::{
@@ -14,6 +15,14 @@ use super::run_environment::RunEnvironmentProvider;
1415
const RUN_PROCESSING_MAX_DURATION: Duration = Duration::from_secs(60 * 5); // 5 minutes
1516
const POLLING_INTERVAL: Duration = Duration::from_secs(1);
1617

18+
#[derive(Tabled)]
19+
struct BenchmarkRow {
20+
#[tabled(rename = "Benchmark")]
21+
name: String,
22+
#[tabled(rename = "Time")]
23+
time: String,
24+
}
25+
1726
#[allow(clippy::borrowed_box)]
1827
pub async fn poll_results(
1928
api_client: &CodSpeedAPIClient,
@@ -100,19 +109,29 @@ pub async fn poll_results(
100109

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

107-
info!("{}: {}", benchmark_name, style(time).bold());
108-
109-
if output_json {
113+
let table_rows: Vec<BenchmarkRow> = response
114+
.run
115+
.results
116+
.iter()
117+
.map(|result| BenchmarkRow {
118+
name: result.benchmark.name.clone(),
119+
time: helpers::format_duration(result.time, Some(2)),
120+
})
121+
.collect();
122+
123+
let table = Table::new(&table_rows).to_string();
124+
info!("\n{table}");
125+
126+
if output_json {
127+
for result in response.run.results {
110128
log_json!(format!(
111129
"{{\"event\": \"benchmark_ran\", \"name\": \"{}\", \"time\": \"{}\"}}",
112-
benchmark_name, result.time,
130+
result.benchmark.name, result.time,
113131
));
114132
}
115133
}
134+
116135
end_group!();
117136
}
118137

0 commit comments

Comments
 (0)