How to read performance counters?  Download
The performance class is a collection of performance counters. For example, a class with name "System" may define several performance counters, such as "Processor Queue Length", "Context Switches/sec", "System Up Time", etc.

The Delphi program below retrieves the value of performance counter and prints it out to the console. This example utilizes TWmiPerformanceMonitor component. The source code below creates and destroys the components on the fly, so this function may be easily adopted for console- or UI-type applications.


program performance_obtain_value;
// This example retrieves the value of a counter that shows the percent of time 
// that processes on the local computer spent in the user mode. 

{$APPTYPE CONSOLE}
uses
  SysUtils, WmiPerformanceMonitor;

var
  vMonitor: TWmiPerformanceMonitor;
  vValue: TWmiPerfCounter;
begin
  vMonitor := TWmiPerformanceMonitor.Create(nil);
  try
    vMonitor.Active := true;
    vMonitor.PerfCounters.Add('Win32_PerfRawData_PerfProc_Process',
                              'PercentUserTime',
                              '_Total');
    vValue := vMonitor.PerfCounters.Items[0];
    while true do
    begin
      writeln(vValue.CounterDefinition.DisplayName, ' ', vValue.FormattedValue);
      Sleep(1000);
    end;
  finally
    vMonitor.Free;
  end;
end.