Skip to content
Myr

Tidy up call to GetProcessTimes from getrusage example

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

authored by Steve Pentland · committed by sharkdp · parent 9753eed · Browse files · 1 file+6 added−19 removed
This commit

State

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

Diff stats

1 file+6 added−19 removed

  • other:+6 added−19 removed

1 file+6 added−19 removed

modified:src/hyperfine/timer/cputimer.rs+6 added-19 removed
2 unmodified lines
34#[cfg(windows)]5use std::os::windows::io::RawHandle;67use std::mem;89#[derive(Debug, Copy, Clone)]10struct CPUTimes {11 /// Total amount of time spent executing in user mode12 user_usec: i64,
14 unmodified lines
27/// Read CPU execution times ('user' and 'system')28#[cfg(not(windows))]29fn get_cpu_times() -> CPUTimes {30 use libc::{getrusage, rusage, RUSAGE_CHILDREN};29 use std::mem;3132 let result: rusage = unsafe {33 let mut buf = mem::zeroed();34 let success = getrusage(RUSAGE_CHILDREN, &mut buf);
22 unmodified lines
5758#[cfg(windows)]59pub fn get_process_times(handle: RawHandle) -> (i64, i64) {60 use winapi::um::processthreadsapi::GetProcessTimes;60 use winapi::shared::minwindef::FILETIME;61 use winapi::um::winnt::HANDLE;6263 // Winapi reports times as per 100 nanosecond64 const HUNDRED_NS_PER_MS: i64 = 10;65 66 let mut _ctime = FILETIME {67 dwLowDateTime: 0,68 dwHighDateTime: 0,69 };70 let mut _etime = FILETIME {71 dwLowDateTime: 0,72 dwHighDateTime: 0,73 };74 let mut kernel_time = FILETIME {75 dwLowDateTime: 0,76 dwHighDateTime: 0,77 };78 let mut user_time = FILETIME {79 dwLowDateTime: 0,80 dwHighDateTime: 0,81 };6566 let (user_usec, system_usec) = unsafe {67 let mut _ctime = mem::zeroed();68 let mut _etime = mem::zeroed();69 let mut kernel_time = mem::zeroed();70 let mut user_time = mem::zeroed();71 let res = GetProcessTimes(72 handle as HANDLE,73 &mut _ctime,74 &mut _etime,
72 unmodified lines