Freigeben über


Machine Performance Counter Collection for Load Tests - Automating collection

In one of our Performance Labs we had a requirement to collect the Performance Counter Logs across more than 15 Application & DB Servers..

Doing them manually each time was not easy and often times error prone. I got the batch Files created which had the Logman commands that triggered the remote collection and then copied them over to a shared network path. That simplified the process greatly. However, We were still running these batch files manually before and after every Load Tests. It wasn't that bad but hey if you could automate it further then why not.

I thought it might just be more convenient to have the process baked into the Load Tests itself leveraging the Load Test Extensibility Points.

Below is the Load Test Plug-in code that did the job for me.

namespace OnePlugins
{
    public class LoadTestInitCleanup : ILoadTestPlugin
    {
        LoadTest thisLoadTest;
        const string startPerfmonCmdFileLocation = @"<<pathname>>\CreateResultsDir_Start_Perfmon.CMD";
        const string endPerfmonCmdFileLocation = @"<<pathname>>\PerfMon_Stop_and_CollectResults.CMD";
        public void Initialize(LoadTest loadTest)
        {
            thisLoadTest = loadTest;
            thisLoadTest.LoadTestStarting += new EventHandler(LoadTestStarting);
            thisLoadTest.LoadTestFinished += new
                EventHandler(LoadTestFinished);
        }
        void LoadTestStarting(object sender, EventArgs e)
        {
            ProcessStartInfo procInfoCreateResultsDirectoryStartPerfmon = new ProcessStartInfo()
            {
                FileName = startPerfmonCmdFileLocation,
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = false
            };
            using (Process processResultsDirectory = new Process() { StartInfo = procInfoCreateResultsDirectoryStartPerfmon })
            {
                processResultsDirectory.Start();
                processResultsDirectory.WaitForExit();
            }
        }
        void LoadTestFinished(object sender, EventArgs e)
        {
             ProcessStartInfo procInfoStopCounterAndCollectResults = new ProcessStartInfo()
            {
                FileName = endPerfmonCmdFileLocation,
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = false
            };
             using (Process processResultsDirectory = new Process() { StartInfo = procInfoStopCounterAndCollectResults })
             {
                 processResultsDirectory.Start();
                 processResultsDirectory.WaitForExit();
             }
        }
    }
}