Platform SDK: Performance Monitoring

PdhComputeCounterStatistics

The PdhComputeCounterStatistics function computes statistics for a counter from an array of raw values.

PDH_STATUS PdhComputeCounterStatistics(
  HCOUNTER hCounter,  
  DWORD dwFormat,     
  DWORD dwFirstEntry, 
  DWORD dwNumEntries, 
  PPDH_RAW_COUNTER lpRawValueArray,
  PPDH_STATISTICS data  
);

Parameters

hCounter
[in] A handle to the counter used for the computation. This determines how the data will be computed.
dwFormat
[in] Formatting information sent by the caller to indicate how the calculated value should be returned. This parameter can be one of the following values.
Value Meaning
PDH_FMT_DOUBLE Return the calculated value as a double-precision floating point real.
PDH_FMT_LARGE Return the calculated value as a 64-bit integer.
PDH_FMT_LONG Return the calculated value 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 counter's scaling factors in the calculation.
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 final value by 1000.

dwFirstEntry
[in] The zero-based index of the first raw counter buffer to look at. This value must point to the oldest entry in the buffer. The PdhComputeCounterStatistics function starts at this entry and scans through the buffer, wrapping at the last entry back to the beginning of the buffer and up to the dwFirstEntry-1 entry, which is assumed to be the newest or most recent data.
dwNumEntries
[in] The number of raw counter entries in the lpRawValueArray buffer.
lpRawValueArray
[in] A pointer to the raw counter value or values used to compute the counter value. Some counters (for example, rate counters) require two values for a calculation. The format of the buffer is assumed to be an array of PDH_RAW_COUNTER structures that contain dwNumEntries entries.
data
[out] A pointer to a PDH_STATISTICS structure that receives the counter statistics.

Return Values

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_HANDLE The counter handle is not valid.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Header: Declared in Pdh.h.
  Library: Use Pdh.lib.

See Also

PdhCalculateCounterFromRawValue, PdhGetRawCounterValue, PDH_RAW_COUNTER, PdhSetCounterScaleFactor, PDH_STATISTICS