Profiling is a method of gathering performance data in any development or deployment scenario. This section is for developers and system administrators who want to gather information about application performance.
Tracking Performance Using the Performance Monitor (Perfmon.exe)
The Performance Monitor is the easiest tool to use to profile your .NET Framework application. The Performance Monitor graphically represents data found in the .NET Framework performance counters that are installed with the common language runtime and the Windows SDK. These counters can be used to monitor everything from memory management to just-in-time (JIT) compiler performance. They tell you about the resources your application uses, which is an indirect measure of your application's performance. Use these counters to understand how your application works internally.
To run Perfmon.exe on Windows Vista and later versions
At the command prompt, type perfmon. The Performance Monitor console appears.
In the Monitoring Tools folder, click Performance Monitor.
In the Performance Monitor toolbar, click the Add icon (the plus sign), if it is present. If it is not present, right-click in the monitor window and select the Add Counters option.
This opens the Add Counters dialog box. The Available counters list box displays the available performance objects. There are a number of predefined objects for .NET Framework applications, including those for memory management (.NET CLR Memory), interoperability (.NET CLR Interop), exception handling (.NET CLR Exceptions), and multithreading (.NET CLR LocksAndThreads). Each performance object includes a number of individual performance counters. For a list of the performance counters available in Performance Monitor, see Performance Counters.
Select the check box next to a performance object's name to view the list of individual performance counters that it supports.
Click the performance counter you want to view.
In the Instances of selected object list box, click <All instances> to specify that you want to monitor the performance counter for the common language runtime globally (that is, on a system-wide basis).
In the Instances of selected object list box, click an application name to monitor the performance counter for that application.
To differentiate multiple versions of the runtime, or to disambiguate multiple applications with the same name, you must also modify a registry key. For more information, see Performance Counters and In-Process Side-By-Side Applications.
When new performance counters are installed while the Performance console is running, stop and restart the Performance console to make the new counters visible.
If you want to profile an assembly that exists in a zone or on a remote share, make sure that the remote assembly has full trust on the computer that runs the performance counters. If the assembly does not have sufficient trust, the performance counters will not work. For information about granting trust to different zones, see Caspol.exe (Code Access Security Policy Tool).
On systems on which the .NET Framework 4 is installed, the Performance Monitor may not display data for performance counters in some categories, such as .NET CLR Data and .NET CLR Networking, for applications that were developed using .NET Framework 1.1. If this is the case, you can configure Performance Monitor to display this data by adding the <forcePerformanceCounterUniqueSharedMemoryReads> element to the application's configuration file.
Reading and Creating Performance Counters Programmatically
The .NET Framework provides classes you can use to programmatically access the same performance information that is available in the Performance console. You can also use these classes to create custom performance counters. The following table describes some of the performance monitoring classes that are provided in the .NET Framework.
|System.Diagnostics.PerformanceCounter||Represents a Windows performance counter component. Use this class to read existing predefined or custom counters and publish (write) performance data to custom counters.|
|System.Diagnostics.PerformanceCounterCategory||Provides several methods for interacting with counters and categories of counters on the computer.|
|System.Diagnostics.PerformanceCounterInstaller||Specifies an installer for the
|System.Diagnostics.PerformanceCounterType||Specifies the formula to calculate the
Submit and view feedback for