Debug Analyzer.NET - Analysis Intelligent Debugger http://debuganalyzer.net/ http://www.rssboard.org/rss-specification BlogEngine.NET 1.6.0.5 en-GB http://debuganalyzer.net/opml.axd http://www.dotnetblogengine.net/syndication.axd Sukesh Debug Analyzer.NET 0.000000 0.000000 Debug Analyzer: Bringing back the dead! <p>Debugging memory dumps are also known as Post-mortem debugging and the reason for this is simple. Memory dumps are just a snapshot of the process memory (in case of usermode dumps) and not live at the time of debugging thus the term 'post-mortem'.</p> <p>While working on Debug Analyzer.NET I was hunting for coolness, things which were never done before and thought it would be ultra-cool to give life to objects in the dumps. <br />Let me explain! Assume that you have a DateTime field for a class and available in the memory dumps. You would like to do some comparison or manipulation of that object, like we do with live objects.</p> <p>It would be very useful if we can utilize methods provided by .NET for that type of object to ease manipulation... isn't it? <br />So here it is, the power to give life to objects from the dumps!!!</p> <h4>Let's see a System.DateTime object in Windbg + SOS</h4> <pre class="brush: text;highlight: [2, 10];">[*** Dump one of the System.DateTime object ***] 0:013&gt; !do 0707e980 Name: System.DateTime MethodTable: 0f310010 EEClass: 0f3085d8 Size: 16(0x10) bytes (C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll) Fields: MT Field Offset Type VT Attr Value Name 0f344060 40000f4 4 System.UInt64 1 instance 633988790520830000 dateData </pre> <p>&nbsp;</p> <h4>Now give life to the dead object using Debug Analyzer.NET !!!</h4> <pre class="brush: csharp;">string someAddress = "0707e980"; // ConvertTo is a generic method which supports a number of different .NET types DateTime datetime = someAddress.ToClrObject().ConvertTo&lt;System.DateTime&gt;(); // You can also do this since ToClrObject is an Extension method for string type DateTime datetime = "0707e980".ToClrObject().ConvertTo&lt;System.DateTime&gt;(); </pre> <p>&nbsp;</p> <h4>Let's see the advantage... the object is alive which means you have all the methods and properties .NET provides for that object type.</h4> <p><img src="/image/2011/1/DateTime-ConvertTo.png" alt="System.DateTime ConvertTo" /></p> <p>Check method ClrExtMethods.ConvertTo in help for supported types. More support for types coming sooooon...</p> <p style="color:#0000ff"><em>Note: Please use comments to suggest the types you think would be useful!</em></p> http://debuganalyzer.net/post/Debug-Analyzer-Bringing-back-the-dead.aspx Sukesh http://debuganalyzer.net/post/Debug-Analyzer-Bringing-back-the-dead.aspx#comment http://debuganalyzer.net/post.aspx?id=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 Sat, 29 Jan 2011 04:13:00 -0500 Analysis Scenario Snippets Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 0 http://debuganalyzer.net/trackback.axd?id=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 http://debuganalyzer.net/post/Debug-Analyzer-Bringing-back-the-dead.aspx#comment http://debuganalyzer.net/syndication.axd?post=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 Scenario: How to find logged-in users with ASP.NET forms based authentication <p>Lets talk about a scenario here and take a look at manual way to find what we need with windbg + sos.<br />We will then see how we can automate this using Debug Analyzer.NET Analysis. <br />For learning pleasure and reuse, attached code snippet can be saved in snippets folder and used with Instant Analyzer feature too.</p> <p><strong>Scenario</strong><br />An intranet ASP.NET application becomes very slow during off-peak hours. Since it's during off peak hours we can guess that it might not be due to heavy load.<br />There are several different tools and ways to troubleshoot this issue using profiling tools etc... But since running profiler etc might not be a great idea on production servers, we will use memory dumps to get the users who are using the application and then check what they are doing during that specific time of the issue.<br /><em>(Maybe running a slow moving, large report?)</em></p> <h4>Let us see how this can be done in Windbg + SOS</h4> <pre class="brush: text;highlight: [2, 35, 44, 52, 58];">[*** Dump all the objects of type System.Web.Security.FormsAuthenticationTicket ***] 0:034&gt; !dumpheap -type System.Web.Security.FormsAuthenticationTicket ------------------------------ Heap 0 Address MT Size 10525a48 663b3f14 44 107f84f4 663b3f14 44 total 2 objects ------------------------------ Heap 1 Address MT Size 1454e4c0 663b3f14 44 145c0a00 663b3f14 44 14a04878 663b3f14 44 total 3 objects ------------------------------ Heap 2 Address MT Size 184fc27c 663b3f14 44 total 1 objects ------------------------------ Heap 3 Address MT Size 1c43ca44 663b3f14 44 1c511cfc 663b3f14 44 total 2 objects ------------------------------ total 8 objects Statistics: MT Count TotalSize Class Name 663b3f14 8 352 System.Web.Security.FormsAuthenticationTicket Total 8 objects [*** Let us dump out one of those objects ***] 0:034&gt; !do 107f84f4 Name: System.Web.Security.FormsAuthenticationTicket MethodTable: 663b3f14 EEClass: 663b3e50 Size: 44(0x2c) bytes (C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll) Fields: MT Field Offset Type VT Attr Value Name 79102290 4001e61 10 System.Int32 1 instance 2 _Version 790fd8c4 4001e62 4 System.String 0 instance 107f8520 _Name 7910c878 4001e63 18 System.DateTime 1 instance 107f850c _Expiration 7910c878 4001e64 20 System.DateTime 1 instance 107f8514 _IssueDate 7910be50 4001e65 14 System.Boolean 1 instance 0 _IsPersistent 790fd8c4 4001e66 8 System.String 0 instance 107f853c _UserData 790fd8c4 4001e67 c System.String 0 instance 107f8550 _CookiePath [*** Now dumping out the field name called '_Name' ***] 0:034&gt; !do 107f8520 Name: System.String MethodTable: 790fd8c4 EEClass: 790fd824 Size: 28(0x1c) bytes (C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll) String: USER1 &lt;=== Heyaa!!! we got the user name!!! Fields: MT Field Offset Type VT Attr Value Name 79102290 4000096 4 System.Int32 1 instance 6 m_arrayLength 79102290 4000097 8 System.Int32 1 instance 5 m_stringLength 790ff328 4000098 c System.Char 1 instance 55 m_firstChar 790fd8c4 4000099 10 System.String 0 shared static Empty &gt;&gt; Domain:Value 000f0050:790d884c 00114ca8:790d884c &lt;&lt; 7912dd40 400009a 14 System.Char[] 0 shared static WhitespaceChars &gt;&gt; Domain:Value 000f0050:142d03f4 00114ca8:142d456c &lt;&lt; </pre> <p><span style="color:#0000ff">Repeat the commands in line # 35 and 52 (8 times) for each object from the 1st command result.</span></p> <h4>Now lets see how this can be done in Debug Analyzer.NET (automation and reuse with 4 lines of code)</h4> <pre class="brush: csharp;">// Write a heading WriteHeadLine("Forms Authentication Users"); //Get all objects of type 'System.Web.Security.FormsAuthenticationTicket' IEnumerable&lt;ClrObject&gt; objs = Analyzer.CLR.GetClrObjectsByType("System.Web.Security.FormsAuthenticationTicket"); //Enumerate through all Objects of type 'System.Web.Security.FormsAuthenticationTicket' foreach (ClrObject clrobj in objs) { ClrObject cobj = clrobj.ClrObjectFieldCollection["_Name"].ToClrObject(); WriteHtmlLine("User Name : {0}", cobj.ToString()); //Shows the string value using Extension Method } </pre> <p>See the result below (all Disney characters on your intranet?)<br /><img src="/image/2011/1/form-auth-results.png" alt="" /></p> <h4>Tip: How many lines of code&nbsp;are needed to show the ClrObject in !do format?</h4> <p><span>Answer is 1 line of code!!! (write the following line of code, inside the foreach loop).</span></p> <pre class="brush: csharp">WriteHTMLLine(clrobj.ToHtml()); </pre> <p>How cool is that? !!! <img title="Cool" src="/editors/tiny_mce3/plugins/emotions/img/smiley-cool.gif" border="0" alt="Cool" /></p> <p>(Use right-click and Save Target As...)<br />Download <a href="/file/2011/1/FormsAuthUsers.cs">FormsAuthUsers.cs (850.00 bytes)</a></p> http://debuganalyzer.net/post/Scenario-How-to-find-logged-in-users-with-ASPNET-forms-based-authentication.aspx Sukesh http://debuganalyzer.net/post/Scenario-How-to-find-logged-in-users-with-ASPNET-forms-based-authentication.aspx#comment http://debuganalyzer.net/post.aspx?id=57597617-9f77-47d5-b853-f8d010d6cc0d Fri, 21 Jan 2011 03:52:00 -0500 Analysis Snippets Scenario Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=57597617-9f77-47d5-b853-f8d010d6cc0d 0 http://debuganalyzer.net/trackback.axd?id=57597617-9f77-47d5-b853-f8d010d6cc0d http://debuganalyzer.net/post/Scenario-How-to-find-logged-in-users-with-ASPNET-forms-based-authentication.aspx#comment http://debuganalyzer.net/syndication.axd?post=57597617-9f77-47d5-b853-f8d010d6cc0d How Visualizer works? <p>Often times complex analysis becomes&nbsp;difficult to digest in textual format. That's where power of Visualization shines.<br />Although the feature is not ready for general use for writing Visualizers, I would like to give you a sneak peek at powerful Visualizer feature part of Debug Analyzer.NET!<br /><em>(Keep in mind, Visualizer does not always mean graph)</em></p> <p>Let us see a screenshot of the Visualizer and then the amount of code required to create this!</p> <p><img src="/image/2011/1/Visualizer.png" alt="" /></p> <p>&nbsp;</p> <h4>Lets see the code required to create the above Visualizer!</h4> <pre class="brush: csharp;">// Data Binding code for the Graph - Top 5 items of ClrHeap sorted descending on TotalSize chartSurface.DataSource = Analyzer.CLR.ClrHeapCollection.OrderByDescending(h =&gt; h.TotalSize).Take(5); chartSurface.DataBind(); // Formatting point labels with friendly values like Bytes/KBytes etc... foreach (DataPoint p in chartSurface.Series[0].Points) { p.Label = p.YValues[0].ToByteString(); } </pre> <p>I'm excited about the capabilities Visualization can bring about. Hope to finish the implementation of this feature sooooooon!<br />See what you can achieve with just 2 lines of code!!! <img title="Cool" src="/editors/tiny_mce3/plugins/emotions/img/smiley-cool.gif" border="0" alt="Cool" /></p> http://debuganalyzer.net/post/How-Visualizer-works.aspx Sukesh http://debuganalyzer.net/post/How-Visualizer-works.aspx#comment http://debuganalyzer.net/post.aspx?id=d6f58675-6ce2-4ac1-a64e-9387f1eeb5bf Fri, 21 Jan 2011 01:13:00 -0500 Analysis Visualizer Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=d6f58675-6ce2-4ac1-a64e-9387f1eeb5bf 1 http://debuganalyzer.net/trackback.axd?id=d6f58675-6ce2-4ac1-a64e-9387f1eeb5bf http://debuganalyzer.net/post/How-Visualizer-works.aspx#comment http://debuganalyzer.net/syndication.axd?post=d6f58675-6ce2-4ac1-a64e-9387f1eeb5bf Video Tutorial <p>Let us see different features in action in <span style="color:#ff0000"><strong>5 min</strong> to fame style</span> screencast...!</p> <p>&nbsp;</p> <div>[vimeo:18995935]</div> http://debuganalyzer.net/post/Video-Tutorial.aspx Sukesh http://debuganalyzer.net/post/Video-Tutorial.aspx#comment http://debuganalyzer.net/post.aspx?id=d934b5fb-36d1-4811-9db9-05293c3013b2 Sun, 02 Jan 2011 04:13:00 -0500 Analysis Debug Analyzer Learn Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=d934b5fb-36d1-4811-9db9-05293c3013b2 0 http://debuganalyzer.net/trackback.axd?id=d934b5fb-36d1-4811-9db9-05293c3013b2 http://debuganalyzer.net/post/Video-Tutorial.aspx#comment http://debuganalyzer.net/syndication.axd?post=d934b5fb-36d1-4811-9db9-05293c3013b2 How Learn Mode Works? <p>One of the core idea behind Debug Analyzer.NET is to aid in learning Debugging and also about the issues it detects.</p> <p>Learn mode is a way for the analysis results to provide articles or other resource links which would help in understanding the issue better and also get guidance on how to avoid such issues in future.<br />Let us see how it looks like in a sample report.</p> <p><img style="border: 1px solid black;" src="/image/2011/1/LearnMode-i.png" alt="" /></p> <p>The icon <img src="/image/2011/1/the-i.png" alt="" />&nbsp;is a clickable link to resource article related to the issue. In this case it's the result of the following code in the analysis plug</p> <pre class="brush: csharp;">WriteRecommendation(ResultSeverity.Error, "You have hit a performance bottle-neck related to Throttling [LM60001] " + (capacity == 16 ? " (due to very low default value on .NET 3.0)" : ""), "Please change the values of maxConcurrentCalls as per suggestion"); </pre> <p>&nbsp;</p> <h4>What are the different formats for Learn Mode articles ?</h4> <pre class="brush: text;">Learn Mode Articles - [LM&lt;learnId&gt;] eg. [LM50000] Microsoft KB - [KB&lt;articleId&gt;] eg. [KB123456] Microsoft Bulletins - [&lt;bulletinId&gt;] eg. [MS10-049] </pre> <p>&nbsp;</p> <h4>How to get the list of Learn Mode Articles?</h4> <p><strong>http://go.debuganalyzer.net</strong></p> <p><img style="border: 1px solid black;" src="/image/2011/1/go-da.png" alt="" /></p> http://debuganalyzer.net/post/How-Learn-Mode-Works.aspx Sukesh http://debuganalyzer.net/post/How-Learn-Mode-Works.aspx#comment http://debuganalyzer.net/post.aspx?id=72950f74-0875-4509-94c1-d7a336b3ecd1 Sun, 02 Jan 2011 03:13:00 -0500 Analysis Debug Analyzer Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=72950f74-0875-4509-94c1-d7a336b3ecd1 0 http://debuganalyzer.net/trackback.axd?id=72950f74-0875-4509-94c1-d7a336b3ecd1 http://debuganalyzer.net/post/How-Learn-Mode-Works.aspx#comment http://debuganalyzer.net/syndication.axd?post=72950f74-0875-4509-94c1-d7a336b3ecd1 How Instant Analyzer works? <p>Instant Analyzer is more like SQL Query Analyzer, you write your analysis and hit F5 ("Compile &amp; Execute")&nbsp;and it shows the results in the window below.<br />You can also save and load snippets, which&nbsp;are saved and kept under the 'snippets' folder. The 2nd icon for loading and 3rd icon for saving.</p> <p>The following things happen when you hit F5 or "Compile &amp; Execute"</p> <ul> <li>Complete&nbsp;Analysis Plug source is generated&nbsp;by merging the source&nbsp;in the Code Editor&nbsp;below</li> <li>The Analysis Plug is compiled (C# for now) to generate an in-memory Analysis Plug (assembly)</li> <li>Plug Framework evaluates the Analysis Plug to get the Attributes</li> <li>In-memory Plug is then instantiated and Invoked&nbsp;by the Debug Analyzer Engine</li> <li>Debug Analyzer Engine invokes the Data Access Component for the relevant Data</li> <li>Uses the Debugger to get the required data from memory dump&nbsp;requested by the Plug</li> <li>Executes the Entry-point function of the Plug and generates the HTML report content</li> <li>Debug Analyzer Engine gives back the HTML report content</li> <li>Report window at the bottom, shows the HTML report content</li> </ul> <p>Below&nbsp;screenshot shows powerful reporting capability with Graph to display Top 5 .NET Heaps details.<br /><img src="/image/2011/1/InstantAnalyzer-HeapGraph.png" alt="" /></p> <p>&nbsp;</p> <p>Below screenshot shows powerful Analysis capabilities using <span style="color:#0000ff">.NET Lambda expression syntax</span><br /><img src="/image/2011/1/InstantAnalyzer-HeapGraph1.png" alt="" /></p> <p>The above snippets are already included in the download.</p> <p>VB.NET support and <span style="color:#0000ff">'Compile and Publish'</span> option coming soon... <br /><span style="color:#0000ff">'Compile and Publish'</span> option would allow you to convert snippet into Analysis Plug directly with the click of a button.</p> http://debuganalyzer.net/post/InstantAnalyzer.aspx Sukesh http://debuganalyzer.net/post/InstantAnalyzer.aspx#comment http://debuganalyzer.net/post.aspx?id=5a2c24db-e55d-465a-9cab-b25e06e06d33 Sun, 02 Jan 2011 02:13:00 -0500 Analysis Debug Analyzer Snippets Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=5a2c24db-e55d-465a-9cab-b25e06e06d33 0 http://debuganalyzer.net/trackback.axd?id=5a2c24db-e55d-465a-9cab-b25e06e06d33 http://debuganalyzer.net/post/InstantAnalyzer.aspx#comment http://debuganalyzer.net/syndication.axd?post=5a2c24db-e55d-465a-9cab-b25e06e06d33 Hello World Analysis Plug <p>A lot of work was done to keep simplicity and zero learning curve for writing Analysis Plugs. Steps to create a Hello World Plug mentioned below</p> <ul> <li>Using Visual Studio or Visual Studio Express create a 'Class Library' project </li> <li>Add reference to Debug.Analyzer.API </li> <li>Inherit the Class from AnalysisPlug </li> <li>Override the method called RunAnalysis() </li> <li>Build the DLL and copy to 'Analysis' folder </li> <li>Add to any Analysis Template! </li> </ul> <!-- code snippet --> <pre class="brush: csharp;">// *** Hello World Analysis Plug *** // using DebugAnalyzer.ObjectModel; namespace Analysis.Sample { public class SamplePlug : AnalysisPlug { public override void RunAnalysis() { // Begin Report and specify Title for Report Island BeginReport("Hello World!"); // Normal report line using fixed width font WriteDataLine("This is in Fixed width Font!"); // Add blank line in the report WriteBlankLine(); // Add Bold line for headings WriteHeadLine("Drawing Graph has become easy as well..."); // Add Graph with color, percentage and label WriteGraphLine(GraphColors.LightGreen, 70, "System.String - 70%"); WriteGraphLine(GraphColors.Orange, 50, "System.Byte[] - 50%"); // Adding HTML content in the report WriteHtmlLine("Testing for HTML content inline like &lt;b&gt;bold&lt;/b&gt; &lt;i&gt;italics&lt;/i&gt; &lt;u&gt;underline&lt;/u&gt; words"); // Write Recommendation WriteRecommendation(ResultSeverity.Error, "Here goes the description for the issue...", "Here goes the recommendation for fixing the issue..."); EndReport(); } } } </pre> <!-- code snippet --> <p>This is a sample plug to show the different reporting functions available. <span style="#0000ff">Keep in mind no analysis is done in this Plug!</span></p> <p><img src="/image/2011/1/HelloWorld-AnalysisPlug.png" alt="" /><br />Above screenshot shows how the Report looks like for the above Analysis code.<br />Every Analysis Plug has&nbsp;it's own&nbsp;analysis container called 'Report Island'.</p> <p>&nbsp;</p> <h4>How to change Author Name in the Analysis Plug 'Report Island' to get credit for your own Analysis Plug?</h4> <p>Author Information comes from Analysis Plug's assembly attribute called 'Company'. You can get to this from Project properties (see screenshots below)</p> <p><img src="/image/2011/1/PlugCredits-App.png" alt="" /><br />Above screenshot shows Project properties</p> <p><img src="/image/2011/1/PlugCredits.png" alt="" /><br />Above screenshot shows Assembly Information window and where you can set Author details.</p> <p>&nbsp;</p> http://debuganalyzer.net/post/Hello-World-Analysis-Plug.aspx Sukesh http://debuganalyzer.net/post/Hello-World-Analysis-Plug.aspx#comment http://debuganalyzer.net/post.aspx?id=b70f24af-cd0f-4909-a24a-2aa64dafaf3a Sun, 02 Jan 2011 01:31:00 -0500 Analysis Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=b70f24af-cd0f-4909-a24a-2aa64dafaf3a 204 http://debuganalyzer.net/trackback.axd?id=b70f24af-cd0f-4909-a24a-2aa64dafaf3a http://debuganalyzer.net/post/Hello-World-Analysis-Plug.aspx#comment http://debuganalyzer.net/syndication.axd?post=b70f24af-cd0f-4909-a24a-2aa64dafaf3a How to Run Analysis? <p>One of the core features of Debug Analyzer.NET is to run Analysis on the memory dumps and provide a friendly report to show you the details in dumps, issues detected and recommendations for resolving those issues. This is accomplished by using a modular approach using Analysis Plugs. The Analysis Plugs are then grouped into what are called "Analysis Templates" according to the scenarios or issues we are troubleshooting.</p> <p>Let us see how the "Analysis Templates" are shown on the left side of the main screen.</p> <p><img style="border: 1px solid black;" src="/image/2011/1/AnalysisTemplateSelection.png" alt="" /></p> <p><span style="color:#0000ff">How do you Run Analysis?</span><br />So when you want to run analysis, you need to select a memory dump and select one of these "Analysis Templates" and click on "Run Analysis". <br />Each sub element shown under the Template Name (highlighted in blue) are individual Analysis Plugs. <br />Please see the article titled "Hello World Analysis Plug" on the&nbsp;right&nbsp;for learning to write your Analysis Plugs.</p> <p><span style="color:#0000ff">How do you create Analysis Template?</span><br />From the top menu click Tools &gt; Analysis Templates. You can get the following screen where you can edit your Templates.</p> <p><img src="/image/2011/1/AnalysisTemplates.png" alt="" /></p> <p>&nbsp;</p> http://debuganalyzer.net/post/How-to-Run-Analysis.aspx Sukesh http://debuganalyzer.net/post/How-to-Run-Analysis.aspx#comment http://debuganalyzer.net/post.aspx?id=574acb54-7e8e-4677-b631-e55dc18d85ef Sat, 01 Jan 2011 02:13:00 -0500 Analysis Debug Analyzer Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=574acb54-7e8e-4677-b631-e55dc18d85ef 0 http://debuganalyzer.net/trackback.axd?id=574acb54-7e8e-4677-b631-e55dc18d85ef http://debuganalyzer.net/post/How-to-Run-Analysis.aspx#comment http://debuganalyzer.net/syndication.axd?post=574acb54-7e8e-4677-b631-e55dc18d85ef