Skip to content

Enumerates and prints all windows system performance counters

Notifications You must be signed in to change notification settings

nikvoronin/AllPerformanceCounters

Repository files navigation

All Performance Counters

Enumerates and prints all system performance counters

System Utility

You can monitor your Windows system over Performance Monitor:

Win+RperfmonOK

tools_perfmon_addCounters

Code First

MSDN: System.Diagnostics.PerformanceCounter

It is important to select right thread culture:

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  • Category
    • Counter 1
      • Instance01 of counter 1
      • Instance02 of counter 1
      • ...
    • Counter 2
    • ...
  • Category ...

How To Measure

CPU Load

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

var processorCategory =
    PerformanceCounterCategory
    .GetCategories()
    .FirstOrDefault( cat => cat.CategoryName == "Processor" );

var countersInCategory =
    processorCategory
    ?.GetCounters( "_Total" );

var cpuLoadCounter =
    countersInCategory
    ?.First( cnt => cnt.CounterName == "% Processor Time" );

while ( !Console.KeyAvailable ) {
    Console.WriteLine( $"CPU Load: { cpuLoadCounter?.NextValue() ?? 0f }" );
    Thread.Sleep( 300 );
}

Memory Usage

Some categories contains instances but some not. Memory has not:

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

var memoryCategory =
    PerformanceCounterCategory
    .GetCategories()
    .FirstOrDefault( cat => cat.CategoryName == "Memory" );

var memoryUsage =
    memoryCategory
    ?.GetCounters()
    .First( cnt => cnt.CounterName == "Available MBytes" );

while ( !Console.KeyAvailable ) {
    Console.WriteLine( $"Memory usage: { memoryUsage?.NextValue() ?? 0f } MBytes" );
    Thread.Sleep( 300 );
}

Temperature

Temperature in Kelvin degrees.

Chips used for things like fan control have an internal structure that allows them to be set up so that zone 1 might be ram+cache, zone 2 cpu, zone 3 video card. Pretty much the way you can divide a home into zones for heating and cooling.

const double AbsZeroK = 273.15;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

var thermalCategory =
    PerformanceCounterCategory
    .GetCategories()
    .FirstOrDefault( cat => cat.CategoryName == "Thermal Zone Information" );

var countersInCategory =
    thermalCategory
    ?.GetCounters( @"\_TZ.TZ00" );

var temperature =
    countersInCategory
    ?.First( cnt => cnt.CounterName == "High Precision Temperature" ); // "Temperature"

while ( !Console.KeyAvailable ) {
    Console.WriteLine( $"Temperature: { (( temperature?.NextValue() ?? AbsZeroK * 10.0 ) / 10.0 - AbsZeroK):0.#} °C" );
    Thread.Sleep( 300 );
}

Command line with PowerShell:

Get-WmiObject -Class Win32_PerfFormattedData_Counters_ThermalZoneInformation |Select-Object Name,Temperature

Instances for thermal zones (TZ):

  • _TZ.THRM
  • _TZ.TZ00, _TZ.TZ01, _TZ.TZ02
  • _TZ.EXTZ
  • _TZ.GFXZ - GPU or graphics card
  • _TZ.LOCZ
  • _TZ.BATZ - Battery
  • _TZ.CPUZ - CPU
  • _TZ.CHGZ
  • _TZ.TSZ0
  • _TZ.GETP
  • _TZ.CHGZ._CRT
  • _TZ.HPTZ
  • _TZ.DTSZ - digital thermal sensor
  • _TZ.SKNZ
  • _TZ.FDTZ - fan speed not temperature

Examples

HP ProBook G7 Laptop

Thermal Zone Information
    >>> INSTANCES
    \_TZ.EXTZ
        >>> COUNTERS
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature
    \_TZ.GFXZ
        >>> COUNTERS
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature
    \_TZ.LOCZ
        >>> COUNTERS
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature
    \_TZ.BATZ
        >>> COUNTERS
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature
    \_TZ.CPUZ
        >>> COUNTERS
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature
    \_TZ.CHGZ
        >>> COUNTERS
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature

Acer Nitro 5 Laptop

CATEGORY: Thermal Zone Information
    INSTANCE: \_TZ.TZ01
        >>> COUNTERS:
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature
    INSTANCE: \_TZ.TZ00
        >>> COUNTERS:
        Temperature
        % Passive Limit
        Throttle Reasons
        High Precision Temperature

About

Enumerates and prints all windows system performance counters

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages