mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-10-05 18:07:24 +03:00
Merge 34cd5b9bb5
into df34f32dca
This commit is contained in:
commit
171356267d
@ -45,6 +45,10 @@ pub struct BenchmarkResult {
|
||||
/// Exit codes of all command invocations
|
||||
pub exit_codes: Vec<Option<i32>>,
|
||||
|
||||
/// All max. memory sizes
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max_rss_byte: Option<Vec<Second>>,
|
||||
|
||||
/// Parameter values for this benchmark
|
||||
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub parameters: BTreeMap<String, String>,
|
||||
|
@ -99,6 +99,7 @@ impl<'a> Executor for RawExecutor<'a> {
|
||||
time_real: result.time_real,
|
||||
time_user: result.time_user,
|
||||
time_system: result.time_system,
|
||||
max_rss_byte: Some(result.max_rss_byte),
|
||||
},
|
||||
result.status,
|
||||
))
|
||||
@ -167,6 +168,7 @@ impl<'a> Executor for ShellExecutor<'a> {
|
||||
time_real: result.time_real,
|
||||
time_user: result.time_user,
|
||||
time_system: result.time_system,
|
||||
max_rss_byte: Some(result.max_rss_byte),
|
||||
},
|
||||
result.status,
|
||||
))
|
||||
@ -226,6 +228,7 @@ impl<'a> Executor for ShellExecutor<'a> {
|
||||
time_real: mean(×_real),
|
||||
time_user: mean(×_user),
|
||||
time_system: mean(×_system),
|
||||
max_rss_byte: None,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
@ -279,6 +282,7 @@ impl Executor for MockExecutor {
|
||||
time_real: Self::extract_time(command.get_command_line()),
|
||||
time_user: 0.0,
|
||||
time_system: 0.0,
|
||||
max_rss_byte: None,
|
||||
},
|
||||
status,
|
||||
))
|
||||
|
@ -11,4 +11,7 @@ pub struct TimingResult {
|
||||
|
||||
/// Time spent in kernel mode
|
||||
pub time_system: Second,
|
||||
|
||||
/// Amount of memory used
|
||||
pub max_rss_byte: Option<i64>,
|
||||
}
|
||||
|
@ -32,6 +32,9 @@ struct CPUTimes {
|
||||
|
||||
/// Total amount of time spent executing in kernel mode
|
||||
pub system_usec: i64,
|
||||
|
||||
/// Total amount of memory used by the process
|
||||
pub max_rss_byte: i64,
|
||||
}
|
||||
|
||||
/// Used to indicate the result of running a command
|
||||
@ -40,7 +43,7 @@ pub struct TimerResult {
|
||||
pub time_real: Second,
|
||||
pub time_user: Second,
|
||||
pub time_system: Second,
|
||||
|
||||
pub max_rss_byte: i64,
|
||||
/// The exit status of the process
|
||||
pub status: ExitStatus,
|
||||
}
|
||||
@ -106,12 +109,13 @@ pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> {
|
||||
let status = child.wait()?;
|
||||
|
||||
let time_real = wallclock_timer.stop();
|
||||
let (time_user, time_system) = cpu_timer.stop();
|
||||
let (time_user, time_system, max_rss_byte) = cpu_timer.stop();
|
||||
|
||||
Ok(TimerResult {
|
||||
time_real,
|
||||
time_user,
|
||||
time_system,
|
||||
max_rss_byte,
|
||||
status,
|
||||
})
|
||||
}
|
||||
|
@ -25,10 +25,10 @@ impl CPUTimer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(&self) -> (Second, Second) {
|
||||
pub fn stop(&self) -> (Second, Second, i64) {
|
||||
let end_cpu = get_cpu_times();
|
||||
let cpu_interval = cpu_time_interval(&self.start_cpu, &end_cpu);
|
||||
(cpu_interval.user, cpu_interval.system)
|
||||
(cpu_interval.user, cpu_interval.system, end_cpu.max_rss_byte)
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,12 +45,20 @@ fn get_cpu_times() -> CPUTimes {
|
||||
|
||||
const MICROSEC_PER_SEC: i64 = 1000 * 1000;
|
||||
|
||||
// Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes
|
||||
let max_rss_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
|
||||
result.ru_maxrss
|
||||
} else {
|
||||
result.ru_maxrss * 1024
|
||||
};
|
||||
|
||||
#[allow(clippy::useless_conversion)]
|
||||
CPUTimes {
|
||||
user_usec: i64::from(result.ru_utime.tv_sec) * MICROSEC_PER_SEC
|
||||
+ i64::from(result.ru_utime.tv_usec),
|
||||
system_usec: i64::from(result.ru_stime.tv_sec) * MICROSEC_PER_SEC
|
||||
+ i64::from(result.ru_stime.tv_usec),
|
||||
max_rss_byte,
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,11 +78,13 @@ fn test_cpu_time_interval() {
|
||||
let t_a = CPUTimes {
|
||||
user_usec: 12345,
|
||||
system_usec: 54321,
|
||||
max_rss_byte: 0,
|
||||
};
|
||||
|
||||
let t_b = CPUTimes {
|
||||
user_usec: 20000,
|
||||
system_usec: 70000,
|
||||
max_rss_byte: 0,
|
||||
};
|
||||
|
||||
let t_zero = cpu_time_interval(&t_a, &t_a);
|
||||
|
Loading…
Reference in New Issue
Block a user