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.

This article has been editorially reviewed by Suprotim Agarwal.

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn. We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle). Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview. Click here to Explore the Table of Contents or Download Sample Chapters!