What can you do with ‘IntelliTrace’ in Visual Studio 2010

(This post is part of my Visual Studio 2010 series)

As I wrote in my earlier article, Visual Studio 2010 has many new features in debugging. IntelliTrace is one of the major features of Visual Studio 2010 and as of now it is available only in Visual Studio 2010 Ultimate edition. In my opinion, IntelliTrace is the best reason to convince your boss to get Ultimate edition for you :). Note, IntelliTrace only supports managed code, for example, it doesn’t support vc++ native code.

This article introduces IntelliTrace and tells how it helps in simplifying debugging and tells some more things that can be done with it (based on Visual Studio 2010 ultimate edition-release candidate).

(I am taking the intro from previous post..)

Introducing Visual Studio 2010's IntelliTrace..

IntelliTrace is a feature previously known as Historical debugging, which is a major enhancement made to the Visual Studio 2010 debugger. When an exception occurs, you usually start debugging with breakpoints set in suspected areas and check variable/object values for correctness.

But if an exception occurs when IntelliTrace is enabled, it allows you to just go back in time of your application execution and find out what events got raised and what were the values of various variables, etc, similar to Call stack like approach. This helps you inspect all the events that finally triggered the exception. This helps in many ways, even you don’t need to worry about breakpoints.

 

Let me start with an example exception and then proceed on how you would handle it without and with IntelliTrace.

Consider you get the below simple exception.

You immediately guess that the filename/path is wrong in FileToRead or the file should have been there, but missing. Let us keep that the file name is wrong for this example.

Let’s see how we will usually debug this, without IntelliTrace..

Without IntelliTrace

Even though the exception is simple; as it’s clear that the filename/path is wrong(as we decided for this example). We need to find out why FileToRead is passed with a wrong value. The possibilities could be anything, like, the folder path is missing/incorrect, file path & name is incorrectly framed, etc. So even though the exception is simple, the point to note is, it could be complex to find out the cause of the exception!

To find out the cause, most of us analyse the current section of code and/or call stack and if nothing seems to help, we may stop this running(debug mode) application and set breakpoints in several areas of code from where the control of execution reaches ReadFromFile() method. Then, we restart debugging the application and step through the code and we could find the cause and correct the code.

This approach may require you to stop the running application and restart(re-debug) it many times, and it could be very tedious and tiring at times. Also you might not be able to reproduce some errors, maybe because you could have forgotten the series of things you did that triggered the exception. IntelliTrace basically provides a solution for this and gives you some more features.

Now let’s see how you can handle this in Visual Studio 2010(ultimate edition) with IntelliTrace enabled..

With IntelliTrace

Before showing how we handle the above exception in IntelliTrace, I will tell how IntelliTrace works and how to setup. IntelliTrace works by collecting information on the background as you run your application.

You can enable IntelliTrace by going to Tools –> Options –> IntelliTrace and check Enable IntelliTrace. There are two ways to collect IntelliTrace information IntelliTrace Events only or IntelliTrace Events and Call information, you can select this in Options. Collecting IntelliTrace information for Events and call option will have more impact in application performance than Events only option.

Events only option works by capturing specific events that occur in your application like file IO, Database access, etc., you can specify this also in the IntelliTrace options.

Events and call information option works by tracking all method calls and events that occur in your application, note that this option fully utilizes the IntelliTrace feature and some IntelliTrace specific IDE tools work only in this option, so most will prefer this(but as I mentioned earlier, don’t forget that this option will degrade application performance).

If you have chosen Events and call information option, in modules section of IntelliTrace options, you can specify what modules to exclude when collecting IntelliTrace information. For instance, you can specify the DLLs which you are not interested in tracing as you might be confident that they won’t be having any errors(ex: YourCompany.Utilities.dll).

 

Now let’s see how we’ll handle the same file IO exception we got above using IntelliTrace features.

When the exception occurs, debugger will as usual show the exception with IntelliTrace window as shown below(I am using Events and call information option).

(click on below image for its enlarged version)

 

IntelliTrace Calls view..

