Wednesday, September 12, 2012

Visual Studio IntelliTrace

We are exactly 1 day before the Microsoft Visual Studio 2012 Virtual Launch and now I am going to explain one of the nicest features in Visual Studio 2010.

In every application we write, there are bugs. It can be a small one which is easy to find or it can be a tough one which can take days to find. So to find the bug normally what we do is, we are putting break points in the code where we suspect problem is and we start debugging. We are pressing F10 and F11 and we keep going on line by line. Sometimes because of our eager to find the bug, we are going faster and suddenly we are passing and missing the bug. Then what we do is, again starting the debugging from the beginning.

Sometimes this can be a real headache when we are fixing a bug on an application where we have to supply a lot of inputs for the bug to raise. Every time we debug the application, we have to supply those values and it is very troublesome. So that’s where this IntelliTrace comes in.

IntelliTrace was introduced with Visual Studio 2010 and it is only available in the Ultimate edition of Visual Studio 2010. IntelliTrace has the ability to go back through the past states of an application and view those states. If you did not understand what I meant by past states of an application, let me explain it taking a simple example.

I have a windows forms application which has only a single form. Form contains a single button and I have two variables which are “i” and “j” and they are initialized to 0. Now in the form load method and the button click event I am changing the values of these variables. My requirement is to trace the value changing of my two variables. (Of course, in the following example there is nothing to debug, I just want you to get the idea behind it.)

Following is the code I have and I have set two breakpoints in Form1_Load and btnGetSum_Click events.
        private int i = 0;
        private int j = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            i = 10;
            j = 20;

            lblI.Text = string.Format("i is {0}", i);
            lblJ.Text = string.Format("j is {0}", j);
        }

        private void btnGetSum_Click(object sender, EventArgs e)
        {
            i = 30;
            j = 40;

            lblSum.Text = string.Format("Sum is {0}", i + j);
        }
First I have opened the IntelliTrace settings from Visual Studio (Tools->Options->IntelliTrace) and I have selected “IntelliTrace events and call information.” under “Collect the following IntelliTrace information while debugging:”.

By selecting this I am telling IntelliTrace to collect both event information and call stack information. The call stack information can include method names, method parameters, and return values. But a thing to note here  is by selecting this option, it can lead to performance issues with the application. The default selection which is “IntelliTrace events only” will only collect information related to IntelliTrace events such as opening file, writing to registry etc.

Untitled1
IntelliTrace Opions

Now I have started debugging and I have gone through both breakpoints and for some reason I couldn’t check the variable values in each event. Now normally what I will have to do is again starting the debugging from the beginning. Now with Visual Studio IntelliTrace, you don’t have to start the debugging again any more. What you have to do is, while the application still running, go or open the IntelliTrace window and click on “Break All”.
Untitled2
IntelliTrace Window
Now you can see the all the event and call information through out your application in the IntelliTrace window.

Untitled3
IntelliTrace Window

When I click on second and forth item which are the Form1_Load and btnGetSum_Click events, I can see the following.

Untitled4
IntelliTrace Window
Untitled5
IntelliTrace Window
It will show me before coming in to the Form1_Load event, the values of  “i” and “j” is 0 and 0 respectfully.   Before control going into btnGetSum_Click event the values of  “i” and “j” is 10 and 20 respectfully. So now I can see what the values of each variable are before and after methods/events. Simply what IntelliTrace does here is, it provides all the information in each of the application’s states. Now I believe you all got a good understanding in what I meant by “IntelliTrace has the ability to go back through the past states of an application and view those states.”.

This is one thing that is available with IntelliTrace. There are a lot of things that can be done using IntelliTrace and for more information on Visual Studio IntelliTrace ,visit following sites.


I am pretty sure, with the release of Visual Studio 2012, Microsoft will gift us some new features which we did not even imagine.

Happy Coding.

Regards,
Jaliya

No comments:

Post a Comment