NtQueryPerformanceCounter - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTEXAPI_H
#if (PHNT_MODE != PHNT_MODE_KERNEL)

//
// Performance Counters
//

/**
 * The NtQueryPerformanceCounter routine retrieves the current value of the performance counter,
 * which is a high resolution (<1us) time stamp that can be used for time-interval measurements.
 *
 * \param PerformanceCounter A pointer to a variable that receives the current performance-counter value, in 100-nanosecond units.
 * \param PerformanceFrequency A pointer to a variable that receives the current performance-frequency value, in 100-nanosecond units.
 * \return NTSTATUS Successful or errant status.
 * \remarks On systems that run Windows XP or later, the function will always succeed and will thus never return zero. Use RtlQueryPerformanceCounter instead since no system calls are required.
 * \sa https://learn.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter
 */
NTSYSCALLAPI
NTSTATUS
NTAPI
NtQueryPerformanceCounter(
    _Out_ PLARGE_INTEGER PerformanceCounter,
    _Out_opt_ PLARGE_INTEGER PerformanceFrequency
    );

#endif
#endif

View code on GitHub
#ifndef _NTZWAPI_H

NTSYSCALLAPI
NTSTATUS
NTAPI
ZwQueryPerformanceCounter(
    _Out_ PLARGE_INTEGER PerformanceCounter,
    _Out_opt_ PLARGE_INTEGER PerformanceFrequency
    );

#endif

View code on GitHub
NTSTATUS NtQueryPerformanceCounter(
  _Out_     PLARGE_INTEGER PerformanceCounter,
  _Out_opt_ PLARGE_INTEGER PerformanceFrequency
);
View the official Win32 development documentation

NtDoc

No description available.

Win32 development documentation (ntqueryperformancecounter)

NtQueryPerformanceCounter function

[This function is not supported and should not be used. Use the QueryPerformanceCounter and QueryPerformanceFrequency functions instead.]

Returns the current value of a performance counter and, optionally, the frequency of the performance counter.

Parameters

PerformanceCounter [out]

The address of a variable to receive the current performance counter value.

PerformanceFrequency [out, optional]

The address of a variable to receive the performance counter frequency.

Return value

If the function succeeds, it returns the NTSTATUS code STATUS_SUCCESS; otherwise, it returns an error code such as STATUS_ACCESS_VIOLATION.

Remarks

No header file is available for NtQueryPerformanceCounter. You should use the alternative functions named above, although you can also use the LoadLibrary and GetProcAddress functions to dynamically link to Ntdll.dll.

Performance frequency is the frequency of the performance counter in hertz, specifically in counts per second. This value is implementation dependent. If the implementation does not have hardware to support performance timing, the value returned is 0.

Requirements

Requirement Value
DLL
Ntdll.dll

See also

QueryPerformanceCounter

QueryPerformanceFrequency


NTinternals.net (undocumented.ntinternals.net)

This function is documented in Windows SDK.


PerformanceCounter

Result is number of processor ticks after last reset.

PerformanceFrequency

It's number of processor ticks per one second.


Another method of uptime calculation:

UpTime = PerformanceCounter / PerformanceFrequency;

Related Win32 API

Documented by