DotNetCurry Logo

IntelliTrace: Fast Track to Debug Microsoft .NET Applications in Visual Studio 2010

Posted by: Subodh Sohoni , on 3/24/2010, in Category Visual Studio, VSTS & TFS
Views: 73591
Abstract: IntelliTrace is a new feature that is introduced by Microsoft in Visual Studio 2010 for putting the debugging in the fast track. It will reduce the time taken by debugging an application by reducing the number of debugging passes required to be executed by the developer.
IntelliTrace: Fast Track to Debug Microsoft .NET Applications in Visual Studio 2010
IntelliTrace is a new feature that is introduced by Microsoft in Visual Studio 2010 for putting the debugging in the fast track. It will reduce the time taken by debugging an application by reducing the number of debugging passes required to be executed by the developer.
Traditional debugger allows a developer to set a breakpoint in the code and when the debugger hits that breakpoint, it takes a pause in the execution. At this point, the developer can view the snapshot of the state of the application, including various variables, call stack etc. Debugger also allows the step by step tracing of the application in the forward direction. What it does not allow is to know what has happened earlier during the execution. Some logical error might have happened in the program during earlier execution of some statement which is not traceable. Developer has to stop the debugging, set a breakpoint somewhere earlier in the program and restart the debugging.
IntelliTrace allows all the traditional facilities of the debugger and also has added an ability to trace the application step by step backward till an error that might have happened earlier is found out. In this way now the second or any number of subsequent passes that would have been required in the traditional debugger are avoided. IntelliTrace starts collecting the data as soon as any debugger session has started in Visual Studio 2010. It stores the data that it collects in a file which has an extension of .iTrace and that file can be sent to another user for reviewing a session.
Let us view the details of IntelliTrace with an example. We are creating an interest calculator that is a Windows Forms application. It needs to accept the principal amount and tenure in number of days from the user; calculate interest and show the interest and final amount to the user on the same form. Interest rate is based upon the tenure table of rates is stored in the database. We have created two components in addition to the windows form. First component rationalizes the tenure so that it is in the number of days as expected in the database. Second component is a data access component that gets the rate from the database and provides it to first component. As per the calculation we expect the rate of interest for 180 to 360 days to be 4.5% PA and above that it should be 5%. Against expectation, when developer enters 361 to 364 days as tenure it still returns the rate at 4.5% PA. We need to debug the code to sort out the error.
We start by checking that IntelliTrace is enabled. This is done from a menu item Tools – Options – IntelliTrace.
By default, IntelliTrace collects data of the IntelliTrace events only to keep the size of the data at the minimum. To know the events that are enabled by default, we click on the submenu item of ‘IntelliTrace Events’
Although it is a comprehensive list that is possible to be configured by selecting or de-selecting the checkboxes as per necessity, what we see is that it cannot collect the data when internal calls from one of our component to the other is made. We make a note of this and select Modules item. This allows us to configure the modules for which we want to collect data. By default anything that is created by Microsoft is omitted since that is not needed to be traced in our application.
Since this setting is satisfactory, we move back to the General item in the menu. It allows us to select a radio button to collect data at the calls as well as IntelliTrace Events.
This is what we wanted so we finalize the setting there.
We now move to the Advance item in the menu. We find that by default IntelliTrace stores the data in the files under the folder ‘C:\Documents and Settings\All Users\Application Data\Microsoft Visual Studio\10.0\TraceDebugging’. We want it at a more convenient location so that we can copy files from it easily. It should also be noted here that IntelliTrace creates data files for every session of debugger. It uses FIFO to maintain those files. It also deletes all the files created for each session when Visual Studio is closed! It means that we need to copy those files and put them somewhere else if we want to maintain them even after Visual Studio is closed. We can create a folder and provide the path of that in the settings of IntelliTrace as the folder to store all the data files. We also provide the maximum size of the data file that is created for every session.
You can see that there also is a checkbox to enable or disable Navigation Gutter when the debugging is on. We will use this gutter to navigate between calls and to go inside a called method.
Explanation of other two options is given by Ian Huff in his blog as The next two options pertain to how symbols are looked up for IntelliTrace. The first option “Enable Team Foundation Server symbol path lookup” means that when you are going to analyze an iTrace file if you have Team Build configured then iTrace files with correct build info can automatically try to pull down the matching PDBs for the build this iTrace file was collected on. The second option “Prompt to enable source server support” comes into play when you open an iTrace file in which PDBs support source server lookup.”
Now that the IntelliTrace is set to our satisfaction, we start the debugging the way we normally do. We provide the 10000 as principal amount and 361 days as the tenure. When we get the interest and the final amount we observe that rate of interest that should have been 5.0 is not applied.
We also observe a link to break the execution with the text ‘Break All’. When we click on that link the debugger opens the IntelliTrace window and puts the debugging execution to pause.
We can click on the steps in the IntelliTrace Window but that does not provide us with much data. That is why we had selected to collect call information also.
We now click on the link that says ‘Switch to call view’
It shows the calls and an icon in the gutter on the left side to set context to the debugger.  
When we click on that icon, it opens the navigation gutter to navigate the calls.
Five linked icons that it shows are for:
1.    Go back to calling site
2.    Go to previous call or IntelliTrace Event
3.    Step In (F11) the call
4.    Go to next call or IntelliTrace Event
5.    Switch to Live Debugging.
Now we can move forward and backward in the method calls across the components
View the values of the variables, Autos, Locals, Watches, Call Stack etc. Finally we reach the root of the problem.
We now stop debugger. If we want to keep the data that was stored by IntelliTrace then we open the folder that we had configured. Copy the latest session file and paste it in some other folder. Now we can safely close the Visual Studio 2010.
If we now reopen that iTrace file by double clicking on the file name, it opens it in Visual Studio 2010.
If we now double click on any of the threads that is shown in the graphical view at the top then it reopens the session with that thread. For example following image shows the session that is opened when we double click on the main thread and do the same operations to open the calls view and to set the debugging context.
We can continue to work in the same session as if the application was still open.
IntelliTrace for the ASP.NET web application works in a very similar way. Events that are collected are much more detailed. I felt it a bit more complex to search through the call that I really wanted to debug.
Summary: IntelliTrace is a feature that can change the way debugging is done. It impvroves the effciency with which developer can do the debugging. It is also possible to collect data in the file and send it to an expert for debugging if the bug is hard to detect. IntelliTrace settings are quite rich and allow us to optimize the session of the IntelliTrace to suite our requirement.

