Print stderr with `--show-output` flag
Before adoption: this commit came in with the history the project adopted, so no landing records it.
The `--print-stdout` flag has been changed to `--show-output` and now both stderr and stdout are forwarded when this option is specified.
authored by Christian Duerr · committed by David Peter · parent e53726d · Browse files · 5 files·+32 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+32 added−31 removed
- other:+32 added−31 removed
Provenance
- Commit
556788c- Tree
e533636- Author
Christian Duerr <contact@christianduerr.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
e53726d
5 files changed+32 added−31 removed
modified:src/hyperfine/app.rs+5 added-4 removed
117 unmodified lines118 .value_name("FILE")119 .help("Export the timing results as a Markdown table to the given FILE."),120 )121 .arg(122- Arg::with_name("print-stdout")123- .long("print-stdout")122+ Arg::with_name("show-output")123+ .long("show-output")124 .conflicts_with("style")125- .help("Print the stdout of the benchmark instead of suppressing it. \125+ .help("Print the stdout and stderr of the benchmark instead of suppressing it. \126 This will increase the time it takes for benchmarks to run, \127- so it should only be used when trying to benchmark output speed."),127+ so it should only be used for debugging purposes or \128+ when trying to benchmark output speed."),129 )130 .help_message("Print this help message.")131 .version_message("Show version information.")132 }modified:src/hyperfine/benchmark.rs+14 added-14 removed
37 unmodified lines38 39 /// Run the given shell command and measure the execution time40 pub fn time_shell_command(41 command: &Command,42- print_stdout: bool,42+ show_output: bool,43 failure_action: CmdFailureAction,44 shell_spawning_time: Option<TimingResult>,45 ) -> io::Result<(TimingResult, bool)> {46 let wallclock_timer = WallClockTimer::start();47 48- let stdout = if print_stdout {49- Stdio::inherit()48+ let (stdout, stderr) = if show_output {49+ (Stdio::inherit(), Stdio::inherit())50 } else {51- Stdio::null()51+ (Stdio::null(), Stdio::null())52 };53- let result = execute_and_time(stdout, &command.get_shell_command())?;53+ let result = execute_and_time(stdout, stderr, &command.get_shell_command())?;54 55 let mut time_user = result.user_time;56 let mut time_system = result.system_time;57 26 unmodified lines84 85 /// Measure the average shell spawning time86 pub fn mean_shell_spawning_time(87 style: &OutputStyleOption,88- print_stdout: bool,88+ show_output: bool,89 ) -> io::Result<TimingResult> {90 const COUNT: u64 = 200;91 let progress_bar = get_progress_bar(COUNT, "Measuring shell spawning time", style);92 4 unmodified lines97 for _ in 0..COUNT {98 // Just run the shell without any command99 let res = time_shell_command(100 &Command::new(""),101- print_stdout,101+ show_output,102 CmdFailureAction::RaiseError,103 None,104 );105 24 unmodified lines130 131 /// Run the command specified by `--prepare`.132 fn run_preparation_command(133 command: &Option<String>,134- print_stdout: bool,134+ show_output: bool,135 ) -> io::Result<TimingResult> {136 if let &Some(ref preparation_command) = command {137 let res = time_shell_command(138 &Command::new(preparation_command),139- print_stdout,139+ show_output,140 CmdFailureAction::RaiseError,141 None,142 );143 if res.is_err() {38 unmodified lines182 &options.output_style,183 );184 185 for _ in 0..options.warmup_count {186- let _ = time_shell_command(cmd, options.print_stdout, options.failure_action, None)?;186+ let _ = time_shell_command(cmd, options.show_output, options.failure_action, None)?;187 progress_bar.inc(1);188 }189 progress_bar.finish_and_clear();190 }5 unmodified lines196 &options.output_style,197 );198 199 // Run init / cleanup command200- let prepare_res = run_preparation_command(&options.preparation_command, options.print_stdout)?;200+ let prepare_res = run_preparation_command(&options.preparation_command, options.show_output)?;201 202 // Initial timing run203 let (res, success) = time_shell_command(204 cmd,205- options.print_stdout,205+ options.show_output,206 options.failure_action,207 Some(shell_spawning_time),208 )?;209 21 unmodified lines231 progress_bar.set_length(count_remaining);232 233 // Gather statistics234 for _ in 0..count_remaining {235- run_preparation_command(&options.preparation_command, options.print_stdout)?;235+ run_preparation_command(&options.preparation_command, options.show_output)?;236 237 let msg = {238 let mean = format_duration(mean(×_real), None);239 format!("Current estimate: {}", mean.to_string().green())1 unmodified line241 progress_bar.set_message(&msg);242 243 let (res, success) = time_shell_command(244 cmd,245- options.print_stdout,245+ options.show_output,246 options.failure_action,247 Some(shell_spawning_time),248 )?;249 89 unmodified linesmodified:src/hyperfine/shell.rs+8 added-8 removed
17 unmodified lines18 }19 20 /// Execute the given command and return a timing summary21 #[cfg(windows)]22-pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResult> {23- let mut child = run_shell_command(stdout, command)?;22+pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<ExecuteResult> {23+ let mut child = run_shell_command(stdout, stderr, command)?;24 let cpu_timer = get_cpu_timer(&child);25 let status = child.wait()?;26 27 let (user_time, system_time) = cpu_timer.stop();5 unmodified lines33 }34 35 /// Execute the given command and return a timing summary36 #[cfg(not(windows))]37-pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResult> {37+pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<ExecuteResult> {38 let cpu_timer = get_cpu_timer();39 40- let status = run_shell_command(stdout, command)?;40+ let status = run_shell_command(stdout, stderr, command)?;41 42 let (user_time, system_time) = cpu_timer.stop();43 44 Ok(ExecuteResult {4 unmodified lines49 }50 51 /// Run a standard shell command52 #[cfg(not(windows))]53-fn run_shell_command(stdout: Stdio, command: &str) -> io::Result<std::process::ExitStatus> {53+fn run_shell_command(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<std::process::ExitStatus> {54 Command::new("sh")55 .arg("-c")56 .arg(command)57 .stdin(Stdio::null())58 .stdout(stdout)59- .stderr(Stdio::null())59+ .stderr(stderr)60 .status()61 }62 63 /// Run a Windows shell command using cmd.exe64 #[cfg(windows)]65-fn run_shell_command(stdout: Stdio, command: &str) -> io::Result<std::process::Child> {65+fn run_shell_command(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<std::process::Child> {66 Command::new("cmd")67 .arg("/C")68 .arg(command)69 .stdin(Stdio::null())70 .stdout(stdout)71- .stderr(Stdio::null())71+ .stderr(stderr)72 .spawn()73 }modified:src/hyperfine/types.rs+2 added-2 removed
89 unmodified lines90 /// What color mode to use for output91 pub output_style: OutputStyleOption,92 93 /// Forward benchmark's stdout to hyperfine's stdout94- pub print_stdout: bool,94+ pub show_output: bool,95 }96 97 impl Default for HyperfineOptions {98 fn default() -> HyperfineOptions {3 unmodified lines102 min_time_sec: 3.0,103 failure_action: CmdFailureAction::RaiseError,104 preparation_command: None,105 output_style: OutputStyleOption::Full,106- print_stdout: false,106+ show_output: false,107 }108 }109 }110 53 unmodified linesmodified:src/main.rs+3 added-3 removed
55 unmodified lines56 57 /// Runs the benchmark for the given commands58 fn run(commands: &Vec<Command>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {59 let shell_spawning_time =60- mean_shell_spawning_time(&options.output_style, options.print_stdout)?;60+ mean_shell_spawning_time(&options.output_style, options.show_output)?;61 62 let mut timing_results = vec![];63 64 // Run the benchmarks63 unmodified lines128 }129 130 options.preparation_command = matches.value_of("prepare").map(String::from);131 132- options.print_stdout = matches.is_present("print-stdout");132+ options.show_output = matches.is_present("show-output");133 134 options.output_style = match matches.value_of("style") {135 Some("full") => OutputStyleOption::Full,136 Some("basic") => OutputStyleOption::Basic,137 Some("nocolor") => OutputStyleOption::NoColor,138- _ => if !options.print_stdout && atty::is(Stream::Stdout) {138+ _ => if !options.show_output && atty::is(Stream::Stdout) {139 OutputStyleOption::Full140 } else {141 OutputStyleOption::Basic142 },57 unmodified lines