PDH functions work with queries and counters. A query is a set of performance counters that are grouped together so that you can collect their data at the same time. A counter is a performance data item stored in the Windows NT registry.
The counter names used by PDH are expressed as counter paths. A counter path uses a collection of hierarchical elements to describe a counter. In the same way that a file path includes drives, directories, subdirectories, and file names, a counter path includes machines, objects, instances, and counter names. The syntax for a counter path is:
\\Machine\PerfObject(ParentInstance/ObjectInstance#InstanceIndex)\Counter
The \\Machine component is optional; it specifies the name of the machine. If you do not supply this component, PDH uses the local machine name. Therefore, a single path string works on any machine that supports the counter.
The \PerfObject component is required; it specifies the performance object that contains the performance counter. These objects are listed in the PDH browse dialog box (see PdhBrowseCounters) and in the Performance Monitor Add To Chart dialog box, in the Objects combo box. If this object has a variable list of instances, then you must also specify an instance string.
The (ParentInstance/ObjectInstance#InstanceIndex) component is only required if the object supports multiple instances. If the instance supports a variable list of instances, then you must specify an instance string. The format of the string depends on the object type. If the object has simple instances, then the format is just the instance name enclosed in parentheses. For example:
(Explorer)
If the instance of this object requires a parent instance name as well, then the parent instance name must come before the object instance, and be separated by a forward slash character. For example:
(Explorer/0)
If the object has multiple instances that have the same name string, they can be indexed sequentially by specifying the instance index prefixed by a pound sign. Instance indexes are 0-based, so all instances have an implicit "0" index. For example:
(Explorer/0#1)
The \Counter component is required; it specifies the performance counter. The counter names are displayed in the PDH browse dialog box and in the Performance Monitor Add To Chart dialog box, in the Counters list box. The counters associated with the selected object are displayed.
The following are two common counters in the PDH counter path format:
\Processor(0)\% Processor Time
\System\% Total Processor Time
For more information on counters, see Performance Objects and Counters.
A query can contain one or more counters, and a counter can be contained in more than one query. To use PDH, you must create queries and add counters to them, as shown in the following sections.