Easy Guide: Adding Counters To Performance Monitor

how to add a counter to performance monitor

Performance counters are a great way to monitor your computer's performance and fix any issues. Windows Performance Monitor is a tool that allows you to collect and view data from various performance counters, helping you to identify and address any problems. In this guide, you will learn how to add a counter to the Performance Monitor, providing you with a comprehensive understanding of your system's performance. Whether you are a system administrator or a software developer, performance counters can offer valuable insights into CPU, memory, and disk usage, enabling you to optimise your computer's performance.

shundigital

How to open Performance Monitor

Performance Monitor is a tool that can help you identify what's wrong with your Windows computer or laptop. It has been available in Windows operating systems since 1993. This tool can help you monitor how your computer’s processor, memory, or storage space are utilized and troubleshoot problems.

Using Search

Click or tap inside the search bar or press the Windows key on your keyboard. Type 'perfmon' or 'Performance Monitor' and then press Enter or click/tap on the appropriate search result.

Using the Start Menu shortcut

In Windows 10, Performance Monitor has its own shortcut in the Start Menu. You can use it to open the app with just a few clicks: click on the Windows icon from the taskbar, scroll down the list of apps until you see the Windows Administrative Tools folder, and click or tap on it to expand it, and then find and click/tap on the Performance Monitor shortcut.

From the command line

If you need to start Performance Monitor from the command line, you can do that by opening Command Prompt, PowerShell, or Windows Terminal and typing this command: 'perfmon'. The Performance Monitor app is opened as soon as you press the Enter key on your keyboard.

Running the executable file

Like all desktop apps for Windows, Performance Monitor has an executable file that you can use to run it. This file can be found by going to: C:\Windows\System32\perfmon.exe. To run it, simply double-click (or double-tap) on it. You can also open its location by using environment variables like this: %WINDIR%\System32\perfmon.exe.

From Run

Press the Windows + R keys on your keyboard to open the Run window. In the Open field, type 'perfmon', press Enter on the keyboard, or click OK.

shundigital

How to add counters to monitor applications and hardware performance

Performance counters are an integral part of monitoring and optimising system performance. They provide detailed data on various system components, including CPU, memory, disk, and network interfaces, allowing administrators to identify and resolve any performance issues.

Using Performance Monitor (PerfMon):

  • Open Performance Monitor: Press Windows + R, type "perfmon", and press Enter.
  • Click the "+" button: This is usually green and located on the toolbar.
  • Select the desired performance object: For example, Processor or Memory.
  • Choose specific counters and instances to monitor: You can monitor multiple instances of a performance object, such as individual CPU cores or physical disks.
  • Click "Add" and then "OK" to start monitoring.

Using Logman for Data Collection:

Logman is a command-line tool for automated data collection:

  • Creating a Data Collector: Open Command Prompt as an administrator and use the command "logman create counter -c "\Processor(_Total)\% Processor Time" -si 60 -o "C:\PerfLogs\"". Replace with your chosen name.
  • Starting and Stopping Data Collection: To start, use "logman start
  • Viewing Collected Data: Data is saved in the specified output file location and can be analysed using Performance Monitor or other tools.

Using Performance Logs and Alerts (PLA):

PLA allows for automated logging and alerting:

  • Creating a Data Collector Set: Open Performance Monitor, expand "Data Collector Sets", right-click "User Defined", select "New", then "Data Collector Set", and follow the wizard to choose counters and set alert conditions and thresholds.
  • Starting the Data Collector Set: Right-click the set and select "Start". The system will now log data and generate alerts.

Using Windows Management Instrumentation (WMI):

WMI enables programmatic access to performance data:

  • Accessing WMI Performance Data: Open PowerShell or Command Prompt and use WMI queries such as "Get-WmiObject -Query "SELECT FROM Win32_PerfFormattedData_PerfOS_Processor"".
  • Creating Custom Scripts: PowerShell scripts can be used to automate data collection and monitoring, e.g., to monitor CPU usage.

shundigital

How to customise the Performance Monitor view

Once you have added the required counters to the Performance Monitor, you can customise the view by following these steps:

  • Double-click on one of the counters to open the Performance Monitor Properties window.
  • On the "Data" tab, select the counter you want to customise.
  • At the bottom, choose the colour, scale, width, and style you want to use.
  • Repeat steps 2 and 3 for each item you want to customise. If you are trying to change the properties for multiple counters, press and hold the Ctrl key, select each item you want to customise, and change the available settings.
  • You can also change the graph's style by clicking the "Change graph type" in the toolbar and selecting one of the available views, including Line, Histogram bar, and Report.
  • Other options in the toolbar allow you to remove and highlight counters, and freeze the display to analyse the current data on the screen.
  • In the context menu, you will also see the "Save Settings as" option, which is useful when you want to save the counters and configuration for later use.

