ANTS Performance Profiler 7

Help for older versions available.

These pages cover ANTS Performance Profiler 7, which is not the latest version. Help for other versions is also available.

Worked example - Profiling an ASP.NET application - TheBeerHouse

This worked example applies to ANTS Peformance Profiler version 7.2 only.

This worked example describes how to profile a sample ASP.NET website called TheBeerHouse. The original ASP.NET MVC source code for TheBeerHouse can be obtained from CodePlex. To create this worked example, TheBeerHouse has been recompiled for .NET 4.

TheBeerHouse has been installed on the same computer as the one being used to profile it, and it can be accessed in a web-browser from the address http://localhost/TBH_Web/

Imagine that the problem with TheBeerHouse is just that it is slow when loading pages. I want to know whether I can do anything to improve the site's performance, before I spend lots of money on improving the hardware it runs on.

There are three main steps:

  1. Set up ANTS Performance Profiler
  2. Use TheBeerHouse
  3. Analyze the profiler's results

Setting up ANTS Performance Profiler

To set up ANTS Performance Profiler:

  1. In the ANTS Performance Profiler settings, on the Application Settings tab, select ASP.NET web application (IIS).
  2. In the ASP.NET web application (URL) dropdown menu, select the site's URL: http://localhost/TBH_Web/.
  3. Choose the required profiling mode.

  4. 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 only restarts the application that you are profiling. If your website depends on another site running on the same IIS instance, that other site will not be present when IIS restarts.

    If your application takes too long to start, IIS might not restart correctly. Use IIS Manager to stop the website manually until you have finished profiling.

The port where the application will be profiled is displayed at the bottom of the ANTS Performance Profiler Settings dialog box.

  1. Click .
  2. Internet Explorer launches and shows TheBeerHouse. If you prefer not to use Internet Explorer, you can open a different browser at the same address. You must leave the instance of Internet Explorer created by the profiler open, however.

Using TheBeerHouse

In this scenario, it is not known exactly where the performance problem is, and so initially a number of different pages are accessed, including some which are known to rely heavily on database queries, and some which mainly contain static HTML. After any particular performance problems have been identified, those pages can be profiled again in a more systematic manner.

After a number of different pages have been opened, in the ANTS Performance Profiler window, click Stop Profiling.

Analyzing the profiler's results

After a few moments, the results are shown. ANTS Performance Profiler shows the 'hottest' stack trace; that is, the code which is using the greatest amount of CPU time. This is usually a good place to start looking for opportunities to optimize the code.

TheBeerHouse is already quite well optimized, with 66% of processor time being spent on very inexpensive methods. The site could be improved, however, because nearly 5% of the processor's time is spent on a method calledSetInputControlsHighlight(), which runs when each page loads.

Select that row.

Because the source code for TheBeerHouse is available, ANTS Performance Profiler shows the source code for this method in the lower pane. Every time a page loads, SetInputControlsHighlight() iterates over the input fields it contains, and adds onfocus and onblur attributes to the HTML output, in turn causing the DOM to change their class when the input has focus. This is clearly a good candidate for optimization, because the same result can be achieved by just changing the CSS file to add the :focus pseudo-class.

In this instance, the File I/O and database call results do not show anything abnormal.


Didn't find what you were looking for?