ANTS Profiler™
How to profile a desktop application that hosts the .NET runtime
This article will explain how you can use ANTS Performance Profiler 4 (APP4) to profile the performance of a native desktop application that hosts the .NET Common Language Runtime (CLR). Native or unmanaged applications can call .NET components using COM callable wrappers (More details at http://msdn2.microsoft.com/en-us/library/ms973802.aspx).
Typical examples of this type of development are .NET Visual Studio add-ins, managed code extensions for Word and Excel, and managed code add-ins for SQL Server Management Studio.
We will see that profiling these types of application is just as straightforward with APP4 as profiling standard .NET applications.
Setting up the performance profiler
We will work through setting up a profiling session to profile the performance of a SQL Server Management Studio add-in. SQL Server Management Studio is a native application which hosts the CLR which, in turn, allows it to execute managed code.
When starting APP4 you will be greeted by the Performance Profiler Settings dialog.

On the Performance Profiler Settings dialog box perform the following steps:
- Set the application type to profile to .NET desktop application.
- Set the .NET desktop application combo box to point to the path where Management Studio is installed. On my machine it is located at C:\Programs\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWb.exe.
- Set the Profiling mode – we will use the default profiling mode.
- Set the Default timing display to CPU.
On the Performance Profiler Settings dialog select the Performance Counters tab.

Here, we can select any additional performance counters that we are interested in. For this scenario, we will only monitor the % Processor Time counter.
Starting the profiler
We have now set all the information needed to start profiling our add-in. So we can click Start Profiling.
At this point, Management Studio will start up, and we can connect to a server, then go into a query window and interact with our add-in. In this example, the add-in in question is SQL Prompt™, an intelligent code-completion and layout tool for MS SQL Server.

Getting results
During a profiling session, you can interact with the profiler whilst your application is still being profiled, and obtain results by selecting areas of the timeline.
Press the Stop Profiling button.
This will close Management Studio, and all the performance profiling data collected for the add-in will be displayed in the APP4 user interface.

We can investigate the results in exactly the same fashion as we would with any .NET application. This will quickly allow us to spot any big bottlenecks or areas of inefficient code.
Other applications
Exactly the same approach will work with all other hosting applications. For example, to profile a Visual Studio .NET add-in, the key step is to enter the full path to devenv.exe as the .NET application that you want to profile (typically C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe for VS.NET 2005).
Conclusion
This short article should get you going with optimizing the performance of your managed applications that are hosted in other applications.





