Profiling with Ants

By Joél Contreras, 9/26/03

Introduction

Write “tight code!”  We’ve all heard the phrase and all like to think we code by this mantra.  However, have you ever stopped and actually ‘clocked’ your code to gauge which procedures, functions, or methods can use some optimization?  In a multi-tier .NET application, thinking about of an approach for optimizing your code can seem as a daunting and frightening challenge.  I mean, think about it, where do you begin?  At the User Interface Layer?  At the business Logic Layer?  Or better yet, at the Data Access Layer?  Who knows!  In fact, why should you even bother with such a monumental task?  Well, this last question can be answered in three simple words: end user satisfaction! Okay you say, I want my users to find the application’s performance acceptable and I’m willing to do whatever it takes to identify where the “bottlenecks” are but, how do I do that?  Well, this is where code profiling can come to your rescue.

Code profiling is the process of determining what pieces of your application code is most frequently used during program execution.  With this type of information in hand, a developer can focus coding efforts on optimizing those essential pieces of the application’s logic.  The end result will not only yield a more robust application but ultimately, a satisfied user.  This article is a brief product review of the Advanced .NET Tool Suite (ANTS) profiler application by Red Gate Software.  ANTS profiler can profile Windows and web based applications written in any of the .NET managed languages.

Installing, Starting, and Configuring a project

Installation of ANTS profiler is truly a “no-brainer” requiring no system restart.  Upon initial startup, you can’t help but to notice the interface look and feel similarities to Visual Studio .NET as shown in figure 1.

Profiler Start Screen

Figure 1: ANTS profiler Start screen

The first step in profiling an application is to set up the project properties.  This is accomplished by clicking on the first link (as shown in Figure 1) in the Start page.  From a project perspective, you can profile an application (Windows, web application, Web Service, or COM+) or, an individual Namespace.  Figure 2.0 shows a screen shot of the project properties page.

Project Properties Set Up Screen

Figure 2: project properties set up screen

As you can discern, the project property interface is intuitive and has a miniscule learning curve.  In terms of Namespace profiling, the options available are either to profile only a specific set of Namespaces, or, to profile every Namespace except the listed exception(s). 

Let’s profile

Once you’ve set up your project profile information, you are ready to begin profiling.  For my particular example, I am profiling a Web Application, thus, have asked ANTS launch Internet Explorer (as noted in the project properties screen shot displayed in figure 2.0). 

As in setting up the project properties, beginning profiling is available from Start page.  When you click on the “Start profiling with current settings” link, a warning popup dialog box informs you that a profiling session is about to begin.  The message will also note that Internet Information Services (IIS) will be restarted.  In addition, ANTS profiler will warn you that running in test and development are safe; however, profiling should not be done in a production environment.

Note for IIS 6.0 users, ANTS profiler Version 1.22 Build 137 does not execute in IIS 6.0.  If you are running IIS 6.0, a dialog box will inform you that the service must run in IIS 5.0 isolation mode.  Some handy direction on how to run IIS 6.0 in IIS 5.0 isolation mode is provided by ANTS profiler.

To begin capturing profile information, ANTS profiler starts my application in Internet Explorer.  At this point, I take my application for a spin and execute as many functions as I possibly can.  This gives the ANTS profiler an opportunity to gather information about my application code, which will ultimately be used in producing the statistical results.  To stop profiling, I can simply click on the “Stop” button displayed in a “Control” window.

Ants Go Stop

A results page (refer to figure 3.0) will be automatically displayed with the following information:

(1)   procedure Times - Execution time incurred by the function (does not include any time incurred sub-functions that may have been called).

(2)   Totals – Total time incurred by a function (this one does include time incurred in a sub-function thus, it renders the total “trip time” in function execution).

(3)   Hits – Number of times a function is called.

(4)   Averages – Self explanatory.  

(5)   Minimum - Self explanatory.

(6)   Maximum – Self explanatory.

>

ANTS Profiler Results Page

Figure 3: ANTS profiler Results page

The report includes sorting functionality via hyperlink report headers.  By clicking on the listed hyperlinks functions you can easily drill down into your applications methods. One recommendation that I would have for Red-Gate, is to add tool tips to each of the report headers to further explain the statistical information being shown on the screen.

By far, the most useful feature of this product is that you are actually able to see the amount of time a piece of logic takes to execute.  This information is made available by ANTS profiler on a line-by-line basis (see Figure 4.0 below).  This includes the line number, total number of hits, and the time incurred in executing the line.  Bar graphs provide you a means to readily see the where most significant “bottlenecks” are in your application.  This is an excellent source of information to guide you in focusing your code optimization efforts.

Details of a Function


Screenshot 4: Details of a Function

product Improvement Suggestions

Although my earlier suggestion to add a tool tip to the headers may be somewhat cosmetic, I believe it will benefit new users of the product.  An export facility into a comma value separated (CSV), or tab delimited, will extend the reporting capabilities of this product.  With this feature available, the output file may be imported into a Microsoft Office product (powerpoint, Word, or Excel) for more flexible report sharing benefits.  This may be particularly useful in larger organizations where code performance information is reviewed as part of managing an application development unit.

Conclusion

Overall, ANTS profiler is impressive product. It has an almost non-existent learning curve and can instantly provide you detailed and invaluable code optimization information.  A 14-day full-featured download version is available at Red Gate Software web site.  If you are interested in getting the most performance out of your code and providing a more satisfying experience to the users of your application, I strongly urge you to download a copy of ANTS profiler and take it for a spin.

About the author

For nearly 19 years, Joél Contreras has been employed in the Information Technology area of a major retirement and financial firm.  During this tenure he has played significant roles in possibly every area of the company’s technological organization including Database Management System, Network Infrastructure, project Management, Disaster Recovery, and Systems programming.  Although, he has been in management for over fourteen years, he has never lost the passion for “playing” with new technology and thus, it is no wonder he has embraced the .NET framework and C#.   Joél has a BA in Computer Information Systems and a Master of Business Administration.  He can be reached at jc@loanhost4life.com