Home > Articles > C# Articles > Measuring C# application performance using performance counters

Measuring C# application performance using performance counters

by Rahul Pyarelal   on Nov 17, 2016   Category: C#  | Level: Beginner  |  Views: 2065    |  Points: 100   
Like this article? Bookmark and Share:
In this article we will measuring C# application performance using performance counters.


What are Performance counters and PERFMON?

Measuring memory consumed by C# application


When it comes to C# application some or other time we need to measure performance. Now think about it your application has gone damn slow and you are on production machine and you need to check the cause for it.

The administrators of the server by nature are so protective that they do not want you to install visual studio or any other profiler tool. In such situations your only dear and near friend is the PERFMON tool and performance counters.

What are Performance counters and PERFMON?

Performance counters are small data variable in your windows operating system which collects performance related information about applications running in your windows OS.

So for example you have excel application running your windows OS and you want to measure how much CPU is utilized or memory is consumed, then you need to track performance counter variable for processor and memory.

PERFMON is a simple tool which helps to view performance counters.

Measuring memory consumed by C# application

So now lets us go ahead and create a simple C# console application and track how much memory is consumed by that application.

So in order to achieve the same below is a simple code which has two for loops.

using System;

staticvoid Main(string[] args)
Console.WriteLine(" Multiplication Tables");

for (int i = 2222; i <= 2240; i++)

for (int j = 1; j <= 10; j++)
Console.WriteLine("{0}*{1}={2}", i, j, i * j);

So first go ahead and the run the application “release” mode or we can say press control + f5. This will make your application running.

Once your application is running , we will run perfmon to monitor the memory. Also please note that we have a console.read statement which makes sure that our for loops do not run and we get ample time to measure the performance counters.

So go to run and type perfmon as shown in the below image.

Once you run perfmon the below window open and you need to click select performance monitor.

Once you click on the performance monitor tab you will see a screen witha running graph as shown below.

You can also change from a running graph to an absolute view mode by clicking on icon as shown in the below image and by clicking on report.

So for now we are not interested to see processor time so we can right click on the current processor counter and remove all counters.

Once the counters are removed you can now right click on the white area and say add counters.

When you click on "Add counter", a new window will be open. After that firstwe need to select.NET CLR Memory. Then select the "Bytes in the heaps” and click on the project name under the “Instances of selected object” as show in the below screenshot.

Click on add button under Instances of selected objectsection your project name will be appear on the right side to Added counters.

Select .NET CLR memory under added counters as shown on the above screen and that should display memory consumed by the application.

I believe in learning fromyoutubeas it has sea of information when it comes to learning C# and .NET. Yesterday I came across this video which explains the need of delegates in C#, worth a watch.

Like this article? Bookmark and Share:

Most viewed Articles

User Comments

No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts