Skip to content
Myr

Merge pull request #581 from devonhollowood/elapsed

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

Add elapsed time to progress bar

authored by David Peter · committed by GitHub · parents 79aea88, 8745487 · Browse files · 2 files+63 added−10 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+63 added−10 removed

  • other:+63 added−10 removed

2 files+63 added−10 removed

modified:src/benchmark/mod.rs+28 added-7 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::{14 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,15};16use crate::outlier_detection::OUTLIER_THRESHOLD;17use crate::output::console_writeln;17use crate::output::progress_bar::get_progress_bar;18use crate::output::progress_bar::{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};24use benchmark_result::{BenchmarkResult, Parameter};
221 unmodified lines
246 // Set up progress bar (and spinner for initial measurement)247 let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {248 Some(get_progress_bar(249 self.options.run_bounds.min,247 "Initial time measurement",250 if preparation_command.is_some() {251 "Running preparation command"252 } else {253 "Initial run"254 },255 self.options.output_style,256 ))257 } else {258 None
5 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 });
25 unmodified lines
320 all_succeeded = all_succeeded && success;321322 // Re-configure the progress bar323 if let Some(bar) = progress_bar.as_ref() {302 bar.set_length(count)324 bar.set_length(count);325 bar.inc(1);326 }304 if let Some(bar) = progress_bar.as_ref() {305 bar.inc(1)306 }327328 // Gather statistics (perform the actual benchmark)329 for i in 0..count_remaining {330 let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);311 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+35 added-3 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);1213// 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} ";1819/// Show the time elapsed since the initial benchmark command started.20pub fn start_initial_measurement(bar: &ProgressBar, started: Instant) {21 let style = bar22 .style()23 .template(INITIAL_TEMPLATE)24 .expect("no template error")25 .with_key(26 "initial_elapsed",27 move |_: &ProgressState, w: &mut dyn fmt::Write| {28 write!(w, "{}", FormattedDuration(started.elapsed())).unwrap();29 },30 );31 bar.set_style(style);32}3334/// Stop showing the initial timer and display the next phase's message.35pub fn finish_initial_measurement(bar: &ProgressBar, message: String) {36 bar.set_message(message);37 bar.set_style(38 bar.style()39 .template(DEFAULT_TEMPLATE)40 .expect("no template error"),41 );42}4344/// Return a pre-configured progress bar45pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {46 let progressbar_style = match option {47 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),48 _ => ProgressStyle::default_spinner()49 .tick_chars(TICK_SETTINGS.0)18 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ")50 .template(DEFAULT_TEMPLATE)51 .expect("no template error"),52 };5354 let progress_bar = match option {
9 unmodified lines