Platform SDK: Performance Monitoring

Collecting Performance Data

After you create a query and add counters to it, call the PdhCollectQueryData function to retrieve the current raw data for all counters in the query. Read the counter values by calling PdhCollectQueryData for each performance data sample you want to read.

The one exception where you would not use PdhCollectQueryData to collect performance data is when performance data is to be written to a log file. Refer to Opening a Log File for Writing and Writing to the Log File for more information on this procedure.

Many counters, such as rate counters, require two data samples to calculate a formatted data value. Do the following to collect these samples.

Performance data collection can create and trigger a user-defined event. One example of when you may want this to happen is when sampling real-time data at regular intervals. Use the PdhCollectQueryDataEx function to do this. The process of calling PdhCollectQueryDataEx is the following.

PdhCollectQueryDataEx will return immediately and create a timing thread. This timing thread will wait the specified interval of time and then collect a sample of performance data and set the event. When set, this event signals the main thread that performance data is available.