Print stderr with --show-output flag

The `--print-stdout` flag has been changed to `--show-output` and now
both stderr and stdout are forwarded when this option is specified.
This commit is contained in:
Christian Duerr authored and David Peter committed 2018-05-22 22:54:08 +02:00
1 parent e53726d3f7
commit 556788c160
5 files changed
+32 -31

No files matched your search

+5 -4
View File
@@ -119,12 +119,13 @@ fn build_app() -> App<'static, 'static> {
.help("Export the timing results as a Markdown table to the given FILE."),
)
.arg(
Arg::with_name("print-stdout")
.long("print-stdout")
Arg::with_name("show-output")
.long("show-output")
.conflicts_with("style")
.help("Print the stdout of the benchmark instead of suppressing it. \
.help("Print the stdout and stderr of the benchmark instead of suppressing it. \
This will increase the time it takes for benchmarks to run, \
so it should only be used when trying to benchmark output speed."),
so it should only be used for debugging purposes or \
when trying to benchmark output speed."),
)
.help_message("Print this help message.")
.version_message("Show version information.")
+14 -14
View File
@@ -39,18 +39,18 @@ fn subtract_shell_spawning_time(time: Second, shell_spawning_time: Second) -> Se
/// Run the given shell command and measure the execution time
pub fn time_shell_command(
command: &Command,
print_stdout: bool,
show_output: bool,
failure_action: CmdFailureAction,
shell_spawning_time: Option<TimingResult>,
) -> io::Result<(TimingResult, bool)> {
let wallclock_timer = WallClockTimer::start();
let stdout = if print_stdout {
Stdio::inherit()
let (stdout, stderr) = if show_output {
(Stdio::inherit(), Stdio::inherit())
} else {
Stdio::null()
(Stdio::null(), Stdio::null())
};
let result = execute_and_time(stdout, &command.get_shell_command())?;
let result = execute_and_time(stdout, stderr, &command.get_shell_command())?;
let mut time_user = result.user_time;
let mut time_system = result.system_time;
@@ -85,7 +85,7 @@ pub fn time_shell_command(
/// Measure the average shell spawning time
pub fn mean_shell_spawning_time(
style: &OutputStyleOption,
print_stdout: bool,
show_output: bool,
) -> io::Result<TimingResult> {
const COUNT: u64 = 200;
let progress_bar = get_progress_bar(COUNT, "Measuring shell spawning time", style);
@@ -98,7 +98,7 @@ pub fn mean_shell_spawning_time(
// Just run the shell without any command
let res = time_shell_command(
&Command::new(""),
print_stdout,
show_output,
CmdFailureAction::RaiseError,
None,
);
@@ -131,12 +131,12 @@ pub fn mean_shell_spawning_time(
/// Run the command specified by `--prepare`.
fn run_preparation_command(
command: &Option<String>,
print_stdout: bool,
show_output: bool,
) -> io::Result<TimingResult> {
if let &Some(ref preparation_command) = command {
let res = time_shell_command(
&Command::new(preparation_command),
print_stdout,
show_output,
CmdFailureAction::RaiseError,
None,
);
@@ -183,7 +183,7 @@ pub fn run_benchmark(
);
for _ in 0..options.warmup_count {
let _ = time_shell_command(cmd, options.print_stdout, options.failure_action, None)?;
let _ = time_shell_command(cmd, options.show_output, options.failure_action, None)?;
progress_bar.inc(1);
}
progress_bar.finish_and_clear();
@@ -197,12 +197,12 @@ pub fn run_benchmark(
);
// Run init / cleanup command
let prepare_res = run_preparation_command(&options.preparation_command, options.print_stdout)?;
let prepare_res = run_preparation_command(&options.preparation_command, options.show_output)?;
// Initial timing run
let (res, success) = time_shell_command(
cmd,
options.print_stdout,
options.show_output,
options.failure_action,
Some(shell_spawning_time),
)?;
@@ -232,7 +232,7 @@ pub fn run_benchmark(
// Gather statistics
for _ in 0..count_remaining {
run_preparation_command(&options.preparation_command, options.print_stdout)?;
run_preparation_command(&options.preparation_command, options.show_output)?;
let msg = {
let mean = format_duration(mean(&times_real), None);
@@ -242,7 +242,7 @@ pub fn run_benchmark(
let (res, success) = time_shell_command(
cmd,
options.print_stdout,
options.show_output,
options.failure_action,
Some(shell_spawning_time),
)?;
+8 -8
View File
@@ -19,8 +19,8 @@ pub struct ExecuteResult {
/// Execute the given command and return a timing summary
#[cfg(windows)]
pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResult> {
let mut child = run_shell_command(stdout, command)?;
pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<ExecuteResult> {
let mut child = run_shell_command(stdout, stderr, command)?;
let cpu_timer = get_cpu_timer(&child);
let status = child.wait()?;
@@ -34,10 +34,10 @@ pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResul
/// Execute the given command and return a timing summary
#[cfg(not(windows))]
pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResult> {
pub fn execute_and_time(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<ExecuteResult> {
let cpu_timer = get_cpu_timer();
let status = run_shell_command(stdout, command)?;
let status = run_shell_command(stdout, stderr, command)?;
let (user_time, system_time) = cpu_timer.stop();
@@ -50,24 +50,24 @@ pub fn execute_and_time(stdout: Stdio, command: &str) -> io::Result<ExecuteResul
/// Run a standard shell command
#[cfg(not(windows))]
fn run_shell_command(stdout: Stdio, command: &str) -> io::Result<std::process::ExitStatus> {
fn run_shell_command(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<std::process::ExitStatus> {
Command::new("sh")
.arg("-c")
.arg(command)
.stdin(Stdio::null())
.stdout(stdout)
.stderr(Stdio::null())
.stderr(stderr)
.status()
}
/// Run a Windows shell command using cmd.exe
#[cfg(windows)]
fn run_shell_command(stdout: Stdio, command: &str) -> io::Result<std::process::Child> {
fn run_shell_command(stdout: Stdio, stderr: Stdio, command: &str) -> io::Result<std::process::Child> {
Command::new("cmd")
.arg("/C")
.arg(command)
.stdin(Stdio::null())
.stdout(stdout)
.stderr(Stdio::null())
.stderr(stderr)
.spawn()
}
+2 -2
View File
@@ -91,7 +91,7 @@ pub struct HyperfineOptions {
pub output_style: OutputStyleOption,
/// Forward benchmark's stdout to hyperfine's stdout
pub print_stdout: bool,
pub show_output: bool,
}
impl Default for HyperfineOptions {
@@ -103,7 +103,7 @@ impl Default for HyperfineOptions {
failure_action: CmdFailureAction::RaiseError,
preparation_command: None,
output_style: OutputStyleOption::Full,
print_stdout: false,
show_output: false,
}
}
}
+3 -3
View File
@@ -57,7 +57,7 @@ pub fn error(message: &str) -> ! {
/// Runs the benchmark for the given commands
fn run(commands: &Vec<Command>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {
let shell_spawning_time =
mean_shell_spawning_time(&options.output_style, options.print_stdout)?;
mean_shell_spawning_time(&options.output_style, options.show_output)?;
let mut timing_results = vec![];
@@ -129,13 +129,13 @@ fn build_hyperfine_options(matches: &ArgMatches) -> HyperfineOptions {
options.preparation_command = matches.value_of("prepare").map(String::from);
options.print_stdout = matches.is_present("print-stdout");
options.show_output = matches.is_present("show-output");
options.output_style = match matches.value_of("style") {
Some("full") => OutputStyleOption::Full,
Some("basic") => OutputStyleOption::Basic,
Some("nocolor") => OutputStyleOption::NoColor,
_ => if !options.print_stdout && atty::is(Stream::Stdout) {
_ => if !options.show_output && atty::is(Stream::Stdout) {
OutputStyleOption::Full
} else {
OutputStyleOption::Basic