TN_1210: Using the performance explorer
Ian Huff, Software Design Engineer
Microsoft Corporation
Included with Visual Studio Team System Developer edition (and Suite edition) is a powerful new profiler that can help to isolate various performance problems in your native, managed and ASP.NET projects. The profiler has both sampling (take a snapshot of the program state on periodic cycles) and instrumentation (insert probes to capture all function entry and exit points) profiling modes to help you get the best profiling information for your specific scenario. This TechNote will take a deeper look at the Performance Explorer window, which is the central control point for controlling the profiler through the IDE.
If you have created a performance session already then the Performance Explorer window should already be open. If it is not, you can open it under the “View” menu in Visual Studio, or you can create or open a new performance session file (.psess file extension) which will automatically open the window for you. In the performance explorer you will see nodes for all the current performance sessions (you can have multiple performance sessions in a solution). Each session has two folders under it, one for “Targets” and one for “Reports.” At the top of the performance explorer window there are options to launch the performance wizard, to create a new performance session, to launch the currently active performance session, and a combo box to select either sampling mode or instrumentation.
In sampling mode the “Targets” folder contains all the items that you want to collect profiling data from, each item under the targets folder represents a project, an executable, a .DLL file or an ASP.net project. If the target icon has a green arrow on it, then that target is one that will be automatically launched when you start your profiling session. By right-clicking on a target you can choose to specify if it is a launch target or not, however for .DLL files you will not be able to specify them as launch targets as .DLL files cannot be directly launched. To add more binaries to a performance session, just right click on the “Targets” folder and select "Add Target Binary" (you can also add binaries from other projects in the solutions or from an ASP.NET web application). In sampling mode, you automatically collect data from all the binaries that you are attached to. But in instrumentation mode, you only collect data from the binaries that you chosen to instrument. You can select what binaries to instrument by right-clicking on them in the performance explorer and selecting “Instrument” from the context menu. Instrumented binaries have little 1s and 0s on the binary icon to indicate that they are to be instrumented when the performance session is launched. When using instrumentation, you want to limit the number of instrumented binaries to keep from being overwhelmed with data as in instrumentation mode data is collected on every function entry and exit. In the picture below, a small windows application that consumes a .dll file is being profiled in instrumentation mode. The application (.exe) is selected as a launch target, so when I run the performance session it will be started automatically. However, only the class library (.dll) is selected to be instrumented so, during the test run, the profiler will only collect data on that specific .dll and not from the .exe file. This type of limiting is important in getting useful data from instrumentation profiling.
.jpg)
As you run your performance sessions, you will create .vsp report files that contain the data for the profiling runs. These reports show up automatically under the “Reports” folder of the performance explorer. The default is that they are named after the solution, with a unique timestamp appended onto the end. In the property pages for the performance session you can change the default location to store these items and the default naming scheme. By double clicking on any report file, you can open it for analysis in the IDE. Also, by right-clicking on the “Reports” folder you can choose to add any previously created report files to the current session.
As I mentioned before, you can have more then one performance session for any given solution. In the performance explorer below I have both a sampling session and an instrumentation session open for my sample project. The session name that is bolded (Performance2.psess) is the currently active session, which is that one that will be run when the "Launch" button is pressed. To set an inactive session as the current session, just right-click on its name and select “Set As Current Session.” Each session has its own “Reports” and “Targets” folder and separate session properties. The combobox that controls profiling method (currently Sampling) is linked to the current session, so changing it to Instrumentation would change just Performance2.psess to use Instrumentation profiling instead of Sampling profiling. As you can see, in each session some application must be specified as a launch target. You cannot start up a performance session if you do not have some executable selected to launch.
.jpg)
The next button of interest in the performance explorer is the launch button. This is the button with the green arrow right next to the profiling method selection combobox. Pressing this button will launch the current performance session and collect data for a new performance report.
The final two buttons are the stop button and the sampling attach button to the right of the profiling mode combobox. The stop button will only be active when you are currently running a performance session. Pressing stop will cut off data collection and close down any running applications that you launched for that performance session. The attach button is used only when sampling mode is selected as the profiling method. In sampling mode you can attach and detach from currently running processes to collect data from them only for specific scenarios and without having to launch or close them.
Now you should know your way around the performance explorer a little better, which should help you when doing your profiling.