Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows-specific extensions for accessing Windows profileapi #70618

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libstd/sys/windows/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod io;
pub mod process;
pub mod raw;
pub mod thread;
pub mod time;

/// A prelude for conveniently writing platform-specific code.
///
Expand Down
21 changes: 21 additions & 0 deletions src/libstd/sys/windows/ext/time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Windows-specific extensions to access Windows profileapi.

#![stable(feature = "windows_profileapi", since = "1.43.0")]

use crate::sys::c;
use crate::sys::cvt;

/// Stores the current value of the performance counter to the memory pointed by the argument pointer,
/// Counter value is a high resolution (<1us) time stamp that can be used for time-interval measurements.
#[stable(feature = "windows_profileapi", since = "1.43.0")]
pub fn QueryPerformanceCounter(qpc_value: &mut i64) -> crate::io::Result<i32> {
cvt(unsafe { c::QueryPerformanceCounter(qpc_value) })
}

/// Stores the frequency of the performance counter to the memory pointed by the argument pointer.
/// The frequency of the performance counter is fixed at system boot and is consistent across all processors.
/// Therefore, the frequency need only be queried upon application initialization, and the result can be cached.
#[stable(feature = "windows_profileapi", since = "1.43.0")]
pub fn QueryPerformanceFrequency(frequency: &mut i64) -> crate::io::Result<i32> {
cvt(unsafe { c::QueryPerformanceFrequency(frequency) })
}