mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 16:40:18 +00:00
Initial work on tracking memory usage
This commit is contained in:
1 parent
f78f482d8f
commit
6556b2bd46
13 files changed
+68
-7
No files matched your search
+17
-2
@@ -1,5 +1,6 @@
|
||||
#![cfg(not(windows))]
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::mem;
|
||||
|
||||
use crate::timer::CPUTimes;
|
||||
@@ -25,10 +26,14 @@ impl CPUTimer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(&self) -> (Second, Second) {
|
||||
pub fn stop(&self) -> (Second, Second, u64) {
|
||||
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.memory_usage_byte,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +50,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),
|
||||
memory_usage_byte: u64::try_from(max_rss_byte).unwrap_or(0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,11 +83,13 @@ fn test_cpu_time_interval() {
|
||||
let t_a = CPUTimes {
|
||||
user_usec: 12345,
|
||||
system_usec: 54321,
|
||||
memory_usage_byte: 0,
|
||||
};
|
||||
|
||||
let t_b = CPUTimes {
|
||||
user_usec: 20000,
|
||||
system_usec: 70000,
|
||||
memory_usage_byte: 0,
|
||||
};
|
||||
|
||||
let t_zero = cpu_time_interval(&t_a, &t_a);
|
||||
|
||||
Reference in new issue
Block a user