shundigital

How to save the counters' setup

To save your setup of counters in Performance Monitor, you can try the following methods:

Using MMC

  • Launch the Microsoft Management Console (mmc.exe).
  • Go to File -> Add/Remove Snap-ins.
  • Select Performance Monitor, then click Add > and OK.
  • Add your desired counters.
  • Save the resulting .msc file.

Using Perfmon /sys

  • Open Performance Monitor by typing "perfmon /sys" into the Run window.
  • Add the desired counters.
  • Right-click on the graph and choose "Save Settings As" to save a web page version of the current view.
  • Open the saved file with Internet Explorer and allow blocked content.
  • Make any desired changes to the counters.
  • Save and load the file using the options in the File menu.

Using Data Collector Sets

  • Define a Data Collector Set and add the desired performance counters.
  • Run the Data Collector Set to completion to generate Reports.
  • Copy and paste counters from one report to another.
  • Go back to Performance Monitor (the live view) and paste the counters.

Using Copy and Paste

  • Open Performance Monitor and add the desired counters.
  • Copy the properties of the session by clicking on the Copy Properties icon.
  • Open Notepad and paste the copied content.
  • Save the Notepad file.
  • When you want to use the settings again, open the file, copy all the text, and click on the Paste Properties icon in Performance Monitor.

shundigital

How to create a performance object and its counters

A performance object is an entity for which performance data is available. Performance counters define the type of data that is available for a performance object. An application can provide information for multiple performance objects. Performance objects can contain either single instance counters or multiple instance counters.

A single instance object returns a single set of counter values. A multiple instance object returns an instance of the object for each occurrence of the object that the application controls. For example, a SCSI application could define a drive object with two counters, such as Bytes Read and Bytes Written.

After deciding if your object supports a single instance or multiple instances, you need to decide on the type of counters that you want the object to provide. For example, you can provide counter values that are displayed as raw values, as rates, or as percentages.

Here's a step-by-step guide on how to create a performance object and its counters:

  • Decide on the type of performance object you want to create (single instance or multiple instance).
  • Choose the type of counters you want the object to provide (raw values, rates, percentages, etc.).
  • Define the counters for your performance object. For example, for a "Processor" performance object, you may have counters such as "Processor Time", "% Processor Time", and "Interrupts/sec".
  • Determine the data collection method. This can be as simple as incrementing a counter each time a particular routine in the application is called, or it can involve more complex calculations.
  • Create the performance object in code by defining its name, description, and the counters associated with it.
  • Instantiate the performance object in your application, specifying the instance name and other relevant details.
  • Start collecting performance data by calling the appropriate methods on the performance object, such as "Start()", "Stop()", and "Collect()".
  • Store and display the collected performance data as per your application's requirements.

Here's an example code snippet in C# to illustrate the process:

Csharp

Using System;

Using System.Diagnostics;

Public class PerformanceObjectExample

{

Private PerformanceCounterCategory performanceCategory;

Private PerformanceCounter counterProcessorTime;

Private PerformanceCounter counterProcessorUsage;

Private PerformanceCounter counterInterrupts;

Public PerformanceObjectExample()

{

// Create the performance category

PerformanceCategory = new PerformanceCounterCategory("Processor", "Performance counters for the processor",

PerformanceCounterCategoryType.SingleInstance, "ProcessorCategory");

// Create the performance counters

CounterProcessorTime = new PerformanceCounter("Processor", "Processor Time", "ProcessorCategory", false);

CounterProcessorUsage = new PerformanceCounter("Processor", "% Processor Time", "ProcessorCategory", false);

CounterInterrupts = new PerformanceCounter("Processor", "Interrupts/sec", "ProcessorCategory", false);

}

Public void Start()

{

// Start the performance counters

CounterProcessorTime.Start();

CounterProcessorUsage.Start();

CounterInterrupts.Start();

}

Public void Stop()

{

// Stop the performance counters

CounterProcessorTime.Stop();

CounterProcessorUsage.Stop();

CounterInterrupts.Stop();

}

Public void CollectData()

{

// Collect performance data

CounterProcessorTime.NextValue();

CounterProcessorUsage.NextValue();

CounterInterrupts.NextValue();

}

}

In this example, we create a "Processor" performance object with three counters: "Processor Time", "% Processor Time", and "Interrupts/sec". We then start the counters, collect performance data, and can subsequently display or store the collected data as needed.

Remember to dispose of the performance counters and category when you're done to free up resources.

Frequently asked questions

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment