mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-28 08:08:58 +00:00
Resolve overlap with merged measurement refactors and current master
This commit is contained in:
1 parent
7a80feb4b0
commit
cf381994d1
8 files changed
+131
-98
No files matched your search
@@ -79,28 +79,15 @@ fn run_command_and_measure_common(
|
||||
let measurement = execute_and_measure(command)
|
||||
.with_context(|| format!("Failed to run command '{command_name}'"))?;
|
||||
|
||||
if command_failure_action == CmdFailureAction::RaiseError && !measurement.exit_status.success()
|
||||
{
|
||||
let when = match iteration {
|
||||
BenchmarkIteration::NonBenchmarkRun => "a non-benchmark run".to_string(),
|
||||
BenchmarkIteration::Warmup(0) => "the first warmup run".to_string(),
|
||||
BenchmarkIteration::Warmup(i) => format!("warmup iteration {i}"),
|
||||
BenchmarkIteration::Benchmark(0) => "the first benchmark run".to_string(),
|
||||
BenchmarkIteration::Benchmark(i) => format!("benchmark iteration {i}"),
|
||||
};
|
||||
bail!(
|
||||
"{cause} in {when}. Use the '-i'/'--ignore-failure' option if you want to ignore this. \
|
||||
Alternatively, use the '--show-output' option to debug what went wrong.",
|
||||
cause=measurement.exit_status.code().map_or(
|
||||
"The process has been terminated by a signal".into(),
|
||||
|c| format!("Command terminated with non-zero exit code {c}")
|
||||
if !measurement.exit_status.success() {
|
||||
use crate::util::exit_code::extract_exit_code;
|
||||
|
||||
let should_fail = match command_failure_action {
|
||||
CmdFailureAction::RaiseError => true,
|
||||
CmdFailureAction::IgnoreAllFailures => false,
|
||||
CmdFailureAction::IgnoreSpecificFailures(ref codes) => {
|
||||
// Only fail if the exit code is not in the list of codes to ignore
|
||||
if let Some(exit_code) = extract_exit_code(result.exit_status) {
|
||||
if let Some(exit_code) = extract_exit_code(measurement.exit_status) {
|
||||
!codes.contains(&exit_code)
|
||||
} else {
|
||||
// If we can't extract an exit code, treat it as a failure
|
||||
@@ -120,7 +107,7 @@ fn run_command_and_measure_common(
|
||||
bail!(
|
||||
"{cause} in {when}. Use the '-i'/'--ignore-failure' option if you want to ignore this. \
|
||||
Alternatively, use the '--show-output' option to debug what went wrong.",
|
||||
cause=result.exit_status.code().map_or(
|
||||
cause=measurement.exit_status.code().map_or(
|
||||
"The process has been terminated by a signal".into(),
|
||||
|c| format!("Command terminated with non-zero exit code {c}")
|
||||
|
||||
|
||||
@@ -115,8 +115,4 @@ impl Measurements {
|
||||
pub fn peak_memory_usage_mean(&self) -> Information {
|
||||
mean(self.measurements.iter().map(|m| m.peak_memory_usage))
|
||||
}
|
||||
|
||||
pub fn peak_memory_usage_mean(&self) -> Information {
|
||||
mean(self.measurements.iter().map(|m| m.peak_memory_usage))
|
||||
}
|
||||
}
|
||||
@@ -379,8 +379,10 @@ impl<'a> Benchmark<'a> {
|
||||
let system_str = measurements.time_system_mean().format(time_unit);
|
||||
|
||||
if self.options.output_style != OutputStyleOption::Disabled {
|
||||
let mut stdout = io::stdout().lock();
|
||||
if measurements.len() == 1 {
|
||||
println!(
|
||||
console_writeln!(
|
||||
stdout,
|
||||
" Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",
|
||||
"abs".green().bold(),
|
||||
mean_str.green().bold(),
|
||||
|
||||
@@ -93,7 +93,7 @@ impl<'a> Scheduler<'a> {
|
||||
stdout,
|
||||
" {} ran",
|
||||
reference.result.command_with_unused_parameters().cyan()
|
||||
);
|
||||
)?;
|
||||
|
||||
for item in others {
|
||||
let stddev = if let Some(stddev) = item.relative_speed_stddev {
|
||||
@@ -123,7 +123,7 @@ impl<'a> Scheduler<'a> {
|
||||
"{} {}",
|
||||
comparator,
|
||||
&item.result.command_with_unused_parameters().magenta()
|
||||
);
|
||||
)?;
|
||||
}
|
||||
}
|
||||
SortOrder::Command => {
|
||||
|
||||
@@ -18,6 +18,7 @@ use self::orgmode::OrgmodeExporter;
|
||||
|
||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||
use crate::options::SortOrder;
|
||||
use crate::output::console_writeln;
|
||||
use crate::quantity::TimeUnit;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
+30
-25
@@ -37,32 +37,37 @@ fn wait4(mut child: Child) -> io::Result<(ExitStatus, ResourceUsage)> {
|
||||
let mut status = 0;
|
||||
let mut rusage = MaybeUninit::zeroed();
|
||||
|
||||
let result = unsafe { libc::wait4(pid, &mut status, 0, rusage.as_mut_ptr()) };
|
||||
|
||||
if result < 0 {
|
||||
Err(io::Error::last_os_error())
|
||||
} else {
|
||||
let rusage = unsafe { rusage.assume_init() };
|
||||
|
||||
let memory_usage_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
|
||||
// Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes
|
||||
// A f64 can represent integers up to 2^53 exactly, so we can represent
|
||||
// all values up to 2^53 bytes = 8 PiB exactly. Beyond that, our precision
|
||||
// is larger than 1 byte, but that's considered acceptable.
|
||||
Information::new::<byte>(rusage.ru_maxrss as f64)
|
||||
} else {
|
||||
Information::new::<kibibyte>(rusage.ru_maxrss as f64)
|
||||
};
|
||||
|
||||
Ok((
|
||||
ExitStatus::from_raw(status),
|
||||
ResourceUsage {
|
||||
time_user: convert_timeval(rusage.ru_utime),
|
||||
time_system: convert_timeval(rusage.ru_stime),
|
||||
memory_usage: memory_usage_byte.into(),
|
||||
},
|
||||
))
|
||||
loop {
|
||||
let result = unsafe { libc::wait4(pid, &mut status, 0, rusage.as_mut_ptr()) };
|
||||
if result >= 0 {
|
||||
break;
|
||||
}
|
||||
let error = io::Error::last_os_error();
|
||||
if error.kind() != io::ErrorKind::Interrupted {
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
|
||||
let rusage = unsafe { rusage.assume_init() };
|
||||
|
||||
let memory_usage_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
|
||||
// Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes
|
||||
// A f64 can represent integers up to 2^53 exactly, so we can represent
|
||||
// all values up to 2^53 bytes = 8 PiB exactly. Beyond that, our precision
|
||||
// is larger than 1 byte, but that's considered acceptable.
|
||||
Information::new::<byte>(rusage.ru_maxrss as f64)
|
||||
} else {
|
||||
Information::new::<kibibyte>(rusage.ru_maxrss as f64)
|
||||
};
|
||||
|
||||
Ok((
|
||||
ExitStatus::from_raw(status),
|
||||
ResourceUsage {
|
||||
time_user: convert_timeval(rusage.ru_utime),
|
||||
time_system: convert_timeval(rusage.ru_stime),
|
||||
memory_usage: memory_usage_byte.into(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub struct CPUTimer {}
|
||||
|
||||
Reference in new issue
Block a user