Yesterday I had a chance to add some additional features to my home grown database explorer and code generator tool that is proving to be more and more useful in my projects. It had been awhile since I did any code profiling of it, so I decided to fire up Red Gate Software’s ANTS Profiler and take a peek under the covers. Note that this is my first time using ANTS, so it gave me a good opportunity to not only look at my application, but compare it to JetBrains’ dotTrace ( see JetBrains dotTrace – Profiling my Simple Winform Database Explorer and Code Generator ).
Summary View – Slow Performing Hot Spots
After you profile your code and take a snapshot of the data, ANTS brings up a nice summary window that shows you the slowest lines of code and methods in your application.
The “Time (sec.)” values are “Wall Clock” values, which is important to keep in mind when comparing these numbers to your own as well as other profilers. Line 267 mentioned above took 9 seconds, because I was interacting with the “New Project” dialog window, which accounts for a few seconds. As you click on the line numbers and methods mentioned above, ANTS gives you a view of the source code that contains the details.
Chatty Catty Database.LoadSchema() Method
I am interested in my chatty Database.LoadSchema() method and ANTS gives me the following details:
As one would expect, the interaction with the Database is consuming all the time here. This database is local to my PC, which means I am not hitting a lag from the network. The complete red bar is always the slowest line of code in the method.
View Connection Pooling in Action for Kicks
When you create a “New Project” from a remote server in my code generator, a dropdown list allows you to select a database from the remote server. The lists of databases is grabbed using SqlConnection.GetSchema(“databases”) and this is often the first time this connection is being used. Hence, you will see slower times when creating and opening the connection for the first time as there isn’t an open connection in the pool:
Here you see the effect of connection pooling when I use the connection a second time to do the same thing:
Filtering and Finding Methods
ANTS allows you to do a bit of filtering by allowing you to group code within its “All methods” tab. Here I am grouping code by “Namespace” which allows me to drilldown into the objects and methods of each Namespace. This makes it really, really easy to find the code you wish to analyze. And, of course, clicking on any of the methods will jump you right into the source code so you can take a more detailed look.
Viewing Methods Within Hierarchy
When you are looking at a method, you can quickly change views between the source code and the hierarchy:
This allows you to compare the various times in the parent, children, and method in question to help determine where the time is being eaten in the code. The parent delay is rather “deceiving,” because it includes me interacting with the “New Project” dialog. Given this information, I know that LoadSchema() is 10 times slower than its children, and that I need to take a better look inside the code that calls the “New Project” dialog to get a better feel as to what percentage of the time was actually interacting with the dialog.
Compared to JetBrains’ dotTrace
As mentioned above, I did a similar examination of my code using JetBrains’ dotTrace in the following post:
Overall, I found ANTS to be a better choice for me in code profiling my small code generator for the following reasons:
- ANTS allows me to manage multiple snapshots per project. For dotTrace, only 1 snapshot per project.
- ANTS has the option to only profile code that has source code ( my code ). When this is all you want, it is much, much, much faster to get shapshots of the data. dotTrace doesn’t have this option.
- ANTS provides hit counts and times within the source code, making it easy to view the code and see the profiling information. dotTrace has this information, but not in the source code.
- The “All methods” tab with “Group By” functionality in ANTS seems an easier solution to filtering and finding data than the show and hide filters and Find Function in dotTrace ( at least for my small project ).
- Although not discussed here, ANTS also does memory profiling. dotTrace only does code profiling at the moment.
ANTS is an easy-to-use code profiler for your .NET applications. The user interface allows you to easily find the slow performing parts of your application by providing a combination of summary, hierarchy, and source code views of your application. They have a free, 14 day trial if you want to try it yourself.