<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Southworks Blogs &#187; Performance Testing</title>
	<atom:link href="http://blogs.southworks.net/category/performance-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.southworks.net</link>
	<description>Powered by Southworks</description>
	<lastBuildDate>Tue, 14 May 2013 19:36:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Visual Studio Load Testing: Optimizing Performance Lab Time</title>
		<link>http://blogs.southworks.net/gabrielsz/2009/06/04/visual-studio-load-testing-optimizing-performance-lab-time/</link>
		<comments>http://blogs.southworks.net/gabrielsz/2009/06/04/visual-studio-load-testing-optimizing-performance-lab-time/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 20:00:35 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Load Testing]]></category>
		<category><![CDATA[Performance Testing]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://22.43</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gabrielsz/2009/06/04/visual-studio-load-testing-optimizing-performance-lab-time/" class="more-link">read more<img src="http://blogs.southworks.net/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>When modeling a Web Application&#8217;s responsiveness with an increasing User Load, you usually configure a Load Test Mix with a Step based Load Pattern, run the test until the Response Time goes above a certain response time, and then manually stop the test. This requires some of your time monitoring the test progress and having to intervene to stop the test.</p>
<p> <img src="http://blogs.southworks.net/gabrielsz/files/2009/06/image.png" border="0" alt="image" width="640" height="340" /></p>
<p>Wouldn&#8217;t be nice if this was automated? Fortunately this can be easily achieved through the use of a custom Load Test Plugin (ILoadTestPlugin) and a configured Threshold. (Custom load test plugins were improved in VS2008SP1 and are also available in VS 2010, used in the creation of this blog post.) This will save you (the Tester) the trouble of having to manually monitor the load test and stop it when the threshold is exceeded.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/06/image1.png" border="0" alt="image" width="640" height="106" /></p>
<p>Let&#8217;s take a look at how this can be implemented in code:</p>
<h2>Creating a Load Test Plug-in that stops the Load Test when a threshold is exceeded</h2>
<p>Load Test Plug-ins allow custom code to be executed when a load test starts, ends, or when a threshold was exceeded, among other events. We&#8217;ll create a Custom Load Test Plug-in that attaches itself to the <strong>ThresholdExceeded</strong> event and stops the test.</p>
<ol>
<li>Create a Class Library project.</li>
<li>Add a reference to the <strong>Microsoft.VisualStudio.QualityTools.LoadTestFramework</strong> assembly.</li>
<li>Create a class named <strong>CustomLoadTestPlugin</strong> and complete it with the following code (VS2008 and VS2010):
<p><!-- begin code paste --></p>
<p class="MsoNormal">
<pre><span style="color: blue">using </span>System;
<span style="color: blue">using </span>Microsoft.VisualStudio.TestTools.LoadTesting;

<span style="color: blue">public class </span><span style="color: #2b91af">CustomLoadTestPlugin </span>: ILoadTestPlugin
{
    <span style="color: blue">private </span>LoadTest test;

    <span style="color: blue">public void </span>Initialize(LoadTest loadTest)
    {
        <span style="color: blue">if </span>(loadTest == <span style="color: blue">null</span>)
        {
            <span style="color: blue">throw new </span><span style="color: #2b91af">ArgumentNullException</span>(<span style="color: #a31515">&quot;loadTest&quot;</span>);
        }

        <span style="color: blue">this</span>.test = loadTest;

        loadTest.ThresholdExceeded += <span style="color: blue">new </span><span style="color: #2b91af">EventHandler</span>&lt;ThresholdExceededEventArgs&gt;(OnThresholdExceeded);
    }

    <span style="color: blue">void </span>OnThresholdExceeded(<span style="color: blue">object </span>sender, ThresholdExceededEventArgs e)
    {
        <span style="color: blue">if </span>(e.ThresholdResult == ThresholdRuleResult.Critical
            &amp;&amp; e.CounterValue != <span style="color: blue">null
            </span>&amp;&amp; e.CounterValue.CounterName == <span style="color: #a31515">&quot;Avg. Test Time&quot;</span>)
        {
            <span style="color: blue">this</span>.test.Scenarios[0].CurrentLoad = 0;
            <span style="color: blue">this</span>.test.Abort();
        }
    }
}</pre>
<p><!-- end code paste -->
</li>
<li>Build the Load Test Plug-in solution</li>
</ol>
<p><em>Note: If you&#8217;d like to get more information about creating a Load Test Plug-in, see the following </em><a href="http://msdn.microsoft.com/en-us/library/ms243153.aspx"><em>link</em></a><em>.</em></p>
<h2>Using the Custom Load Test Plug-in</h2>
<ol>
<li>Open the Load Test Configuration (.loadtest) you&#8217;d like to modify.</li>
<li>Using Solution Explorer, add a reference to the Load Test Plug-In (either to the Load Test Plug-In project or to the compiled assembly).</li>
<li>Add a Compare Constant threshold rule on the Avg. Test Time counter. To do this, Expand the <strong>Counter Sets</strong> | <strong>LoadTest</strong> | <strong>Counter Categories</strong> | <strong>LoadTest:Test</strong> element, right click on the <strong>Avg. Test Time</strong> counter and select <strong>Add Threshold Rule</strong>.<img src="http://blogs.southworks.net/gabrielsz/files/2009/06/image2.png" border="0" alt="image" width="395" height="459" /></li>
<li>Add the Load Test Plug-In to the test run. To do this, right click on the Load Test Name (the top element) and choose Add Load Test Plug-in. On the window that opens, select CustomLoadTestPlugin and hit OK.
<p><img src="http://blogs.southworks.net/gabrielsz/files/2009/06/image3.png" border="0" alt="image" width="192" height="103" /></li>
<li>That&#8217;s it, you should now run the Load Test and see if it stops after your configured threshold.</li>
</ol>
<p>Hope this saves you time. If you&#8217;d like to learn more ways to extend Visual Studio Load Testing, check <a href="http://blogs.msdn.com/billbar/">Bill Barnett&#8217;s</a>  <a href="http://blogs.msdn.com/billbar/articles/533216.aspx">article</a>.</p>
<h2>Related Articles</h2>
<ul>
<li><a title="Permanent Link to Visual Studio 2010- How to create a Performance Data Collector" href="http://blogs.southworks.net/gabrielsz/2009/05/21/visual-studio-2010-how-to-create-a-performance-data-collector/">Visual Studio 2010- How to create a Performance Data Collector</a></li>
</ul>
<p>Happy testing!</p>
<div id="39136f40-7337-440e-afbb-e5e3f4fafdb6" class="wlWriterEditableSmartContent" style="padding-bottom: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;float: none;padding-top: 0px">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Load+Testing">Load Testing</a>,<a rel="tag" href="http://technorati.com/tags/Performance+Testing">Performance Testing</a>,<a rel="tag" href="http://technorati.com/tags/Visual+Studio">Visual Studio</a></div>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.southworks.net%2fgabrielsz%2f2009%2f06%2f04%2fvisual-studio-load-testing-optimizing-performance-lab-time%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.southworks.net%2fgabrielsz%2f2009%2f06%2f04%2fvisual-studio-load-testing-optimizing-performance-lab-time%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010: How to create a Performance Data Collector</title>
		<link>http://blogs.southworks.net/gabrielsz/2009/05/21/visual-studio-2010-how-to-create-a-performance-data-collector/</link>
		<comments>http://blogs.southworks.net/gabrielsz/2009/05/21/visual-studio-2010-how-to-create-a-performance-data-collector/#comments</comments>
		<pubDate>Thu, 21 May 2009 14:39:19 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Data Collector]]></category>
		<category><![CDATA[Performance Collector]]></category>
		<category><![CDATA[Performance Testing]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Visual Studio 2010 Beta 1]]></category>

		<guid isPermaLink="false">http://22.38</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gabrielsz/2009/05/21/visual-studio-2010-how-to-create-a-performance-data-collector/" class="more-link">read more<img src="http://blogs.southworks.net/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s assume you often run Performance Tests and your application outputs a log file that you manually backup on every test run. You can automate the process using a Collector, a new feature that ships with Visual Studio 2010.</p>
