This blog post will describe how to create custom counter sets.  First let me start with what a counter set is.  It is a collection of counters that you can collect during the execution of a load test.  Visual Studio provides a number of counter sets already defined.  They are sets such as IIS or SQL.  In these counter sets, you will find counters which are interesting to collect for machines running IIS or SQL Server.  Counter Sets are a good way to group counters for a particular technology.  Here is a link which describes some more high level information about counter sets: Counter Sets on MSDN

 

As I mentioned, we provide a number of pre-defined counter sets, but what if you want to collect a counter that isn’t already part of a set.  This is easy.  You can either create a new counter set to add the counter to or add it to a counter set that already exists.  Let’s create a new counter set.

 

1)      Open a load test in the load test editor.

2)      Then right click on the counter sets node and select “Add custom counter set”.

3)      You can rename the counter set from the property browser.

4)      Now right click on the new counter set and select “Add Counters…”.  This will launch dialog which is similar to the perfmon counter dialog.

5)      In this dialog, select a Counter Category and then a counter.  You can also select specific instances of the counter of all instances.

6)      Then click Ok.  As you can see the counter has been added to the counter set.

 

Now you can map this counter set to any of your machines under test and this set of counters will be collected.  It can be very useful to define specific counter sets for the different types of machines under test.

 

Now you have a new counter set, but what if you want to use this new counter set in a different load test.  There are 2 options and I’ll go through both.

 

First open the new load test.  Now go back to the original load test with the new counter set.  Right click on the counter set and select Copy.  Then go to the new load test.  Now right click on the Counter Sets node and select Paste.  As before, you can map the counter set to a machine under test.

 

The second way to share the counter set is to create a new counter set template.  This process is very similar to another blog post I wrote about adding a new browser template: Adding Browser Templates.  A counter set template is an xml file.  Here are step for creating a new template:

1)      Go to the location the templates are stored in: Program Files\Microsoft Visual Studio 9\Common7\IDE\Templates\LoadTest\CounterSets

2)      Copy an existing template that most closely matches what you want the new template to look like.

3)      Rename the file

4)      Open the file.  First change the Name and CounterSetType attributes on the CounterSet node. 

5)      Now start modifying the categories, counters and instances.  Once you are done save the file.

 

Now let’s verify the new template loads correctly. 

1)      First restart Visual Studio

2)      Create a new load test. 

3)      Once you have a load test, right click on the Counter Sets node and select Manage Counter Sets. 

4)      In the manage counter sets dialog, click add computer and enter a computer to collect counters on. 

5)      Then the list of available counter sets should be displayed.  You should see your new counter set.

 

 

There are a few more things to know about the second approach.  First, when you add a counter set to a load test, the template is pulled into the load test.  If you open the load test file with notepad, you will see each of the counter sets.  This means that you can share this load test with someone that does not have the new template.  Second, if you want to share the new template, just have other users scopy it to the following location: Program Files\Microsoft Visual Studio 9\Common7\IDE\Templates\LoadTest\CounterSets.