Address review feedback

This commit is contained in:
David Peter committed 2026-10-05 14:16:33 +02:00
1 parent ce704016f9
commit 0f2871bd66
2 files changed
+60 -39

No files matched your search

+28 -12
View File
@@ -6,6 +6,7 @@ pub mod scheduler;
use std::cmp; use std::cmp;
use std::io::{self, Write}; use std::io::{self, Write};
use std::time::Instant;
use crate::benchmark::executor::BenchmarkIteration; use crate::benchmark::executor::BenchmarkIteration;
use crate::command::Command; use crate::command::Command;
@@ -15,7 +16,7 @@ use crate::options::{
use crate::outlier_detection::OUTLIER_THRESHOLD; use crate::outlier_detection::OUTLIER_THRESHOLD;
use crate::output::console_writeln; use crate::output::console_writeln;
use crate::output::progress_bar::{ use crate::output::progress_bar::{
get_progress_bar, replace_message_template, reset_progress_template, finish_initial_measurement, get_progress_bar, start_initial_measurement,
}; };
use crate::output::warnings::{OutlierWarningOptions, Warnings}; use crate::output::warnings::{OutlierWarningOptions, Warnings};
use crate::parameter::ParameterNameAndValue; use crate::parameter::ParameterNameAndValue;
@@ -244,13 +245,15 @@ impl<'a> Benchmark<'a> {
// Set up progress bar (and spinner for initial measurement) // Set up progress bar (and spinner for initial measurement)
let progress_bar = if self.options.output_style != OutputStyleOption::Disabled { let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {
let temp_bar = get_progress_bar( Some(get_progress_bar(
self.options.run_bounds.min, self.options.run_bounds.min,
"Initial time measurement:", if preparation_command.is_some() {
"Running preparation command"
} else {
"Initial run"
},
self.options.output_style, self.options.output_style,
); ))
let template = format!("{{msg}} {{elapsed:<{}}}", 30 - temp_bar.message().len() - 1,);
Some(replace_message_template(temp_bar, &template))
} else { } else {
None None
}; };
@@ -262,6 +265,9 @@ impl<'a> Benchmark<'a> {
}); });
// Initial timing run // Initial timing run
if let Some(bar) = progress_bar.as_ref() {
start_initial_measurement(bar, Instant::now());
}
let res = self.executor.run_command_and_measure( let res = self.executor.run_command_and_measure(
self.command, self.command,
benchmark_iteration, benchmark_iteration,
@@ -270,6 +276,18 @@ impl<'a> Benchmark<'a> {
)?; )?;
let success = res.exit_status.success(); let success = res.exit_status.success();
if let Some(bar) = progress_bar.as_ref() {
let time_unit = self
.options
.time_unit
.unwrap_or(res.time_wall_clock.suitable_unit());
let estimate = res.time_wall_clock.format(time_unit);
finish_initial_measurement(
bar,
format!("Current estimate: {}", estimate.to_string().green()),
);
}
let conclusion_result = run_conclusion_command(benchmark_iteration)?; let conclusion_result = run_conclusion_command(benchmark_iteration)?;
let conclusion_overhead = conclusion_result.map_or(Time::zero(), |res| { let conclusion_overhead = conclusion_result.map_or(Time::zero(), |res| {
res.time_wall_clock + self.executor.time_overhead() res.time_wall_clock + self.executor.time_overhead()
@@ -302,18 +320,14 @@ impl<'a> Benchmark<'a> {
all_succeeded = all_succeeded && success; all_succeeded = all_succeeded && success;
// Re-configure the progress bar // Re-configure the progress bar
let progress_bar = progress_bar.map(reset_progress_template);
if let Some(bar) = progress_bar.as_ref() { if let Some(bar) = progress_bar.as_ref() {
bar.set_length(count) bar.set_length(count);
} bar.inc(1);
if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
} }
// Gather statistics (perform the actual benchmark) // Gather statistics (perform the actual benchmark)
for i in 0..count_remaining { for i in 0..count_remaining {
let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1); let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);
run_preparation_command(benchmark_iteration)?;
let msg = { let msg = {
let t_wall_clock_mean = measurements.time_wall_clock_mean(); let t_wall_clock_mean = measurements.time_wall_clock_mean();
@@ -329,6 +343,8 @@ impl<'a> Benchmark<'a> {
bar.set_message(msg.to_owned()) bar.set_message(msg.to_owned())
} }
run_preparation_command(benchmark_iteration)?;
let res = self.executor.run_command_and_measure( let res = self.executor.run_command_and_measure(
self.command, self.command,
benchmark_iteration, benchmark_iteration,
+32 -27
View File
@@ -1,5 +1,6 @@
use indicatif::{ProgressBar, ProgressStyle}; use indicatif::{FormattedDuration, ProgressBar, ProgressState, ProgressStyle};
use std::time::Duration; use std::fmt;
use std::time::{Duration, Instant};
use crate::options::OutputStyleOption; use crate::options::OutputStyleOption;
@@ -9,42 +10,46 @@ const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);
#[cfg(windows)] #[cfg(windows)]
const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200); const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);
const DEFAULT_MESSAGE_TEMPLATE: &str = "{msg:<30}"; // Keep the message area 30 columns wide across preparation, the initial run,
// and estimates so that switching between them does not move the bar.
const DEFAULT_TEMPLATE: &str = " {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ";
const INITIAL_TEMPLATE: &str =
" {spinner} Initial run: {initial_elapsed:<17} {wide_bar} ETA {eta_precise} ";
fn create_progress_template(msg_template: &str) -> String { /// Show the time elapsed since the initial benchmark command started.
format!( pub fn start_initial_measurement(bar: &ProgressBar, started: Instant) {
" {{spinner}} {} {{wide_bar}} ETA {{eta_precise}} ", // Keep a separate clock: the progress bar's clock and ETA estimator must
msg_template // continue to include preparation time.
) let style = bar
.style()
.template(INITIAL_TEMPLATE)
.expect("no template error")
.with_key(
"initial_elapsed",
move |_: &ProgressState, w: &mut dyn fmt::Write| {
write!(w, "{}", FormattedDuration(started.elapsed())).unwrap();
},
);
bar.set_style(style);
} }
/// Replace the usual `message` in a progress bar with the result of evaluating `template`. /// Stop showing the initial timer and display the next phase's message.
/// The `template` may contain a `ProgressBar`'s templated fields. pub fn finish_initial_measurement(bar: &ProgressBar, message: String) {
#[must_use] bar.set_message(message);
pub fn replace_message_template(bar: ProgressBar, template: &str) -> ProgressBar { bar.set_style(
let old_style = bar.style(); bar.style()
let new_template = create_progress_template(template); .template(DEFAULT_TEMPLATE)
let new_style = old_style .expect("no template error"),
.template(&new_template) );
.expect("no template error");
bar.with_style(new_style)
}
/// Reset a progress bar's template to the default.
/// This is useful after calling `replace_message_template()`.
#[must_use]
pub fn reset_progress_template(bar: ProgressBar) -> ProgressBar {
replace_message_template(bar, DEFAULT_MESSAGE_TEMPLATE)
} }
/// Return a pre-configured progress bar /// Return a pre-configured progress bar
pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar { pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {
let template = create_progress_template(DEFAULT_MESSAGE_TEMPLATE);
let progressbar_style = match option { let progressbar_style = match option {
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(), OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),
_ => ProgressStyle::default_spinner() _ => ProgressStyle::default_spinner()
.tick_chars(TICK_SETTINGS.0) .tick_chars(TICK_SETTINGS.0)
.template(&template) .template(DEFAULT_TEMPLATE)
.expect("no template error"), .expect("no template error"),
}; };