(Print this page)

Get help from IntelliTrace to debug your .Net application
Published date: Thursday, August 15, 2013
On: Moer and Éric Moreau's web site

You, or your boss paid extra money to get you the Ultimate edition of Visual Studio (and/or MSDN) but do you get the most of it?

The feature I’ll introduce you to this month is called IntelliTrace and is only available in this edition, the most expensive one. It is one of the few features available in this edition only. You can check http://www.microsoft.com/visualstudio/eng/products/compare to see the full editions comparison. If you want to prove your boss is spent is money wisely, better make use of that feature!

This feature always has a minimum overhead but it can save minutes (not to say hours) of debugging. I am pretty that many times when you are testing an application, it does not exactly do what you are expecting and you don’t really know what you have done to end with this incorrect behavior. The IntelliTrace feature can save you exactly in those situations.

This month demo code

The code this month is useless. It is only provided (in both VB and C#) to help you quickly test the IntelliTrace feature. You can use your own code if you prefer.

The demo application is nothing else then a 3 random values generated on a click of a button and the total which is sometimes wrong! The whole purpose is only to provide some code to demonstrate the feature.

Figure 1: Figure 1: 6 + 3 + 5 = ?!?!?!?!

IntelliTrace Settings

While you are experimenting with this feature, you need to be aware that some options are existing. You first need to ensure that IntelliTrace is enabled (as per figure 1).

Figure 2: Default IntelliTrace settings

The default setting (IntelliTrace events only) will show you the stack of events where that were handled by your application but it won’t be able to show you other valuable information like variables value. The second setting (IntelliTrace events and call information) is way better but (1) it slows down your application because more information is collected and (2) edit-and-continue is disabled in this mode. We just can’t have it all!

How to use IntelliTrace?

You don’t have much to do.

As shown in the previous section, you first need to ensure the feature is enabled. If you really want the benefits of IntelliTrace, you should also select the “IntelliTrace events and call information” option to get the most of it.

Then you start the application in the debugger like you do normally and you do whatever you want in your application past the point where you detect a problem occurred.

When you were able to reproduce the problem (in my demo app, find a total that is incorrect according to the 3 values), you break the app using the Break All option of IntelliTrace (as shown in figure 3). The Break All command is available from the IntelliTrace dialog (available from Debug – Windows – IntelliTrace Events or Calls).

Figure 3: Breaking the execution for IntelliTrace

You can now start investigating your problem.

After you clicked the Break All button, the IntelliTrace dialog should show you the Events view (something like figure 4). This view shows all the events like gesture (button click) that happened since you start the application (or you have reach the maximum space of recording). The latest event is at the bottom of that list. In my case, I clicked the button 7 times to get an incorrect result.

Figure 4: IntelliTrace Events view

If you click on one of the gesture (figure 4 shows that I selected the Live Event), you will see the time stamp of that event.

Clicking the “Call View” will show more details about this specific gesture (see figure 5).. In my case, those are mostly to the Framework own stuff.

Figure 5: The Call View

Because I know the interesting code is behind the click event of my button, double click btn1_Click item in the dialog (near the bottom) and it should expand to show you the content of figure 6.

Figure 6: Details of btn1_Click event

Now if you click any row from that detailed section, check the code window and the Locals window (figure 7). You should see both refreshing to reflect the exact position and some values that were used at that moment.

Figure 7: Code window and Locals window

From that information, you should be able to find out that the problem is a rounding issue. We have been able to find out the cause without stepping through the code an infinite number of time or by adding debug/trace code. IntelliTrace, in this case has been a lot better than any other methods because the problem was not always reproducible.

Still in figure 7, if you check the left margin of the code window, you can see that there are some icons to let you step through the code (instead of using the IntelliTrace dialog).

Pushing your luck even further

What if the problem occurs on the tester’s computer? By using Standalone Collector, you could produce a trace file for you as a developer to open and step through the code that was executed for the user. You can read more on that subject from http://msdn.microsoft.com/en-us/library/vstudio/hh398365.aspx.

Conclusion

I only scratch the surface here! IntelliTrace is really worth it to help you debug your application. If you have the Ultimate edition, you really need to crank up this feature.


(Print this page)