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
Provenance
- Commit
ce70401- Tree
6117e79- Author
Devon Hollowood <devonhollowood@google.com>- Committer
David Peter <mail@david-peter.de>- Parent
f39b497
2 files changed+39 added−5 removed
modified:src/benchmark/mod.rs+9 added-4 removed
12 unmodified lines13 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,14 };15 use crate::outlier_detection::OUTLIER_THRESHOLD;16 use crate::output::console_writeln;17-use crate::output::progress_bar::get_progress_bar;17+use crate::output::progress_bar::{18+ get_progress_bar, replace_message_template, reset_progress_template,19+};20 use crate::output::warnings::{OutlierWarningOptions, Warnings};21 use crate::parameter::ParameterNameAndValue;22 use crate::quantity::{const_time_from_seconds, ratio, FormatQuantity, Time, Zero};23 use benchmark_result::{BenchmarkResult, Parameter};219 unmodified lines243 }244 245 // 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 lines301 302 all_succeeded = all_succeeded && success;303 304 // 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 linesmodified:src/output/progress_bar.rs+30 added-1 removed
7 unmodified lines8 9 #[cfg(windows)]10 const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);11 12+const DEFAULT_MESSAGE_TEMPLATE: &str = "{msg:<30}";13+14+fn create_progress_template(msg_template: &str) -> String {15+ format!(16+ " {{spinner}} {} {{wide_bar}} ETA {{eta_precise}} ",17+ msg_template18+ )19+}20+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)31+}32+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+40 /// Return a pre-configured progress bar41 pub 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 };50 51 let progress_bar = match option {9 unmodified lines