Skip to content
Myr

Make time elapsed only show up initially

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Devon Hollowood · committed by David Peter · parent f39b497 · Browse files · 2 files+39 added−5 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+39 added−5 removed

  • other:+39 added−5 removed

2 files+39 added−5 removed

modified:src/benchmark/mod.rs+9 added-4 removed
12 unmodified lines
13 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,14};15use crate::outlier_detection::OUTLIER_THRESHOLD;16use crate::output::console_writeln;17use crate::output::progress_bar::get_progress_bar;17use crate::output::progress_bar::{18 get_progress_bar, replace_message_template, reset_progress_template,19};20use crate::output::warnings::{OutlierWarningOptions, Warnings};21use crate::parameter::ParameterNameAndValue;22use crate::quantity::{const_time_from_seconds, ratio, FormatQuantity, Time, Zero};23use benchmark_result::{BenchmarkResult, Parameter};
219 unmodified lines
243 }244245 // Set up progress bar (and spinner for initial measurement)246 let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {245 Some(get_progress_bar(247 let temp_bar = get_progress_bar(248 self.options.run_bounds.min,247 "Initial time measurement",249 "Initial time measurement:",250 self.options.output_style,249 ))251 );252 let template = format!("{{msg}} {{elapsed:<{}}}", 30 - temp_bar.message().len() - 1,);253 Some(replace_message_template(temp_bar, &template))254 } else {255 None256 };257
43 unmodified lines
301302 all_succeeded = all_succeeded && success;303304 // Re-configure the progress bar305 let progress_bar = progress_bar.map(reset_progress_template);306 if let Some(bar) = progress_bar.as_ref() {307 bar.set_length(count)308 }309 if let Some(bar) = progress_bar.as_ref() {
179 unmodified lines
modified:src/output/progress_bar.rs+30 added-1 removed
7 unmodified lines
89#[cfg(windows)]10const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);1112const DEFAULT_MESSAGE_TEMPLATE: &str = "{msg:<30}";1314fn create_progress_template(msg_template: &str) -> String {15 format!(16 " {{spinner}} {} {{wide_bar}} ETA {{eta_precise}} ",17 msg_template18 )19}2021/// 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)31}3233/// 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}3940/// Return a pre-configured progress bar41pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {42 let template = create_progress_template(DEFAULT_MESSAGE_TEMPLATE);43 let progressbar_style = match option {44 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),45 _ => ProgressStyle::default_spinner()46 .tick_chars(TICK_SETTINGS.0)18 .template(" {spinner} {msg:<30} {wide_bar} Time: {elapsed} ETA {eta_precise} ")47 .template(&template)48 .expect("no template error"),49 };5051 let progress_bar = match option {
9 unmodified lines