Address review feedback
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent ce70401 · Browse files · 2 files·+60 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+60 added−39 removed
- other:+60 added−39 removed
Provenance
- Commit
0f2871b- Tree
094aafe- Author
David Peter <mail@david-peter.de>- Committer
David Peter <mail@david-peter.de>- Parent
ce70401
2 files changed+60 added−39 removed
modified:src/benchmark/mod.rs+28 added-12 removed
4 unmodified lines5 pub mod scheduler;6 7 use std::cmp;8 use std::io::{self, Write};9+use std::time::Instant;10 11 use crate::benchmark::executor::BenchmarkIteration;12 use crate::command::Command;13 use crate::options::{1 unmodified line15 };16 use crate::outlier_detection::OUTLIER_THRESHOLD;17 use crate::output::console_writeln;18 use crate::output::progress_bar::{18- get_progress_bar, replace_message_template, reset_progress_template,19+ finish_initial_measurement, get_progress_bar, start_initial_measurement,20 };21 use crate::output::warnings::{OutlierWarningOptions, Warnings};22 use crate::parameter::ParameterNameAndValue;23 use crate::quantity::{const_time_from_seconds, ratio, FormatQuantity, Time, Zero};220 unmodified lines244 }245 246 // Set up progress bar (and spinner for initial measurement)247 let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {247- let temp_bar = get_progress_bar(248+ Some(get_progress_bar(249 self.options.run_bounds.min,249- "Initial time measurement:",250+ if preparation_command.is_some() {251+ "Running preparation command"252+ } else {253+ "Initial run"254+ },255 self.options.output_style,251- );252- let template = format!("{{msg}} {{elapsed:<{}}}", 30 - temp_bar.message().len() - 1,);253- Some(replace_message_template(temp_bar, &template))256+ ))257 } else {258 None259 };260 3 unmodified lines264 res.time_wall_clock + self.executor.time_overhead()265 });266 267 // Initial timing run268+ if let Some(bar) = progress_bar.as_ref() {269+ start_initial_measurement(bar, Instant::now());270+ }271 let res = self.executor.run_command_and_measure(272 self.command,273 benchmark_iteration,274 None,275 output_policy,276 )?;277 let success = res.exit_status.success();278 279+ if let Some(bar) = progress_bar.as_ref() {280+ let time_unit = self281+ .options282+ .time_unit283+ .unwrap_or(res.time_wall_clock.suitable_unit());284+ let estimate = res.time_wall_clock.format(time_unit);285+ finish_initial_measurement(286+ bar,287+ format!("Current estimate: {}", estimate.to_string().green()),288+ );289+ }290+291 let conclusion_result = run_conclusion_command(benchmark_iteration)?;292 let conclusion_overhead = conclusion_result.map_or(Time::zero(), |res| {293 res.time_wall_clock + self.executor.time_overhead()294 });24 unmodified lines319 320 all_succeeded = all_succeeded && success;321 322 // Re-configure the progress bar305- let progress_bar = progress_bar.map(reset_progress_template);323 if let Some(bar) = progress_bar.as_ref() {307- bar.set_length(count)324+ bar.set_length(count);325+ bar.inc(1);326 }309- if let Some(bar) = progress_bar.as_ref() {310- bar.inc(1)311- }327 328 // Gather statistics (perform the actual benchmark)329 for i in 0..count_remaining {330 let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);316- run_preparation_command(benchmark_iteration)?;331 332 let msg = {333 let t_wall_clock_mean = measurements.time_wall_clock_mean();334 let time_unit = self7 unmodified lines342 if let Some(bar) = progress_bar.as_ref() {343 bar.set_message(msg.to_owned())344 }345 346+ run_preparation_command(benchmark_iteration)?;347+348 let res = self.executor.run_command_and_measure(349 self.command,350 benchmark_iteration,351 None,153 unmodified linesmodified:src/output/progress_bar.rs+32 added-27 removed
1-use indicatif::{ProgressBar, ProgressStyle};2-use std::time::Duration;1+use indicatif::{FormattedDuration, ProgressBar, ProgressState, ProgressStyle};2+use std::fmt;3+use std::time::{Duration, Instant};4 5 use crate::options::OutputStyleOption;6 7 #[cfg(not(windows))]1 unmodified line9 10 #[cfg(windows)]11 const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);12 12-const DEFAULT_MESSAGE_TEMPLATE: &str = "{msg:<30}";13+// Keep the message area 30 columns wide across preparation, the initial run,14+// and estimates so that switching between them does not move the bar.15+const DEFAULT_TEMPLATE: &str = " {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ";16+const INITIAL_TEMPLATE: &str =17+ " {spinner} Initial run: {initial_elapsed:<17} {wide_bar} ETA {eta_precise} ";18 14-fn create_progress_template(msg_template: &str) -> String {15- format!(16- " {{spinner}} {} {{wide_bar}} ETA {{eta_precise}} ",17- msg_template18- )19+/// Show the time elapsed since the initial benchmark command started.20+pub fn start_initial_measurement(bar: &ProgressBar, started: Instant) {21+ // Keep a separate clock: the progress bar's clock and ETA estimator must22+ // continue to include preparation time.23+ let style = bar24+ .style()25+ .template(INITIAL_TEMPLATE)26+ .expect("no template error")27+ .with_key(28+ "initial_elapsed",29+ move |_: &ProgressState, w: &mut dyn fmt::Write| {30+ write!(w, "{}", FormattedDuration(started.elapsed())).unwrap();31+ },32+ );33+ bar.set_style(style);34 }35 21-/// Replace the usual `message` in a progress bar with the result of evaluating `template`.22-/// The `template` may contain a `ProgressBar`'s templated fields.23-#[must_use]24-pub fn replace_message_template(bar: ProgressBar, template: &str) -> ProgressBar {25- let old_style = bar.style();26- let new_template = create_progress_template(template);27- let new_style = old_style28- .template(&new_template)29- .expect("no template error");30- bar.with_style(new_style)36+/// Stop showing the initial timer and display the next phase's message.37+pub fn finish_initial_measurement(bar: &ProgressBar, message: String) {38+ bar.set_message(message);39+ bar.set_style(40+ bar.style()41+ .template(DEFAULT_TEMPLATE)42+ .expect("no template error"),43+ );44 }45 33-/// Reset a progress bar's template to the default.34-/// This is useful after calling `replace_message_template()`.35-#[must_use]36-pub fn reset_progress_template(bar: ProgressBar) -> ProgressBar {37- replace_message_template(bar, DEFAULT_MESSAGE_TEMPLATE)38-}39-46 /// Return a pre-configured progress bar47 pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {42- let template = create_progress_template(DEFAULT_MESSAGE_TEMPLATE);48 let progressbar_style = match option {49 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),50 _ => ProgressStyle::default_spinner()51 .tick_chars(TICK_SETTINGS.0)47- .template(&template)52+ .template(DEFAULT_TEMPLATE)53 .expect("no template error"),54 };55 56 let progress_bar = match option {9 unmodified lines