Issues with using Custom Counter in Goal Based Load Pattern inside Load Test

If you are using custom counter in goal based load pattern inside load test then you may come across this kind of error while running load test:

Exception LoadTestGoalCounterNotFoundException 1 A goal based load pattern can not be applied because it specifies a performance counter (RUBELSVM1\MyCategory1\MyCounter1\) that could not be read: Category does not exist.

In error message above, MyCounter1 is custom counter, MyCategory1 iscounter category and RubelsVM1 is box where this counter is defined. This is how my goal based load pattern looks like:

This error occurs because of a known issue with Dev10 because of which test controller always look for counter on test controller machine for a remote run or on the visual studio client machine for a local run.

To workaround this issue, you need to create the custom category and counter on your test controller box when running remote runs or on the visual studio clientbox in case of local run.

It is easy to create custom counter on a box. This is the sample code which you can use to create custom category and counter:

 using System.Diagnostics;

namespace CreateCustomCounter
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a collection of type CounterCreationDataCollection.
            System.Diagnostics.CounterCreationDataCollection CounterDatas =
               new System.Diagnostics.CounterCreationDataCollection();
            // Create the counters and set their properties.
            System.Diagnostics.CounterCreationData cdCounter1 =
               new System.Diagnostics.CounterCreationData();
            cdCounter1.CounterName = "MyCounter1";
            cdCounter1.CounterHelp = "help string1";
            cdCounter1.CounterType = System.Diagnostics.PerformanceCounterType.NumberOfItems64;
            // Add both counters to the collection.
            CounterDatas.Add(cdCounter1);
            // Create the category and pass the collection to it.
            System.Diagnostics.PerformanceCounterCategory.Create(
                "MyCategory1", "Category help",
                PerformanceCounterCategoryType.SingleInstance, CounterDatas);
        }
    }
}
  

Your load test should run fine without any errors after you've created the custom counters on test controller / client box. Please note that you need to run the above program with admin privileges. You can refer here for more details on creating custom counters.

If you have any questions or comments please email the author at: rubels@microsoft.com