ANTS Performance Profiler - 6.2
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
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.
- 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.
- For C#:
- 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.
- 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
- 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.

- Select .NET executable from the Choose application type to profile list.
- 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.
- 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
- When you have finished setting up the profiler, click Start Profiling to run the Mandelbrot application and start collecting performance data.
- 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).
- Wait for a few seconds, until the % Processor Time performance-counter value (the red line on the timeline) reduces to zero.
- 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.

- When the image has been drawn, click Stop Profiling

- 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.

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.
- Click and drag a region that covers the first run of the Mandelbrot application (which used the Slow algorithm).

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.
- Click the
icon above the events bar to bookmark this region.This option is only available in the professional edition of ANTS Performance Profiler. - Now, repeat steps 1 and 2, but select a region that covers the second run of the Mandelbrot application (which used the Quick algorithm).
- 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 (*).
- 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.
- 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.
- To see a flat list of all methods hit during the selected period, click
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.
- 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
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.
- 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 |
Was this article helpful?
ANTS Performance Profiler
- Installation error 5100 when installing ANTS Performance Profiler and ANTS Memory Profiler
- Attach to process unavailable with some anti-virus software
- Memory leaks observed when profiling Windows Presentation Framework (WPF) applications
- Log files
- The manifest for the SQL server event source did not match the generated events. Some SQL events may report incorrect data. To fix this issue, consider recompiling etwcls.mof
- Setting file I/O and child process profiling in high DPI modes
- HTTP request timings in IIS
- Profiling web services in IIS Express
- Method not found: 'UInt32 <Module>._ANTS_Begin_Sql(System.String)'
- Enabling line-level timings for SecurityTransparent code
- Profiling SharePoint 2010 in v6.0 - 6.3
- Profiling SharePoint subsites
- Problems synchronizing results
- Windows service profiling fails if the service uses a system account
- Profiling assemblies protected with DeployLx
- The type initializer for 'y.layout.hierarchic.ClassicLayerSequencer' threw an exception
- Forcing your application to use .NET 4
- Double hit counts occurring on one line
- System.EntryPointNotFoundException (Versions: 3,4 only)
- Methods in (ASCX) web controls may not appear
- Failed to CoCreate Profiler error profiling a Windows service
- Multiple-core portable computers may show inflated times (version 3)
- No .NET methods were profiled on web application
- ANTS Profiler code instrumentation method
- Add-in fails to load when using RunAs to start Visual Studio as another user
- Profiling unit tests using Nunit
- Can I profile Compact Framework applications?
- Profiling a SharePoint 2007 Web Part
- Profiling an assembly in the Global Assembly Cache (GAC)
- Profiling IIS web applications that need to run under the SYSTEM account
- Profiling a web application hosted in IIS on a fixed TCP port
- Profiling client-side XBAP .NET applications
- ANTS Profiler prompts for location of source code which is not your own source code
- ANTS menu remains in Visual Studio after uninstall of ANTS Profiler
- Profiling a web application needing to run as the Network Service account
- Cannot start COM+ application via Remote Desktop
- Finding the overall time taken to execute a thread
- Profiling BizTalk applications
- Profiling Microsoft Office managed-code add-ins
- The system cannot find the file specified
- Error Stopping IISAdmin profiling IIS web application on Windows XP
- Creating a global debugging symbols (PDB) directory
- Using the add-in to profile solutions containing more than one project
- Methods may be missing on multi-core systems in version 3
- ASP .NET 1.x application recycling causing incomplete results
- Application recycling causes incomplete results and other errors when profiling ASP .NET
- (version 5) Support for profiling Silverlight applications
- Couldn't open metabase error when profiling ASP .NET hosted in IIS
- Failed to coCreate Profiler on ASP .NET web application
- HTTP error 404.17 profiling ASP .NET 1.1 on IIS 7
- Performance counters missing from results
- Isolating single ASP .NET pages in ANTS Profiler results
- Missing hits for lines in the source code view
- ANTS Profiler restarts IIS
- Showing the amount of time taken for a method in one particular thread
- Please specify a valid URL message profiling ASP .NET
- Times on individual lines do not add up to method time
- Explanation of "thread blocked" methods in ANTS Profiler
- Call graph percentages do not add up exactly
- Operation could destabilize the runtime error profiling ASP .NET
- IIS ceases to work after profiling web applications
- Problems with ANTS Visual Studio integration
- ANTS Profiler has been split into two distinct programs
- Windows Installer errors 1603 and 2738 occurring during installation
- Times in source code window are greater than the times showing in the method grid or tree view
- Problems with ANTS Performance Profiler Visual Studio integration
- Profiling ClickOnce applications deployed to IIS
- Could not enable tracing due to error code 112
- AjaxControlToolkit incompatibility causing application being profiled to crash
- Could not enable tracing because SQL Express is installed
- ANTS Performance Profiler menu items not showing in Visual Studio 2010
- Profiler stopping while profiling an in-browser Silverlight application
- "No Disk" error occurring while profiling application
- IE error "Internet Explorer cannot display the webpage" when profiling a website
- Profiler failing to connect to the server when profiling web applications
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
ANTS Performance Profiler
- Activating your products
- Activating your products
- Interpreting unexpected profiling results
- Choosing a profiling mode in ANTS Performance Profiler 6
- ANTS Performance Profiler 7 release notes - version 7.xx
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Using ANTS Performance Profiler