diff --git a/Cargo.toml b/Cargo.toml index e1fb776..610dca3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ features = [ "fileapi", "minwindef", "processenv", + "profileapi", "winbase", "wincon", "winerror", diff --git a/src/lib.rs b/src/lib.rs index 0bb259d..9e57a31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,4 +29,6 @@ pub mod console; #[cfg(windows)] pub mod file; #[cfg(windows)] +pub mod time; +#[cfg(windows)] mod win; diff --git a/src/time.rs b/src/time.rs new file mode 100644 index 0000000..1e0918e --- /dev/null +++ b/src/time.rs @@ -0,0 +1,17 @@ +use std::io; +use std::mem; + +use winapi::um::{ + profileapi::QueryPerformanceFrequency, winnt::LARGE_INTEGER, +}; + +pub fn perf_counter_frequency() -> io::Result { + unsafe { + let mut frequency: LARGE_INTEGER = mem::zeroed(); + let rc = QueryPerformanceFrequency(&mut frequency); + if rc == 0 { + return Err(io::Error::last_os_error()); + }; + Ok(*frequency.QuadPart() as u64) + } +}