Skip to content
Myr

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

5 files+32 added−31 removed

modified:src/hyperfine/app.rs+5 added-4 removed
117 unmodified lines
118 .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 lines
3839/// Run the given shell command and measure the execution time40pub 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();4748 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())?;5455 let mut time_user = result.user_time;56 let mut time_system = result.system_time;57
26 unmodified lines
8485/// Measure the average shell spawning time86pub 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 lines
97 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 lines
130131/// Run the command specified by `--prepare`.132fn 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 lines
182 &options.output_style,183 );184185 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 lines
196 &options.output_style,197 );198199 // 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)?;201202 // 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 lines
231 progress_bar.set_length(count_remaining);232233 // 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)?;236237 let msg = {238 let mean = format_duration(mean(&times_real), None);239 format!("Current estimate: {}", mean.to_string().green())
1 unmodified line
241 progress_bar.set_message(&msg);242243 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 lines
modified:src/hyperfine/shell.rs+8 added-8 removed
17 unmodified lines
18}1920/// Execute the given command and return a timing summary21#[cfg(windows)]22pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResult> {23 let mut child = run_shell_command(stdout, command)?;22pub 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()?;2627 let (user_time, system_time) = cpu_timer.stop();
5 unmodified lines
33}3435/// Execute the given command and return a timing summary36#[cfg(not(windows))]37pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResult> {37pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<ExecuteResult> {38 let cpu_timer = get_cpu_timer();3940 let status = run_shell_command(stdout, command)?;40 let status = run_shell_command(stdout, stderr, command)?;4142 let (user_time, system_time) = cpu_timer.stop();4344 Ok(ExecuteResult {
4 unmodified lines
49}5051/// Run a standard shell command52#[cfg(not(windows))]53fn run_shell_command(stdout: Stdio, command: &str) -> io::Result<std::process::ExitStatus> {53fn 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}6263/// Run a Windows shell command using cmd.exe64#[cfg(windows)]65fn run_shell_command(stdout: Stdio, command: &str) -> io::Result<std::process::Child> {65fn 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 lines
90 /// What color mode to use for output91 pub output_style: OutputStyleOption,9293 /// Forward benchmark's stdout to hyperfine's stdout94 pub print_stdout: bool,94 pub show_output: bool,95}9697impl Default for HyperfineOptions {98 fn default() -> HyperfineOptions {
3 unmodified lines
102 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 lines
modified:src/main.rs+3 added-3 removed
55 unmodified lines
5657/// Runs the benchmark for the given commands58fn 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)?;6162 let mut timing_results = vec![];6364 // Run the benchmarks
63 unmodified lines
128 }129130 options.preparation_command = matches.value_of("prepare").map(String::from);131132 options.print_stdout = matches.is_present("print-stdout");132 options.show_output = matches.is_present("show-output");133134 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