Platform SDK: Performance Monitoring |
The PdhGetFormattedCounterValue function returns the current value of a specified counter in the format requested by the caller.
PDH_STATUS PdhGetFormattedCounterValue( HCOUNTER hCounter, DWORD dwFormat, LPDWORD lpdwType, PPDH_FMT_COUNTERVALUE pValue );
Value | Meaning |
---|---|
PDH_FMT_DOUBLE | Return data as a double-precision floating point real. |
PDH_FMT_LARGE | Return data as a 64-bit integer. |
PDH_FMT_LONG | Return data as a long integer. |
The value selected from the previous table can be combined using the OR operator with one of the following scaling flags.
Value | Meaning |
---|---|
PDH_FMT_NOSCALE | Do not apply the default scaling factor. |
PDH_FMT_NOCAP100 | Counter values above 100 (for example, counter values measuring the processor load on multiprocessor machines) will not be reset to 100. The default behavior is that counter values are capped at a value of 100. |
PDH_FMT_1000 | Multiply the actual value by 1000. |
If the function succeeds, it returns ERROR_SUCCESS.
If the function fails, the return value is a PDH error status defined in PDHMsg.h. The following are possible error values.
Error value | Description |
---|---|
PDH_INVALID_ARGUMENT | An argument is not correct or is incorrectly formatted. |
PDH_INVALID_DATA | The specified counter does not contain valid data or a successful status code. |
PDH_INVALID_HANDLE | The counter handle is not valid. |
The data for the counter is locked (protected) for the duration of the call to PdhGetFormattedCounterValue to prevent any changes during the processing of the call. Reading the data (calling this function successfully) clears the data-changed flag for the counter.
Obtaining the value of rate counters such as Page faults/sec requires that PdhCollectQueryData be called twice, with a specific time interval between the two calls, before calling PdhGetFormattedCounterValue. Call Sleep to implement the waiting period between the two calls to PdhCollectQueryData.
Windows NT/2000: Requires Windows NT 4.0 or later.
Header: Declared in Pdh.h.
Library: Use Pdh.lib.
PdhGetRawCounterValue, PdhSetCounterScaleFactor, PdhCollectQueryData