I have been creating a very simple database explorer in my spare time to reintroduce myself to winform development, which I haven't done in quite some time. The bare bones utility essentially just pulls the schema from the database of my choosing and then allows me to explore it as well as generate various business and data access classes, queries, and stored procedures. I will add to it over time, but the main goal here is just to do some winform development for a change.

SqlSultan Database Library
The application contains a simple library, called SqlSultan.Dll, that wraps the schema of a database into a simple object hierarchy. Although I have to change this because you don't want your object constructors doing this much work, you can create an object model for a database by simply passing a connection string into the constructor of the Database object:
Database db = new Database("connection string");
The library currently uses the new GetSchema function in ADO.NET 2.0 which I wanted to play with as well. In some cases, I will have to go around GetSchema for additional information.
As you can expect, the constructor calls a few functions to go out and load up the tables in the database and the tables then load up their columns. Because there is a lot going on in the code and it is very much Ad-Hoc Code, I decide to fire up JetBrains dotTrace to profile the construction of the database object hierarchy.
JetBrains dotTrace Demo
JetBrains has a demo of dotTrace that you can sit and watch on their website if you want to see a complete walkthrough on how to use it. I just want to cover the highlights on how one would use it to profile specific areas of your application.
dotTrace - Find Function
After profiling the application and taking a snapshot, I immediately went into the very useful Find Function feature of dotTrace that allows you to find the area you wish to investigate. In this case, I wanted the constructor of the Database Class in the SqlSultan Library:

Open in New View
When you select the appropriate function, dotTrace navigates and highlights the particular function call in the call tree. There may be several of these function calls within the tree and dotTrace will put clickable bookmarks ( similar to how ReSharper highlights warnings and errors in your code ) so you can easily navigate to each call in the snapshot. In my case there was only 1 call.
To make things easy, you can open a particular function call into a new tabbed view. This is awesome, because it allows you to navigate and view stats / source code for a particular area.

dotTrace Views
JetBrains dotTrace has 4 main ways to view the snapshot: Call Tree, Back Traces, Plain View, and Hot Spots. I was mainly interested in the Call Tree. Although, if the Database Class Constructor was being called from several places, the Back Traces is a great way to find out who is calling your functions and reversing through the Call Tree.

When you click on a particular entry in the Call Tree ( or any view for that matter ), the Source Code View also hops to the place in code.
Icons Help Indicate Amount of Time Spent in Functions
Initially I thought they were just eye candy, but dotTrace has some useful icons that help direct your attention as to which functions are actually consuming time. The icons become the visual indicator and Ctr + Shift + Left Arrow and Ctrl + Shift + Right Arrow allow you to move back and forth through the important nodes in the call tree and bypass functions that only delegate, for example.

Filters
If you still find yourself getting overwhelmed with various function calls that are of no interest, you can apply filters to the views that collapse and grey out "noise." You can create both Show and Hide Filters. In my case, I created a show filter that I briefly used during the investigation that only highlighted function calls within SqlSultan so I could better understand my code.

Profiling Results
JetBrains dotTrace helped me make 2 conclusions:
- The calls to GetSchema were the most time intensive, which is what I expected. The time used by my code was minimal in comparison.
- My code was poorly written. Rather than making separate schema calls to get the schema for each table one at a time, the tool would probably be better off getting all the schema from the database in 1 shot and then parsing it into the object model. I expected this as well. Avoid Chatty Interfaces Between the Tiers in Your Applications ;)
JetBrains dotTrace is Sweet - Love to See a Couple of Changes
Overall, I really enjoyed using dotTrace:
- The UI is really simple to use.
- The Find Function and ability to open new Views in tabs helps you focus on specific areas of your projects.
- The Show and Hide Filters allow you to focus on the code of interest within those specific views.
- Icon indicators in cooperation with certain keystrokes allow you to easily move back and forth within the call tree to find important nodes.
- Source Code Viewer helps you to visually see the code profiled.
- Back Traces helps you step backwards in the call tree to see who is calling the function in question.
- Hot Spots shows you which functions are consuming the most time in the view and Plain View gives you raw numbers as to number of calls, etc. when you need them.
Improvements:
- The application loads and saves snapshots, but doesn't allow me to save my tabbed views. This needs to be changed ASAP so I can save my work and come back and review it later with all my tabbed views intact.
- I recommend moving from a snapshot oriented interface to a project oriented interface, so I can associate multiple snapshots to a project.
- Show and Hide Filters are global across all applications you are profiling. It would be nice to be able to set project specific filters so that I don't have to reset filters according to which application I am profiling.
Conclusion
I need to spend a lot more time on my winform development :), and if you are in the market for a simple-to-use .NET profiler for both winform and web applications, JetBrains dotTrace is really nice.
Posted by David Hayden ( .NET Developer )
Related Information: .NET Tools, Code Generators, O/R Mappers