From 6af23bb885e087e105babe211a4b79a2db53c83d Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 5 Oct 2026 13:51:06 +0200 Subject: [PATCH] Unify the Windows CPU timer stop interface --- src/timer/mod.rs | 8 -------- src/timer/windows_timer.rs | 14 ++++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/timer/mod.rs b/src/timer/mod.rs index 9866e39..be00286 100644 --- a/src/timer/mod.rs +++ b/src/timer/mod.rs @@ -82,17 +82,9 @@ pub fn execute_and_measure(mut command: Command) -> Result { 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, diff --git a/src/timer/windows_timer.rs b/src/timer/windows_timer.rs index 1797c67..4363990 100644 --- a/src/timer/windows_timer.rs +++ b/src/timer/windows_timer.rs @@ -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::::uninit(); @@ -113,9 +118,10 @@ impl CPUTimer { // processes no longer associated with the job, in 100-nanosecond ticks." let system_time = Time::new::((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)) } } }