Published: 24 Oct 2007
By: Granville Barnett

A review of ANTS Profiler 3 from Redgate software.

Introduction

Sometimes as developers we get too focused on creating aesthetically pleasing code and we forget about the real life implications of our design - are we picking the right class for the job? Or are we using it simply because it's more convenient to interact with? The latter would be a fair opinion if the costs associated with its use were identical to the other solutions. Unfortunately in most cases this is not true.

The .NET platform has a wide range of solutions that are generalized. Interacting with the Base Class Library (BCL) and other associated classes is a part of life as a .NET developer just like using the standard library and Win32 is if you are a Windows C++ developer. But what distinguishes many choices at the implementation level is speed (after clarity of system design and composition), and a lot of the .NET stuff can be very expensive to use.

By using a profiler we can analyze our code to see where the bulk of time is being spent in our application and see if we can find a more appropriate solution to reduce that time. I like referring to time allocation for routines as a budget. A well planned project will have certain quality standards: Maybe your application has 10 milliseconds to perform operation X - then 10 milliseconds is your budget for the entire operation. Therefore, you need to make sure that you meet that quota. Profiling plays a major role by highlighting slow code.

In this review we will talk about using ANTS Profiler 3 to highlight problematic areas of code.

What ANTS Profiler 3 supports

  • ANTS Profiler 3 supports two types of profiling:
  • Performance profiling (two types: detailed and fast)
  • Memory profiling
  • Each of which supports the following application types:
  • .NET desktop application
  • ASP.NET application hosted in IIS
  • .NET Service
  • COM+ server application
  • The support offered by ANTS Profiler is pretty comprehensive. In this review I will be profiling a .NET desktop application.

The workflow of a profiling session

Profiling an application with ANTS Profiler couldn't be any simpler. You simply start ANTS Profiler and then follow the wizard, selecting the profiling type and specifying the location of the binary you wish to profile.

Figure 1: Selecting the application type

type.png

After completing the wizard you get a nice overview report that highlights:

  • Slowest lines of code
  • Slowest methods
  • Slowest methods with children

Figure 2: The slow stuff

slow.png

I would suggest that even though the profiler may mark a line of code or method as being slow, before you think that your code is not very good think about the scenario it is satisfying. As a rule of thumb, you should investigate that code to see what is costing you.

As well as statistical data in the form of a summarized report, you also get a preview of your source code along with cost annotations that make it easier to identify the more expensive code in your application.

Figure 3: Code cost annotations

annotations.png

In Figure 3 we have hit counts displayed. If a line of code or method is pretty expensive and the hit count is high then you are probably going back to the whiteboard. Like I mentioned earlier, everything is within context. The profiler may identify a line of code as being really slow yet you know that you maybe have to touch the disk for a certain operation and that is the bulk of the cost there.

As well as the summary and code annotations you also have an All Methods view which allows you to see every method called and its associated call time. You will probably spend the majority of time in this screen, filtering by time and hit count to check that the code under stress is as efficient as possible.

Figure 4: All methods screen

allmethods.png

Note: I've squeezed the columns together for the screenshot. All columns can be customized and filtered.

Memory Profiling

This is another great way to look at what resources you're program is consuming, in particular the size of the managed heap.

The way the memory profiler works is driven by the notion of a snapshot. You take as many snapshots as you want to see what the allocation looks like at the various stages of your applications lifespan.

The memory profiler has a Summary screen, All objects screen and All classes screen.

Figure 5: All classes screen

allclasses.png

The memory profiler is useful as it highlights expensive types that will consume a fair amount of memory, although bytes are fairly trivial in small applications. If you have a type that will spawn 10 or so thousand objects then it's a different story.

Exporting results

There are two options when exporting the profiling data from a particular session: These are XML or HTML. The HTML version is simply a table that replicates the All Methods view found in the profiler application itself.

Figure 6: Results exported as HTML

html.png

Summary

This is an awesome tool, and ever since downloading it I have been using it on a daily basis and just love the detail of the reports. The snapshot feature for memory profiling can be a little strange at first but after playing with it for a while you will absolutely love it. The whole experience couldn't be better.

ANTS Profiler 3 is one of my favorite all time tools - definitely recommended if your job entails producing highly optimized code - this is a must have!

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Granville Barnett

Sorry, no bio is available

This author has published 32 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category


Developing a Hello World Java Application and Deploying it in Windows Azure - Part I
This article demonstrates how to install Windows Azure Plugin for Eclipse, create a Hello World appl...
Android for .NET Developers - Building a Twitter Client
In this article, I'll discuss the features and capabilities required by an Android application to ta...
Ref and Out (The Inside Story)
Knowing the power of ref and out, a developer will certainly make full use of this feature of parame...
Developing a Hello World Java Application and Deploying it in Windows Azure - Part II
In this article we will see the steps involved in deploying the WAR created in the first part of thi...
Android for .NET Developers - Using Web Views
In this article, I'll show a native app that contains a web-based view. The great news is that HTML ...

You might also be interested in the following related blog posts


November's Toolbox Column Now Online read more
October's Toolbox Column Now Online read more
September's Toolbox Column Now Online read more
August's Toolbox Column Now Online read more
July's Toolbox Column Now Online read more
Load Testing vs. Profiling read more
An Overview of Wrox Series read more
AjaxView Javascript profiling read more
Due Diligence and Code Comments read more
The Joy of Code Reviews read more
Top
 
 
 

Please login to rate or to leave a comment.

Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.