Skip to content
Myr

Unify the Windows CPU timer stop interface

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 683885a · Browse files · 2 files+10 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−12 removed

  • other:+10 added−12 removed

2 files+10 added−12 removed

modified:src/timer/mod.rs-8 removed
80 unmodified lines
81 // Handle CommandOutputPolicy::Pipe82 discard(output);83 }8485 #[cfg(not(windows))]85 let (time_user, time_system, peak_memory_usage, exit_status) = cpu_timer.stop(child)?;8788 #[cfg(windows)]89 let exit_status = child.wait()?;9086 let time_wall_clock = wallclock_timer.stop();8793 #[cfg(windows)]94 let (time_user, time_system, peak_memory_usage) = cpu_timer.stop();9588 Ok(Measurement {89 time_wall_clock,90 time_user,91 time_system,
4 unmodified lines
modified:src/timer/windows_timer.rs+10 added-4 removed
1#![cfg(windows)]2#![warn(unsafe_op_in_unsafe_fn)]34use std::process::{self, Child, ExitStatus};4use std::{mem, os::windows::io::AsRawHandle, process, ptr};5use std::{mem, os::windows::io::AsRawHandle, ptr};67use anyhow::Result;89use windows_sys::Win32::{10 Foundation::{CloseHandle, HANDLE},11 System::JobObjects::{12 AssignProcessToJobObject, CreateJobObjectW, JobObjectBasicAccountingInformation,
73 unmodified lines
8687 Self { job_object }88 }8987 pub fn stop(&self) -> (Time, Time, Information) {90 pub fn stop(&self, mut child: Child) -> Result<(Time, Time, Information, ExitStatus)> {91 let status = child.wait()?;9293 let mut job_object_info =94 mem::MaybeUninit::<JOBOBJECT_BASIC_ACCOUNTING_INFORMATION>::uninit();9596 // SAFETY: A valid job object got created in `start_suspended_process`
20 unmodified lines
117 // for all active processes associated with the job, as well as all terminated118 // processes no longer associated with the job, in 100-nanosecond ticks."119 let system_time =120 Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);116 (user_time, system_time, Information::zero())121122 Ok((user_time, system_time, Information::zero(), status))123 } else {118 (Time::zero(), Time::zero(), Information::zero())124 Ok((Time::zero(), Time::zero(), Information::zero(), status))125 }126 }127}128
6 unmodified lines