IntelliTrace window has Events view and Calls view(calls view-only if you enable tracing Events and call info), you can switch views using the link in top.

In Events/Calls view, list of recorded items are shown, double-clicking one of them takes you to the code which triggered it and from there you can Step Into the code as usual and inspect it. Also note the “Related views” links, using these you can switch to Calls View, Locals window and Call Stack.

Important thing here is, the Locals and Call stack set their context and behave as if the current line is the next statement to be executed, and shows information in them accordingly, like, Locals will show current context’s local variables/objects. This allows you to inspect using them, in all the events/calls that IntelliTrace recorded!, else you have to set breakpoints at each location you suspect and restart the application and debug it.

Navigation Gutter

Note the navigation gutter in above image, you can do below things using it.

(This image is a screenshot of Debug->IntelliTrace menu, which here can be used to explain the navigation gutter)

Most of the above is clear in its caption itself, Go To Live Mode just takes you back to the code which raised the exception and leaves you in a stage when you got the exception first, before you started using IntelliTrace’s navigation options for inspecting.

Note Go to Live mode option appears in navigation gutter only if your current context is Not in the line the exception got thrown.

 

So how do we debug the file IO exception we saw above..?

Now you probably would have figured out how we would debug the exception I said above, using IntelliTrace..anyway, I am telling it. Once we get the exception we can..

  • Use the events or calls view and go to suspected items and check the code in those areas.
  • Use the navigation gutter to go backwards in application execution step by step and maybe use the Locals window and examine the variable values

...and find out what went wrong and fix, that’s it.

 

More...

We can do more things with IntelliTrace.. you can right-click any line and search for that line or method in IntelliTrace call information. You can set the debugger context in all the call locations(call sites) from where the current exception triggering code got reached.

You can share the IntelliTrace information with colleagues by giving them the .itrace file stored in the path you choose in IntelliTrace options and they can load this file and start debugging the exception(but I was able to open the corresponding source solution/file only when it is present in the same location, I mean, if you have the solution in c:\MyProj, other machine should also have in same path) the .itrace file is deleted if Visual Studio is closed, so copy it before closing Visual Studio.

Also Microsoft Test Manager is launched along with Visual Studio 2010 and it is available with Ultimate/Test professional edition, Test manager can collect IntelliTrace information and the tester can attach the trace file with the issues he/she logs in Team Foundation Server! which would be a great thing, click here for more on this.

 

Conclusion

I hope you got good idea about Visual Studio 2010’s IntelliTrace feature and how it can change the issue handling capabilities we have now(and why ultimate edition matters ;)

 

Please note: The purpose of the article is to provide a broad overview about IntelliTrace and what can be done with it, these are the features majority of the developers may use. To the most extent the article is written keeping beginners too in mind.

 

 

If you like this article..

kick it on DotNetKicks.com    Shout it

Bookmark / Share

Comments for this entry..


                What can you do with

                You've been kicked (a good thing) - Trackback from DotNetKicks.com
            

by.. DotNetKicks.com | April 8, 2010 01:27 | Reply


                Daily tech links for .net and related technologies - Apr 8-10, 2010

                Daily tech links for .net and related technologies - Apr 8-10, 2010 Web Development Using RIA DomainServices
            

by.. Sanjeev Agarwal | April 8, 2010 12:30 | Reply


                What can you do with

                Thank you for submitting this cool story - Trackback from iAwaaz-News-by-People
            

by.. iAwaaz-News-by-People | April 9, 2010 04:12 | Reply

I would have to say that Intellitrace is the number one reason for upgrading to Visual Studio 2010 Ultimate.  I am using the RC and tried to use Intellitrace but I didn't install the Ultimate version and am now wishing I had.

by.. Bret Ferrier | April 9, 2010 10:03 | Reply

9 new features of Visual Studio 2010 that can help your productivity right away

9 new features of Visual Studio 2010 that can help your productivity right away

by.. CodeHappiness.com | June 22, 2010 01:06 | Reply

Write your comment..




biuquote
  • Comment
  • Preview
Loading