次の方法で共有


Search For This Line In IntelliTrace

One of the key benefits of IntelliTrace is that it collects lots of useful information about your application which allows you to debug exactly what the application was doing when a problem occurred. With so much information, it's important to be able to search for the specific data that led to the bug in the program. IntelliTrace provides a couple of features inside the editor that allow you to narrow down your search:

  1. Search For This Line In IntelliTrace
  2. Search For This Method In IntelliTrace

Both of these features are available from the editor context menu (shown below). In this blog post, I'm going to cover the first feature, i.e. Search For This Line In IntelliTrace. In a future blog, I'm going to cover the second feature, i.e. Search For This Method In IntelliTrace.

Editor Context Menu 

So what does the "Search For This Line In IntelliTrace" command do exactly and how is it used? Let's walkthrough a simple example to see how this feature works. In the following code snippet, I am interested in finding out how many times the the statement ShoppingCartItem item = FindItem(product); (line 7 below) was executed and also, I want to figure out what happened before this line was called.

    1: /// <summary>
    2: /// Adds a product to the cart
    3: /// </summary>
    4: public void AddItem(Product product, int quantity, DateTime dateAdded) {
    5:  
    6:     //see if this item is in the cart already
    7:     ShoppingCartItem item = FindItem(product);
    8:  
    9:     if (quantity != 0) {
   10:         if (item != null) {
   11:             //if the passed in amount is 0, do nothing
   12:             //as we're assuming "add 0 of this item" means
   13:             //do nothing
   14:             if (quantity != 0)
   15:                 AdjustQuantity(product, quantity);
   16:         } else {
   17:             if (quantity > 0) {
   18:                 item = new ShoppingCartItem(product, quantity, dateAdded);
   19:  
   20:                 //add to list
   21:                 Items.Add(item);
   22:             }
   23:         }
   24:  
   25:     }
   26: }

In order to do that, I can right-click on line 7 above and select "Search For This Line in IntelliTrace".

Search For This Line In IntelliTrace

After selecting the command, the IntelliTrace Search Bar is shown at the top of the editor window. The screenshot below highlights the IntelliTrace Search Bar.

image

Think of the Search Bar as the controls on your DVR where you can go backwards and forwards through your IntelliTrace recording. One of the key features that the IntelliTrace Search Bar provides is displaying the number of times that a line of code was executed. In the example below, you can see that the highlighted line was executed 4 times.

image

Using the Search Bar, you can debug backwards from the time when the line of code was executed. In the screenshot below, after clicking the left arrow once, I can now use IntelliTrace to step back through the code.

Go to Previous event 

Habib Heydarian.

Comments

  • Anonymous
    November 25, 2009
    thanks a lot for this article