mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Use unit system in unix_timer
This commit is contained in:
1 parent
641451aea6
commit
e2fc547dad
1 file changed
+16
-14
+16
-14
@@ -13,19 +13,21 @@ use crate::benchmark::quantity::{Information, InformationQuantity, Time, TimeQua
|
|||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
struct ResourceUsage {
|
struct ResourceUsage {
|
||||||
/// Total amount of time spent executing in user mode
|
/// Total amount of time spent executing in user mode
|
||||||
pub user_usec: f64,
|
pub time_user: Time,
|
||||||
|
|
||||||
/// Total amount of time spent executing in kernel mode
|
/// Total amount of time spent executing in kernel mode
|
||||||
pub system_usec: f64,
|
pub time_system: Time,
|
||||||
|
|
||||||
/// Maximum amount of memory used by the process, in bytes
|
/// Maximum amount of memory used by the process, in bytes
|
||||||
pub memory_usage_byte: i64,
|
pub memory_usage: Information,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::useless_conversion)]
|
#[allow(clippy::useless_conversion)]
|
||||||
fn timeval_to_seconds(tv: libc::timeval) -> f64 {
|
fn convert_timeval(tv: libc::timeval) -> Time {
|
||||||
const MICROSEC_PER_SEC: i64 = 1000 * 1000;
|
let sec = tv.tv_sec as f64;
|
||||||
(i64::from(tv.tv_sec) * MICROSEC_PER_SEC + i64::from(tv.tv_usec)) as f64 * 1e-6
|
let usec = tv.tv_usec as f64;
|
||||||
|
|
||||||
|
Time::from_seconds(sec) + Time::from_microseconds(usec)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::useless_conversion)]
|
#[allow(clippy::useless_conversion)]
|
||||||
@@ -45,17 +47,17 @@ fn wait4(mut child: Child) -> io::Result<(ExitStatus, ResourceUsage)> {
|
|||||||
|
|
||||||
let memory_usage_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
|
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
|
// Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes
|
||||||
rusage.ru_maxrss
|
Information::from_bytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0))
|
||||||
} else {
|
} else {
|
||||||
rusage.ru_maxrss * 1024
|
Information::from_kibibytes(u64::try_from(rusage.ru_maxrss).unwrap_or(0))
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
ExitStatus::from_raw(status),
|
ExitStatus::from_raw(status),
|
||||||
ResourceUsage {
|
ResourceUsage {
|
||||||
user_usec: timeval_to_seconds(rusage.ru_utime),
|
time_user: convert_timeval(rusage.ru_utime),
|
||||||
system_usec: timeval_to_seconds(rusage.ru_stime),
|
time_system: convert_timeval(rusage.ru_stime),
|
||||||
memory_usage_byte: memory_usage_byte.into(),
|
memory_usage: memory_usage_byte.into(),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -72,9 +74,9 @@ impl CPUTimer {
|
|||||||
let (status, usage) = wait4(child)?;
|
let (status, usage) = wait4(child)?;
|
||||||
Ok((
|
Ok((
|
||||||
status,
|
status,
|
||||||
Time::from_seconds(usage.user_usec),
|
usage.time_user,
|
||||||
Time::from_seconds(usage.system_usec),
|
usage.time_system,
|
||||||
Information::from_bytes(u64::try_from(usage.memory_usage_byte).unwrap_or(0)),
|
usage.memory_usage,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user