<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">GrayCode</title><subtitle type="html">Fast Code/Slow Code - Good Code/Bad Code - Let's do some Gray Code</subtitle><id>http://blogs.msdn.com/graycode/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/graycode/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/graycode/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2005-04-21T19:10:00Z</updated><entry><title>What I did in the summer of '91 - The debugger as a sampling profiler</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/graycode/archive/2005/12/08/DebuggerAsProfiler.aspx" /><id>http://blogs.msdn.com/graycode/archive/2005/12/08/DebuggerAsProfiler.aspx</id><published>2005-12-08T20:50:00Z</published><updated>2005-12-08T20:50:00Z</updated><content type="html">&lt;P&gt;While speaking with some of our internal performance engineers the other day, I was reminded of the method I’ve been using to explain sampling profiling to customers.&amp;nbsp; Since I don’t think it has made it into any of the official documentation or blogs, I’ll take a moment or two to share it with a broader audience.&lt;/P&gt;
&lt;P&gt;Back in the day before the Visual Studio Team Systems profiler (and even before other sampling profilers were available), there were already performance problems – go figure.&amp;nbsp; My personal experience with an extreme example of this was in the early nineties when I was working on CodeView.&amp;nbsp; CodeView was the standalone COW (Character Oriented Windows) debugger that we shipped up until most of its functionality was incorporated into Developer Studio. Some of our internal customers were breathing down our necks because it took a half hour to load their application into CodeView to debug it when they had symbols available for all components.&amp;nbsp; As a stop-gap they were creating hybrid builds that only had debug information for certain modules, but they were definitely &lt;STRONG&gt;not&lt;/STRONG&gt; happy with that solution!&lt;/P&gt;
&lt;P&gt;So I knew up front that there was some problem with symbol load time, but how do I figure out what?&amp;nbsp; I used what was a pretty common technique in the day which was to run the scenario under the debugger, break a number of times and take a look at the call stack.&amp;nbsp; This doesn’t always work, but in this extreme it lead me right to the main culprit.&amp;nbsp; We were reading the entire symbol table, doing individual allocations for each symbol and doing a transformation from the file-formatted symbol into an internal format for the symbol.&amp;nbsp; So my random call stacks were consistently showing that we were spending lots of time in the code that did this allocation and transformation.&amp;nbsp; Reworking the code so that the entire debug section could be loaded as a single block and doing a quick run for some fixups gave me a 10x performance gain with not too much work.&lt;/P&gt;
&lt;P&gt;Now while this may be a somewhat interesting historical note, you may ask what this has to do with sampling based profiling. With two pretty important differences, the above technique with the debugger is a poor man’s version of a sampling profiler.&amp;nbsp; In the sampling profiler, every time a specific event occurs we walk the call stack of the current thread and put this information in our log file.&amp;nbsp; When we later analyze the file, we aggregate the results to give you a picture of what your program was doing the most when these events occurred.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Voila – we’ve just re-invented an ancient technique for tracking down performance problems!&amp;nbsp; But now let’s take a closer look at how the two techniques are different.&lt;/P&gt;
&lt;P&gt;The first major difference is that we can gather and aggregate a lot more data than you can when breaking your program randomly in the debugger, so issues that are less extreme than the example I cited above can be detected.&amp;nbsp; Along with that comes the ability to do more sophisticated analysis than the flat set of call stacks that you would see in the debugger.&amp;nbsp; This is the justification for having a sampling based profiler in the first place.&amp;nbsp; I recommend that you take a look at some of the other VSTS profiler team’s blogs for loads of additional info.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The second major difference is something that was pointed out by the performance engineers the other day, and puts a different spin on a recurring issue with sampling profiling.&amp;nbsp; When you break in the debugger it stops all threads and you can take a look at all of their call stacks.&amp;nbsp; With our implementation of a sampling profiler, we only report the call stacks of the thread that was active at the time our event occurred.&amp;nbsp; Why is this a significant difference, you may ask?&amp;nbsp; Because a thread that is sitting in WaitForSingleObject or any other system level synchronization call (this counts managed locks as well) won’t ever be sampled.&amp;nbsp; In our sampling profiler, we do a good job of showing you where you use the most of a particular resource (for instance processor usage in the default case), but we don’t do anything to show you when the problem is multiple threads contending over the same resource.&amp;nbsp; In the debugger you can look at the call stacks of the inactive threads and see that some particular thread is sitting in WaitForSingleObject much more often that you expect.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Now before you run out and start using the debugger as your primary tool for identifying resource contention issues, let me tell you that we do have a completely different solution to help you identify resource contention issues.&amp;nbsp; This is one of the things that the instrumentation based flavor of our profiler does pretty well, and I’ll follow up with a blog about that sometime in the near future.&lt;/P&gt;
&lt;P&gt;--dwg&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=501644" width="1" height="1"&gt;</content><author><name>dwgray</name><uri>http://blogs.msdn.com/members/dwgray.aspx</uri></author><category term="profiler" scheme="http://blogs.msdn.com/graycode/archive/tags/profiler/default.aspx" /><category term="performance" scheme="http://blogs.msdn.com/graycode/archive/tags/performance/default.aspx" /></entry><entry><title>ASP.NET Profiling - Off Road</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/graycode/archive/2005/05/10/AspNetOffRoadProfiling.aspx" /><id>http://blogs.msdn.com/graycode/archive/2005/05/10/AspNetOffRoadProfiling.aspx</id><published>2005-05-10T23:54:00Z</published><updated>2005-05-10T23:54:00Z</updated><content type="html">&lt;P&gt;I just posted an article about profiling ASP.NET applications 'Off Road'.&lt;/P&gt;
&lt;P&gt;&lt;a href="http://blogs.msdn.com/graycode/articles/AspNetOffRoadProfilingArticle.aspx"&gt;http://blogs.msdn.com/graycode/articles/AspNetOffRoadProfilingArticle.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;May it provide many hours of pleasure for those who enjoy digging around the edges of the 'mainline' experience.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=416118" width="1" height="1"&gt;</content><author><name>dwgray</name><uri>http://blogs.msdn.com/members/dwgray.aspx</uri></author><category term="profiler" scheme="http://blogs.msdn.com/graycode/archive/tags/profiler/default.aspx" /><category term="asp.net" scheme="http://blogs.msdn.com/graycode/archive/tags/asp.net/default.aspx" /><category term="off-roading" scheme="http://blogs.msdn.com/graycode/archive/tags/off-roading/default.aspx" /></entry><entry><title>Boomerang</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/graycode/archive/2005/04/21/David.aspx" /><id>http://blogs.msdn.com/graycode/archive/2005/04/21/David.aspx</id><published>2005-04-22T04:10:00Z</published><updated>2005-04-22T04:10:00Z</updated><content type="html">&lt;P&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;HE'S BACK&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;After spending a number of years OOM (Outside Of Microsoft) I was seduced by the promise of working on a profiler.&amp;nbsp; Since I occasionally feel the need for speed, I couldn’t resist and returned to Microsoft in the fall of 2003.&amp;nbsp; I was a debugger developer during a good part of my initial stint at Microsoft, so this seemed like a good fit.&amp;nbsp; At some later date I may blog about why the challenges of writing profilers and debuggers are more different that one might assume.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;We’ve just shipped Beta 2 of Visual Studio Team Systems so it’s public now and I can start talking about how to use the thing.&amp;nbsp; We’ve done a lot of work to get an easily usable, “press the button and go” type of experience for the average developer or performance engineer working in our core scenarios.&amp;nbsp; (Take a look at &lt;a href="http://blogs.msdn.com/ianhu"&gt;IanHu’s blog&lt;/A&gt; for some good walkthroughs).&amp;nbsp; But like the debugger, when you really need a profiler, you really need a profiler.&amp;nbsp; If you happen to be off the beaten track enough that our user friendly ‘easy’ solution doesn’t work, you still need to grab that data and find out why you app is running so dang slow.&amp;nbsp; You won’t take no for an answer (at least I wouldn’t).&amp;nbsp; For those of you that find yourself in these situations we’re planning a series of “Off-Road” posts.&amp;nbsp; &lt;a href="http://blogs.msdn.com/ms_joc"&gt;John Cunningham &lt;/A&gt;has posted the &lt;a href="http://blogs.msdn.com/ms_joc/articles/406608.aspx"&gt;first of this series&lt;/A&gt; and I’m busily working on one of these little gems myself.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;So stay tuned for some off-road profiling and other fast and fun GrayCode.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=410599" width="1" height="1"&gt;</content><author><name>dwgray</name><uri>http://blogs.msdn.com/members/dwgray.aspx</uri></author><category term="noise" scheme="http://blogs.msdn.com/graycode/archive/tags/noise/default.aspx" /></entry></feed>