<p><strong>Note: </strong>For a great introduction on Data Collectors in Visual Studio 2010 Beta1, please check <a href="http://blogs.msdn.com/amit_chatterjee/archive/2009/03/28/remote-execution-and-data-collection.aspx">Amit&#8217;s blog</a>.</p>
<p>This post is meant to answer the question: <em>How can I create my own Data Collector in Visual Studio 2010? </em></p>
<h1>Steps to create a Performance Collector</h1>
<p>Let&#8217;s create a Performance Collector that generates a log file and copies it to the Test Results folder:</p>
<ol>
<li>Create a Class Library Project (C# 4.0).</li>
<li>Add a reference to <strong>Microsoft.VisualStudio.PerformanceTools.DataCollection</strong> and <strong>Microsoft.VisualStudio.QualityTools.ExecutionCommon</strong>. Both assemblies can be found in the %DevEnvDir%PrivateAssemblies folder, and should only be used for extending Visual Studio.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image.png" border="0" alt="image" width="460" height="134" /></li>
<li>Create a new class. Assign it a name, like CustomLogDataCollector.</li>
<li>Add the following using declarations above the class name.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image1.png" border="0" alt="image" width="457" height="78" /></li>
<li>Make the class inherit from <strong>DataCollector</strong> (<strong>Microsoft.VisualStudio.PerformanceTools.DataCollection</strong> namespace).</li>
<li>Decorate the class name with the <strong>DataCollectorFriendlyName</strong>, <strong>DataCollectorTypeUri</strong> and <strong>DataCollectorDescription</strong> attributes. The Uri needs to be unique for Visual Studio to identify the Collector, it is usually created in a Company/CollectorName/Version hierarchy, as shown below.<br />
<a href="http://blogs.southworks.net/gabrielsz/files/2009/05/image2.png"><img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image-thumb.png" border="0" alt="image" width="473" height="78" /></a></li>
<li>Add a property of type <strong>IDataCollectorSink</strong> and implement the <strong>DoInitialize </strong>method to capture the <strong>IDataCollectorSink</strong> value. An <strong>IDataCollectorSink</strong> allows the Collector to interact with the Test Results folder.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image3.png" border="0" alt="image" width="588" height="159" /></li>
<li>Override the <strong>SessionEnd</strong> method and invoke the IDataCollectionSync&#8217;s <strong>SendFileAsync</strong> method to copy the log file contents into the Test Results folder. In the example below I&#8217;m simulating a log file by creating a HelloWorld.txt file with a log line. It&#8217;s very easy to adapt this to your own environment!<br />
 <img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image4.png" border="0" alt="image" width="495" height="193" /></li>
<li>Build the project. Copy the project&#8217;s DLL into the %DevEnvDir%PrivateAssembliesDataCollectors folder.</li>
</ol>
<p>That&#8217;s it! Now it&#8217;s time to enjoy your first Custom Collector. </p>
<h2>Using the custom Data Collector in your Test Project</h2>
<p>To use the Data Collector for your Test Project you just need to:</p>
<ol>
<li>In Solution Explorer, double click on the &#8220;.testsettings&#8221; file (the project&#8217;s test run configuration) to open the configuration editor.<br />
 <img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image5.png" border="0" alt="image" width="248" height="148" /></li>
<li>Select the <strong>Execution Criteria</strong> configuration from the list on the left. In the Collectors section on the right, scroll down until you see &#8220;Your custom collector1&#8243;. Make sure the <strong>Enabled</strong> checkbox is selected and click <strong>Apply</strong> and then <strong>Close</strong>. <img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image6.png" border="0" alt="image" width="767" height="662" /></li>
<li>Start a Load Test run.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image7.png" border="0" alt="image" width="490" height="179" /></li>
<li>Wait until the Load Test run is completed. On the Test Results window, click the <strong>Test run completed</strong> link.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image8.png" border="0" alt="image" width="519" height="202" /></li>
<li>Verify that there is a file named HelloWorld.txt in the <strong>Collected Files</strong> section, as shown below. Clicking the link will open the file in your configured text editor.<br />
<img src="http://blogs.southworks.net/gabrielsz/files/2009/05/image9.png" border="0" alt="image" width="570" height="272" /></li>
</ol>
<h2>Next steps</h2>
<p>This was a quick introduction on how to create custom Collectors for your Test Projects. Now that you have it working, you can augment it by creating:</p>
<ul>
<li>An installer that copies the DLL file to PrivateAssembliesDataCollectors folder</li>
<li>A class to hold the Collector&#8217;s configuration</li>
<li>A visual editor for the Data Collector&#8217;s options</li>
</ul>
<p>I hope you can find a good use for this, and your feedback is greatly appreciated.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
