Displaying Performance Data
Most counters require two sample values in order to compute a displayable value. The formula for each counter determines if the counter requires two samples. For a list of counters and their formulas, see the Counter Types section of the Windows Server 2003 Deployment Kit.
If you need to scale the counter value up or down in order to display the value, call the PdhSetCounterScaleFactor function before calling PdhGetFormattedCounterValue. Counter values can be scaled by a power of ten from a factor of -7 to 7.
If the counter path contains a wildcard character for the instance name, call PdhGetFormattedCounterArray to retrieve an array of formatted counter values for each instance collected.
You can also use the PdhCalculateCounterFromRawValue and PdhFormatFromRawValue functions to compute a displayable value. To use these functions, you must retrieve the collected sample after each PdhCollectQueryData call and store the sample yourself. To retrieve the sample, call the PdhGetRawCounterValue or PdhGetRawCounterArray function. For time-based counter values, call PdhGetCounterTimeBase before PdhFormatFromRawValue to retrieve the counter's time base.
If you perform calculations using the raw data, always check the CStatus member of the PDH_RAW_COUNTER structure before using the sample. The sample is not valid if the value of CStatus is not PDH_CSTATUS_NEW_DATA or PDH_CSTATUS_VALID_DATA.
Displaying statistics for a counter
If you want to compute the minimum, maximum, and mean values of a counter, call the PdhComputeCounterStatistics function. When you collect samples, store the PDH_RAW_COUNTER structures in an array that you pass to PdhComputeCounterStatistics. The function returns the statistical values in a PDH_STATISTICS structure.
You can also use this function to compress a log file. For example, read ten records from a log file, call PdhComputeCounterStatistics to compute the mean value and then write the mean value to an output log file.