Skip to content
Myr

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

2 files+60 added−39 removed

modified:src/benchmark/mod.rs+28 added-12 removed
4 unmodified lines
5pub mod scheduler;67use std::cmp;8use std::io::{self, Write};9use std::time::Instant;1011use crate::benchmark::executor::BenchmarkIteration;12use crate::command::Command;13use crate::options::{
1 unmodified line
15};16use crate::outlier_detection::OUTLIER_THRESHOLD;17use crate::output::console_writeln;18use 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};21use crate::output::warnings::{OutlierWarningOptions, Warnings};22use crate::parameter::ParameterNameAndValue;23use crate::quantity::{const_time_from_seconds, ratio, FormatQuantity, Time, Zero};
220 unmodified lines
244 }245246 // 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 lines
264 res.time_wall_clock + self.executor.time_overhead()265 });266267 // 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();278279 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 }290291 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 lines
319320 all_succeeded = all_succeeded && success;321322 // 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 }327328 // 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)?;331332 let msg = {333 let t_wall_clock_mean = measurements.time_wall_clock_mean();334 let time_unit = self
7 unmodified lines
342 if let Some(bar) = progress_bar.as_ref() {343 bar.set_message(msg.to_owned())344 }345346 run_preparation_command(benchmark_iteration)?;347348 let res = self.executor.run_command_and_measure(349 self.command,350 benchmark_iteration,351 None,
153 unmodified lines
modified:src/output/progress_bar.rs+32 added-27 removed
1use indicatif::{ProgressBar, ProgressStyle};2use std::time::Duration;1use indicatif::{FormattedDuration, ProgressBar, ProgressState, ProgressStyle};2use std::fmt;3use std::time::{Duration, Instant};45use crate::options::OutputStyleOption;67#[cfg(not(windows))]
1 unmodified line
910#[cfg(windows)]11const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);1212const 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.15const DEFAULT_TEMPLATE: &str = " {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ";16const INITIAL_TEMPLATE: &str =17 " {spinner} Initial run: {initial_elapsed:<17} {wide_bar} ETA {eta_precise} ";1814fn 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.20pub 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}3521/// 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]24pub 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.37pub 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}4533/// Reset a progress bar's template to the default.34/// This is useful after calling `replace_message_template()`.35#[must_use]36pub fn reset_progress_template(bar: ProgressBar) -> ProgressBar {37 replace_message_template(bar, DEFAULT_MESSAGE_TEMPLATE)38}3946/// Return a pre-configured progress bar47pub 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 };5556 let progress_bar = match option {
9 unmodified lines