mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 01:00:31 +00:00
Export exit codes to JSON output
This commit is contained in:
1 parent
9e57bf613c
commit
3fcc6a187b
7 files changed
+53
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
use std::process::Stdio;
|
||||
use std::process::{ExitStatus, Stdio};
|
||||
|
||||
use colored::*;
|
||||
use statistical::{mean, median, standard_deviation};
|
||||
@@ -46,7 +46,7 @@ pub fn time_shell_command(
|
||||
show_output: bool,
|
||||
failure_action: CmdFailureAction,
|
||||
shell_spawning_time: Option<TimingResult>,
|
||||
) -> io::Result<(TimingResult, bool)> {
|
||||
) -> io::Result<(TimingResult, ExitStatus)> {
|
||||
let (stdout, stderr) = if show_output {
|
||||
(Stdio::inherit(), Stdio::inherit())
|
||||
} else {
|
||||
@@ -88,7 +88,7 @@ pub fn time_shell_command(
|
||||
time_user,
|
||||
time_system,
|
||||
},
|
||||
result.status.success(),
|
||||
result.status,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -201,6 +201,26 @@ fn run_cleanup_command(
|
||||
run_intermediate_command(shell, command, show_output, error_output)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn extract_exit_code(status: ExitStatus) -> i32 {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
/* From the ExitStatus::code documentation:
|
||||
"On Unix, this will return None if the process was terminated by a signal."
|
||||
In that case, ExitStatusExt::signal should never return None.
|
||||
*/
|
||||
status.code().unwrap_or_else(|| status.signal().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn extract_exit_code(status: ExitStatus) -> i32 {
|
||||
/* From the ExitStatus::code documentation:
|
||||
"On Unix, this will return None if the process was terminated by a signal."
|
||||
On the other configurations, ExitStatus::code should never return None.
|
||||
*/
|
||||
status.code().unwrap()
|
||||
}
|
||||
|
||||
/// Run the benchmark for a single shell command
|
||||
pub fn run_benchmark(
|
||||
num: usize,
|
||||
@@ -228,6 +248,7 @@ pub fn run_benchmark(
|
||||
let mut times_real: Vec<Second> = vec![];
|
||||
let mut times_user: Vec<Second> = vec![];
|
||||
let mut times_system: Vec<Second> = vec![];
|
||||
let mut exit_codes: Vec<i32> = vec![];
|
||||
let mut all_succeeded = true;
|
||||
|
||||
// Run init command
|
||||
@@ -280,13 +301,14 @@ pub fn run_benchmark(
|
||||
let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;
|
||||
|
||||
// Initial timing run
|
||||
let (res, success) = time_shell_command(
|
||||
let (res, status) = time_shell_command(
|
||||
&options.shell,
|
||||
cmd,
|
||||
options.show_output,
|
||||
options.failure_action,
|
||||
Some(shell_spawning_time),
|
||||
)?;
|
||||
let success = status.success();
|
||||
|
||||
// Determine number of benchmark runs
|
||||
let runs_in_min_time = (options.min_time_sec
|
||||
@@ -310,6 +332,7 @@ pub fn run_benchmark(
|
||||
times_real.push(res.time_real);
|
||||
times_user.push(res.time_user);
|
||||
times_system.push(res.time_system);
|
||||
exit_codes.push(extract_exit_code(status));
|
||||
|
||||
all_succeeded = all_succeeded && success;
|
||||
|
||||
@@ -328,17 +351,19 @@ pub fn run_benchmark(
|
||||
|
||||
progress_bar.as_ref().map(|bar| bar.set_message(msg.to_owned()));
|
||||
|
||||
let (res, success) = time_shell_command(
|
||||
let (res, status) = time_shell_command(
|
||||
&options.shell,
|
||||
cmd,
|
||||
options.show_output,
|
||||
options.failure_action,
|
||||
Some(shell_spawning_time),
|
||||
)?;
|
||||
let success = status.success();
|
||||
|
||||
times_real.push(res.time_real);
|
||||
times_user.push(res.time_user);
|
||||
times_system.push(res.time_system);
|
||||
exit_codes.push(extract_exit_code(status));
|
||||
|
||||
all_succeeded = all_succeeded && success;
|
||||
|
||||
@@ -438,6 +463,7 @@ pub fn run_benchmark(
|
||||
t_min,
|
||||
t_max,
|
||||
times_real,
|
||||
exit_codes,
|
||||
cmd.get_parameters()
|
||||
.iter()
|
||||
.map(|(name, value)| ((*name).to_string(), value.to_string()))
|
||||
|
||||
Reference in new issue
Block a user