If you liked the article,  Subscribe to the RSS Feed or Subscribe Via Email

Subodh Sohoni is a VSTS MVP, MCTS - Microsoft Team Foundation Server - Configuration and Development and also is a Microsoft Certified Trainer(MCT) since 2004.   

Was this article worth reading? Share it with fellow developers too. Thanks!
Share on Google+
Further Reading - Articles You May Like!
Subodh is a consultant and corporate trainer. He has overall 28+ years of experience. His specialization is Application Lifecycle Management and Team Foundation Server. He is Microsoft MVP – VS ALM, MCSD – ALM and MCT. He has conducted more than 300 corporate trainings and consulting assignments. He is also a Professional SCRUM Master. He guides teams to become Agile and implement SCRUM. Subodh is authorized by Microsoft to do ALM Assessments on behalf of Microsoft. Follow him on twitter @subodhsohoni

Page copy protected against web site content infringement 	by Copyscape

Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by MR on Thursday, March 25, 2010 11:09 PM
Thank you for posting about Intellitrace. Good job
Comment posted by shahaji on Wednesday, January 5, 2011 3:43 PM
basic information is missing in this article and that is "IntelliTrace" is part of VS 2010 Ultimate version.
Comment posted by szredziu on Wednesday, July 3, 2013 4:27 AM
Generally you forgot to mention that this feature is available only in Visual Studio 2010 Ultimate..