Skip to content
Myr

Merge pull request #964 from sharkdp/codex/windows-timer-precision

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

Preserve 100-nanosecond precision in Windows CPU times

authored by David Peter · committed by GitHub · parents f16b6b9, 85293b5 · Browse files · 2 files+8 added−11 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+8 added−11 removed

  • other:+8 added−11 removed

2 files+8 added−11 removed

modified:src/quantity/mod.rs+3 added-1 removed
2 unmodified lines
3pub use uom::num_traits::Zero;4pub use uom::si::f64::{Information, Ratio, Time};5pub use uom::si::information::byte;6pub use uom::si::ratio::ratio;7#[cfg(any(not(windows), test))]8pub use uom::si::time::microsecond;7pub use uom::si::time::{microsecond, nanosecond, second};9pub use uom::si::time::{nanosecond, second};1011pub use units::TimeUnit;1213pub mod statistics;
122 unmodified lines
modified:src/timer/windows_timer.rs+5 added-10 removed
25 unmodified lines
26 System::LibraryLoader::{GetModuleHandleW, GetProcAddress},27 },28};2930use crate::quantity::{microsecond, Information, Time, Zero};30use crate::quantity::{nanosecond, Information, Time, Zero};3132const HUNDRED_NS_PER_MS: i64 = 10;3332#[cfg(not(feature = "windows_process_extensions_main_thread_handle"))]33#[allow(non_upper_case_globals)]34static NtResumeProcess: Lazy<unsafe extern "system" fn(ProcessHandle: HANDLE) -> NTSTATUS> =35 Lazy::new(|| {
69 unmodified lines
105106 // The `TotalUserTime` is "The total amount of user-mode execution time for107 // all active processes associated with the job, as well as all terminated processes no108 // longer associated with the job, in 100-nanosecond ticks."111 let user: i64 = job_object_info.TotalUserTime / HUNDRED_NS_PER_MS;109 let user_time = Time::new::<nanosecond>((job_object_info.TotalUserTime as f64) * 100.0);110111 // The `TotalKernelTime` is "The total amount of kernel-mode execution time112 // for all active processes associated with the job, as well as all terminated113 // processes no longer associated with the job, in 100-nanosecond ticks."116 let kernel: i64 = job_object_info.TotalKernelTime / HUNDRED_NS_PER_MS;117 (118 Time::new::<microsecond>(user as f64),119 Time::new::<microsecond>(kernel as f64),120 Information::zero(),121 )114 let system_time =115 Time::new::<nanosecond>((job_object_info.TotalKernelTime as f64) * 100.0);116 (user_time, system_time, Information::zero())117 } else {118 (Time::zero(), Time::zero(), Information::zero())119 }120 }
8 unmodified lines