ANTS Performance Profiler - 6.2

ANTS Performance Profiler

Learning ANTS Performance Profiler - 6.2

Profiling an ASP.NET application (worked example)

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. Choose Record SQL and file I/O performance if you are interested in seeing these values. (Not available on Windows XP or Windows Server 2003.)

  5. To profile the website without restarting IIS, you can choose to profile the program on an unused port. The safest option is generally to profile the application on the original port (80), but this will cause IIS to restart. See 'Troubleshooting' below for more information.
  6. Click start_profiling_uac.
  7. 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.

    aspnet_beerhouse

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.

aspnet_inputcontrols

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 called SetInputControlsHighlight(), 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 SQL results do not show anything abnormal.

aspnet_sqlfile

Was this article helpful?

Search support
Forums

ANTS Performance Profiler

all products