10/23/11

C# Custom Performance Counters - Introduction

Table of content:

I. C# Custom Performance Counters - Introduction
II. C# Custom Performance Counters - First Performance Counter

1. Introduction

There is a moment in software engineer life when it is time to check application performance. At this certain point you will ask yourself “How can I do it?”. Answer is not simple because you can do it in a very different way. You can of course find any 3rd party application which will measure some things for you. You can make some kind of log file and insert some performance data to it, or you can use .NET System.Diagnostics namespace.

In this article I’ll focus on System.Diagnostics. I’m not saying it is the best approach, I’ll just describe some elements of it and you can decide if it suits your needs or not.

2. Where I can find Performance counters in Windows.

In Windows you can find some predefined performance counters. Just open Control Panel -> Administrative Tools -> Performance
There you can find some predefined counters on a chart.
You can of course add some additional predefined counters to the chart. Just press button marked red on the previous image and choose a Performance Object (performance category), some counters and instances.
If you would like to save some performance counters to look at the offline, you can save data to a file.

Just choose Performance Logs and Alerts -> Counter Logs.
Then press Action -> New Log Settings…  and type a name
In the next form
Press Add Counters and choose whatever you wish.


I’ve choose % Processor Time. Press Add and close when you finish.
On the Log Files sheet choose the log file type. I usually use the comma delimited file. It is easy to process in Excel for example. Set the interval on a General sheet and Schedule (if you like) to setup start and stop time for measurements.

Press OK to finish your job.

You should see the log file in location mentioned in “”Current log file name”.









No comments:

Post a Comment