1

I have created some Load Tests. All my load tests are consist of one unit test. I have also created a LoadTest Plug-in and assigned it to all my load tests. Each unit test updates some custom performance counters that I create in the LoadTest Plug-in (more details here) with the following code.

PlugIn code:

private void m_loadTest_LoadTestStarting(object sender, System.EventArgs e)
{
    CounterCreationDataCollection counters = new CounterCreationDataCollection();
    counters.Add(new CounterCreationData("CustomCoumter", "Custom Coumter description", PerformanceCounterType.AverageCount64));

    PerformanceCounterCategory.Create("CustomCounterCategory", "Custom Performance Counters", PerformanceCounterCategoryType.MultiInstance, counters);
}

UnitTest code:

[TestClass]
public class UnitTest1
{
    PerformanceCounter customCounter;

    [ClassInitialize]
    public static void ClassInitialize(TestContext TestContext)
    {
        // Create the instances of the counters for the current test
        customCounter= new PerformanceCounter("CustomCounterCategory", "CustomCoumter", "UnitTest1", false));
    }

    [TestMethod]
    public void TestMethod1()
    {
         // ... Testing
         customCounter.Incerement(time);
    }
}

Since the plugin is running in the Test Controller the custom counter category is created in the pc where the controller is running. Now I am running my Load Tests in a Test Rig using many Test Agents. When a unit test is executing in a pc other than this where the Test Controller is running the counter is not updated. I think this happens because with my code I am updating the counter in the pc where the test is running, NOT in the controller's pc.

How can I update my custom counter in the controller's pc? Do I have to create the counter's instance in my unit tests with a different way?

Community
  • 1
  • 1
chaliasos
  • 9,659
  • 7
  • 50
  • 87

2 Answers2

2

Performance counters are usually used to monitor performance for components that are running locally on the machine. perfmon can then be used to monitor the performance counter for that machine. From what you describe, this is exactly what is happening.

So you would have to monitor the performance counter on the agent machines (after installing it there, of course) in order to get the data about the counter.

I assume that this counter is in some way measuring how long the test is taking. Because, if you were measuring the system under test then the performance counter increment would be integrated into the production code that is under test.

I'm not aware of any way to increment a performance counter on a remote machine, but this seems to be against the usual patten. However, there are ways to read remote performance counters (from the agent machines, for instance). I think this would be best in your circumstance.

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132
  • Thanks for your answer. I was hoping, if possible, to update the counters on the remote machine (controller) so I can easily see the Total results from the counters. Otherwise, I have to change my implementation and calculate on my own the Total results based on counters's instances on all agents. – chaliasos Jul 04 '12 at 14:31
  • @Schaliasos yeah, unfortunately I don't think that is possible (at least by the C# API). However, you can read remotely and then aggregate the figures from each agent. – Davin Tryon Jul 04 '12 at 14:44
0

I came across this problem myself and found that what you can do in code is setup to call a remote executable that have been pre-installed on the machine. Since it will be running locally, it can modify the performance counter.

You can either start the process psExec or WMI code.

How to execute process on remote machine, in C#

Community
  • 1
  • 1
MichaelChan
  • 1,808
  • 17
  • 34