ANTS Performance Profiler - 7.4
Worked example: Profiling an ASP.NET application - ANTS Performance Profiler
This worked example describes how to profile a sample ASP.NET website called NerdDinner. You can download the original ASP.NET MVC source code for NerdDinner from CodePlex: in this example, the NerdDinner code has been modified to illustrate a performance problem.
In this example, NerdDinner is installed on the same computer as the one being used to profile it, and can be accessed in a web-browser at http://127.0.0.1:8090 .
Imagine that the problem with NerdDinner is that it is slow to return results for a search involving a SQL query. Imagine you want to know whether you can do anything in the application's .NET code to improve the site's performance, before you investigate performance on the database, or spend money to improve the hardware the site runs on.
There are three main steps:
- Set up ANTS Performance Profiler
- Use NerdDinner
- Analyze the profiler's results
Setting up ANTS Performance Profiler
To set up ANTS Performance Profiler:
- In the ANTS Performance Profiler settings, on the Application Settings tab, select ASP.NET web application (IIS).
- In the ASP.NET web application (URL) dropdown menu, select the site's URL: http://127.0.0.1:8090.
- Choose the required profiling mode. Here, we'll use line-level and method-level timings.
For more on profiling modes, see Choosing a profiling mode.

- Select the port on which to profile your application:
- If you are using IIS 6 or IIS 7, select Unused port and choose a port that is not used by IIS.
IIS will start a new instance of your application on the specified port.
Note that this will not work if your application's code binds to a specific port.
- If you are using IIS 5, or if you are using IIS 6 or 7 and your application binds to a specific port, select Original port.
IIS will restart so that the profiler can attach to the port.
Note that restarting IIS stops IIS and restarts only the application that you are profiling. Other websites on the same IIS instance will not be present when IIS restarts.
The port where the application will be profiled is displayed at the bottom of the ANTS Performance Profiler Settings dialog box.
For more on profiling web applications in IIS, see Profiling ASP.NET applications running on IIS and Troubleshooting IIS profiling.
- If you are using IIS 6 or IIS 7, select Unused port and choose a port that is not used by IIS.
- Click
. - Internet Explorer launches and loads NerdDinner.
If you prefer not to use Internet Explorer, you can open a different browser at the same address. You must, however, leave open the instance of Internet Explorer created by the profiler.

Using NerdDinner
In this example, the NerdDinner site includes several pages that rely heavily on database queries, as well as some static HTML. Imagine users have reported that the site's location search feature is slow: we start the investigation by exercising that feature, entering a place name in the search box and hitting Search. The search is designed to return a list of events near a certain location.
While we use the site, ANTS Performance Profiler's timeline shows the CPU usage the application has caused:

There's a brief, expected CPU peak when the site launches. CPU then returns to near zero until we start our search, when it begins to grow to nearly 200%, staying high for long after the first results were returned. This clearly indicates a performance bottleneck in the search feature.
For more information on analyzing CPU usage, see Working with the time line.
Now we see where the bottleneck may lie, we can explore the results in detail: In the ANTS Performance Profiler window, click Stop Profiling.

The website closes.
Analyzing the profiler's results
After a few moments, full results are shown.
At the top of the call tree, ANTS Performance Profiler shows the 'hottest' stack trace; that is, the code that contributes the greatest proportion of CPU time. This is usually a good place to start looking for opportunities to optimize the code.

At the top of each call tree stack, we see the HTTP request that triggered the calling of the .NET methods. As we expected, the hottest stack trace during the whole profiling session descends from the request http://127.0.0.1:8090/Search/SearchByLocation, child methods of which account for about 64% of the total time spent in the profiling session.
Looking down the hot stack, we can see that this request called a .NET method, NerdDinner.Models.DinnerRepository.NearestDinners(double latitude, double longitude), that was hit 1620 times - as was the SQL SELECT query it ultimately runs.
For more information on hot stacks and HTTP nodes, see Working with the call tree.
If we select the method's parent, NerdDinner.Controllers.SearchController.SearchByLocation(float latitude, float longitude), we can view its source code. Because we used a profiling mode with line-level timings, we can also see where inside the method the greatest time was spent. This shows us that the method retrieves the full list of all recorded events from the database:

The method NerdDinner.Models.DinnerRepository.FindByLocation(float latitude, float longitude) then tries to process the result set in the web page, to filter by location:

These methods are good candidates for optimization. The same results could be achieved via AJAX calls, and by returning from the database only events that meet specified latitude and longitude criteria.
For more on the source code view, see Working with source code.
Switching to Database Calls view, we can see that the query to return the full results set was run thousands of times, summing to over 14 seconds just to return the first result for all the instances of the query:

Again, it's clear that this very broad request is being run repeatedly, contributing a large total running time. It would be more efficient to run a more precise request fewer times.
For more on SQL query timings, see Working with the database calls view.
After profiling, we now have a clear idea of which HTTP requests are associated with slow performance, and which of our .NET methods contain the source of those slowdowns. We know which methods to rewrite to remove bottlenecks, and the steps we'll need to reproduce in the application to check that the problem has gone.
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
ANTS Performance Profiler
- Worked example: Profiling an ASP.NET application - ANTS Performance Profiler
- Worked example: Profiling from the command line - ANTS Performance Profiler
- Worked example: Profiling performance of an algorithm - ANTS Performance Profiler
- Worked example: Profiling network overheads - ANTS Performance Profiler

Using ANTS Performance Profiler