mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-12 02:22:35 +00:00
Unify the Windows CPU timer stop interface
This commit is contained in:
@@ -82,17 +82,9 @@ pub fn execute_and_measure(mut command: Command) -> Result<Measurement> {
|
||||
discard(output);
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
let (time_user, time_system, peak_memory_usage, exit_status) = cpu_timer.stop(child)?;
|
||||
|
||||
#[cfg(windows)]
|
||||
let exit_status = child.wait()?;
|
||||
|
||||
let time_wall_clock = wallclock_timer.stop();
|
||||
|
||||
#[cfg(windows)]
|
||||
let (time_user, time_system, peak_memory_usage) = cpu_timer.stop();
|
||||
|
||||
Ok(Measurement {
|
||||
time_wall_clock,
|
||||
time_user,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#![cfg(windows)]
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use std::{mem, os::windows::io::AsRawHandle, process, ptr};
|
||||
use std::process::{self, Child, ExitStatus};
|
||||
use std::{mem, os::windows::io::AsRawHandle, ptr};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use windows_sys::Win32::{
|
||||
Foundation::{CloseHandle, HANDLE},
|
||||
@@ -84,7 +87,9 @@ impl CPUTimer {
|
||||
Self { job_object }
|
||||
}
|
||||
|
||||
pub fn stop(&self) -> (Time, Time, Information) {
|
||||
pub fn stop(&self, mut child: Child) -> Result<(Time, Time, Information, ExitStatus)> {
|
||||
let status = child.wait()?;
|
||||
|
||||
let mut job_object_info =
|
||||
mem::MaybeUninit::<JOBOBJECT_BASIC_ACCOUNTING_INFORMATION>::uninit();
|
||||
|
||||
@@ -113,9 +118,10 @@ impl CPUTimer {
|
||||
// processes no longer associated with the job, in 100-nanosecond ticks."
|
||||
let system_time =
|
||||
Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);
|
||||
(user_time, system_time, Information::zero())
|
||||
|
||||
Ok((user_time, system_time, Information::zero(), status))
|
||||
} else {
|
||||
(Time::zero(), Time::zero(), Information::zero())
|
||||
Ok((Time::zero(), Time::zero(), Information::zero(), status))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user