ANTS Performance Profiler - 6.2

ANTS Performance Profiler

Learning ANTS Performance Profiler - 6.2

Worked example: profiling the performance of an application

This worked example gives you a guided tour of ANTS Performance Profiler. It introduces you to the application's main features and shows you how you can use ANTS Performance Profiler to profile your own applications. The example shows how you can use ANTS Performance Profiler to identify the most time-critical parts of a demonstration application and determine why one programming approach is more efficient than the other.

This example is split into the following sections:

1. The Mandelbrot set demonstration application

2. Setting up the profiler

3. Profiling the application

4. Viewing the results

1. The Mandelbrot set demonstration application

This worked example is based on a demonstration .NET desktop application that draws a fractal called the Mandelbrot set. A debug build of the demonstration application is included with the ANTS Performance Profiler installation. The source code for the demonstration application is also provided, along with the .pdb file. This is located in the same folder as the executable file, so the profiler can display source code with the profiling results.

Before you profile the demonstration application, you may wish to run the application to familiarize yourself with its behavior. If you would rather just start profiling, continue to Setting up the profiler.

  1. Run the Mandelbrot set application by double-clicking the executable file located by default in the following folders:
    • For C#:

      C:\Program Files\Red Gate\ANTS Performance Profiler 6\Tutorials\CS\Mandelbrot\Mandelbrot.exe

    • For Visual Basic:

      C:\Program Files\Red Gate\ANTS Performance Profiler 6\Tutorials\VB\Mandelbrot\MandelbrotVB.exe

    Note that this worked example refers to the C# version of the application; if you are using Visual Basic, you can follow the example, but you may see slightly different results.

  2. Click Draw Mandelbrot Set to plot the Mandelbrot set:

    The application uses two alternative methods of calculating the image. You can choose between these by selecting Quick or Slow.

  3. Close the demonstration application when you have finished using it.

To prepare for profiling the demonstration application, you first need to set up ANTS Performance Profiler.

2. Setting up the profiler

  1. If you have not yet started ANTS Performance Profiler, select it from your Start menu.

    If it is already running, on the File menu, click New Profiling Session.

    The Application Settings tab enables you to specify the application to be profiled, set application-specific options, and choose the profiling mode.

    fullscreenstartup3.gif

  2. Select .NET executable from the Choose application type to profile list.
  3. From the Profiling mode list, select Line-level and method-level timings; only methods with source (detailed). This profiling mode enables you to investigate how long each line of code takes to execute.

    The other profiling modes are available in the professional edition of ANTS Performance Profiler. For descriptions of these other modes, see Application settings.

  4. Next to the .NET executable list, click to browse and select the Mandelbrot.exe. This is located in the folder where you installed ANTS Performance Profiler, for example:

    C:\Program Files\Red Gate\ANTS Performance Profiler 6\Tutorials\CS\Mandelbrot

    Under Startup Options, Working Directory is the directory that the application is launched from and is set to the location of the executable file. Arguments enables you to specify command line arguments for the running of applications. For this example, leave these settings unchanged.

3. Profiling the application

  1. When you have finished setting up the profiler, click Start Profiling to run the Mandelbrot application and start collecting performance data.
  2. In the Mandelbrot set window, select Slow to choose the slower algorithm, then click Draw Mandelbrot Set to draw the image.

    After a few seconds, the ANTS Performance Profiler timeline is updated with performance counters and event data.

    Note that execution of the Mandelbrot application is slower than usual due to the overhead of recording the profiling data. By default, ANTS Performance Profiler estimates the amount of overhead and subtracts this so that the results represent the normal execution times. This estimate is most accurate when you use a profiling mode that does not collect line-level timings. You can control whether overhead is removed from the results with the Adjust timings to compensate for overhead added by the profiler option (see Performance profiling options for further information).

  3. Wait for a few seconds, until the % Processor Time performance-counter value (the red line on the timeline) reduces to zero.
  4. Now, in the Mandelbrot set window, select Quick to choose the fast algorithm, then click Draw Mandelbrot Set to draw the image. The timeline continues to update with performance-counters and event data.

  5. When the image has been drawn, click Stop Profiling
  6. This closes the Mandelbrot application, and stops the profiling process.

4. Viewing the results

ANTS Performance Profiler summarizes the profiling results and displays the performance data as a call tree.

APP_workedexample_calltree

The call tree displays performance data for the entire time the Mandelbrot application was running, so the results include performance data for both the Slow and Quick algorithms. For the purposes of this example, you will analyze the performance data for each algorithm individually, by selecting the appropriate region on the timeline.

You can see more information about events by moving your mouse pointer over the blue lines on the timeline events bar. A tooltip is displayed for each event, listing the event type (for example, Click), and other useful information such as control names and text. By reviewing this event information, you can identify relevant regions on the timeline.

  1. Click and drag a region that covers the first run of the Mandelbrot application (which used the Slow algorithm).

    APP_workedexample_timeline

    ANTS Performance Profiler updates the profiling results such that they relate to the selected time period only, and displays the performance data as a call tree.

  2. Click the savebookmark2 icon above the events bar to bookmark this region.This option is only available in the professional edition of ANTS Performance Profiler.
  3. Now, repeat steps 1 and 2, but select a region that covers the second run of the Mandelbrot application (which used the Quick algorithm).
  4. Click on the first bookmark you created to redisplay the call tree of summarized results for the first run of the Mandelbrot application (which used the Slow algorithm).

    The call tree shows you the hottest stack trace for the selected time period (that is, the stack trace that accounts for the most execution time). It also indicates methods that may be good candidates for optimization with an asterisk (*).

  5. To change the timings from percentages to seconds, on the View menu, click Seconds. Timings are displayed as percentages by default (relative to the length of the time region selected on the timeline).

    The Time With Children column clearly shows a substantial drop in the execution time after the EvaluateUsingComplexNumbers method, suggesting that it may well be worth investigating this method for possible optimizations.

    See Working with the call tree for more information on how to use the call tree effectively.

  6. Click the EvaluateUsingComplexNumbers method in the call tree, to display the relevant source code. If the source code is not displayed, on the View menu, click Show Source View. You can now browse line-level timings in the source-code pane. The red bars in the heat map next to the scroll bar indicate the slowest lines of code.
  7. To see a flat list of all methods hit during the selected period, click APP_methodsgridicon on the display toolbar, above the call tree.

    The methods grid is displayed. You can sort and filter methods as required. For more information about the methods grid, see Working with the methods grid.

  8. To see a call graph of the methods hit during the selected period, select a method in either the call tree or methods grid, and click newcallgraph next to the method name. The call graph is displayed.

    The method you select is used as the base method for the call graph. For further information about the call graph, see Working with the call graph.

  9. To display performance profiling results for the Quick algorithm, click on the second bookmark that you created on the timeline.

    You can see from the results, that the Evaluate method (Time With Children) now executes much more quickly. EvaluateUsingDoubles replaces the inefficient EvaluateUsingComplexNumbers method in the Quick algorithm.

See also

Working with the call graph

Working with the methods grid

Working with the call tree

Working with the timeline

ANTS Performance Profiler options

Was this article helpful?

Search support
Forums

ANTS Performance Profiler

all products