Get Started with Performance Profiling
dotTrace provides two methods for profiling your apps: performance and timeline. To some extent, both methods are interchangeable. Nevertheless, there are types of tasks where one or another profiling method is more suitable. For example, the performance profiling method described in this section is better suited for more straightforward "What is the slowest method" tasks, or for the tasks when you need to take an in-depth look at the line-by-line performance of a particular method or algorithm.
The timeline profiling method, in its turn, collects not only stack trace data but also the data about calls distribution in time. This method shows its best on issues where the order of events does matter: UI freezes, slow SQL requests, excessive garbage collections, and so on. For details on how to use timeline profiling, refer to the next tutorial.
Now, let's take a look at the simplest performance profiling workflow. For example, we have some application which does or does not have performance issues. So, all we want is to evaluate its performance, i.e. find out what methods take the most time.
Step 1. Running dotTrace
There are two ways to start profiling your application: you can either launch dotTrace as a standalone tool or from Visual Studio.
Running standalone dotTrace
This mode is ideal for applications where the original project or source code is not available or when you want to run dotTrace without having Visual Studio installed or launched. To run standalone dotTrace:
Start dotTrace from the Windows Start menu. This will run the dotTrace Home window.
Running dotTrace from Visual Studio
Run Visual Studio.
Open the solution you want to profile.
In the menu, choose.
Step 2. Configuring and running profiling sessionThe next step is to configure the profiling properties and run a profiling session.
In the left panel in New Session, select Local. This indicates, we want to profile the application located on this computer.
- In the central panel in Profile Application, select Standalone. Note that dotTrace is able to profile different kinds of applications including web apps hosted on IIS server, WCF services, and many others*.
- In the right panel, specify profiling options.
In Application, specify path to the application executable.
- In Profiling type, specify the profiling type.
This is by far the most important profiling option. You can choose among:
Sampling - the fastest method. It accurately measures calls time, but doesn't get data on number of calls. This profiling type allows you to quickly get a general idea of the application's performance.
Tracing - slower than Sampling (and due to this it cannot measure calls time precisely) but accurately measures how many times a particular method was called. Use this method when Sampling data is not enough, e.g. for evaluation of algorithms complexity.
Line-by-line - the slowest method that measures each line of code. The line-by-line profiling makes sense only when you already know what function causes issues and want to analyze each line of it.
Timeline - used to perform timeline profiling. Read about it in a separate tutorial.
Click Run to start profiling. dotTrace will attach to your application's process and start collecting performance data.
Step 3. Getting snapshots
Once you run the profiling session, dotTrace will run not only the profiled application, but also the so-called 'profiling controller' - a separate window used to control the profiling session - collect performance snapshots, detach from the profiled applications, and so on. Thus, the next step is to collect profiling data (or, in other words, take performance snapshot(s)) using the controller window.
Work with your application: run the functionality whose performance you want to check, perform a particular usage scenario, etc.
- Once you are sure that the collected profiling data is enough, click Get Snapshot and Wait in the controller window.
Close the profiled application. This will close the controller window as well.
Step 4. Analyzing snapshot data
After you close the profiled application, dotTrace will run a separate application - Performance Viewer. It allows you to analyze the collected performance data using a handy UI.
The UI consists of a number of views that allow you to look at the data from different angles:
You may want to start with Hot Spots. This view simply shows you the list of functions with the highest execution time. Use this view to find the slowest methods in just a glance.
If you want to perform a more thorough analysis, you can use other Performance Profiler views: Threads Tree, Call Tree, and Plain List.
Allows you to view and analyze threads activity in your application.
Call Tree shows you all method calls in all threads. Each top-level node represents a top-level function which was executed by a certain thread. Use this view to quickly get down to actual application activity:
Shows a plain list of methods. Allows you to thoroughly analyze a particular method.
Note that whenever you select a method, Performance Viewer shows you the actual code for this method based on information provided by your application's debugging symbols. If no source code is available, Performance Viewer will try to decompile the method from the assembly.
Once you've mastered these basics, learn the various techniques in analyzing profiler data. Performance Viewer includes great features like remote profiling, navigating through method calls, filtering and folding and estimating performance gains. Read about these and other features in particular sections of this guide.