.NET Debugging : Introduction to the Tools - CLR Profiler, Performance Counters

2/24/2013 6:38:21 PM

1. CLR Profiler

Usage scenarios:Memory Allocation Profiler
Download point:www.microsoft.com/downloads/details.aspx?FamilyId=A362781C-3870-43BE-8926-862B40AA0CD0&displaylang=en

The CLR Profiler is an invaluable tool when it comes to troubleshooting memory-related issues in .NET applications. It provides features such as

  • Heap statistics (including allocation graphs)

  • Garbage Collection Statistics

  • Garbage Collector Handle Statistics (including allocation graphs)

  • Garbage Collection Generation Sizes

  • Profiling Statistics

The installation process for the CLR Profiler is straightforward. The installation package comes in the form of a ZIP file. Simply extract the contents of the ZIP file to a specified folder location (default is C:\CLRProfiler). If you extract all the files from the ZIP file, you get both the x86 and x64 version of the tool. To launch CLR Profiler, simply run CLRProfiler.exe. The installation of the CLR Profiler is accompanied by the source code making modifications and enhancements readily available.

After the CLR Profiler is launched, a dialog appears that contains a number of options as shown in Figure 1.

Figure 1. CLR Profiler Start dialog

Clicking the Start Application button brings up a dialog where you can choose the application you want to profile. After an application and profiling action has been chosen, the CLR Profiler launches the application and starts collecting data. The CLR Profiler offers a number of different statistical views of the data collected. Figure 2 shows an example of a view when profiling the CLR Profiler itself.

Figure 2. Sample View when profiling the CLR Profiler

As can be seen in Figure 2, the CLR Profiler offers a very detailed view of the allocation history and hierarchical relationships in a given application run. We will look at the specifics of the different CLR Profiler views in upcoming chapters.

The data collected is output to a log file that is by default located in %windir%\Temp. The log filename takes the form


where <pid> is the process identifier of the process being profiled.

The CLR Profiler can also be started and controlled via the command line. Running the CLR Profiler using the /? switch opens a window with all the available options. For example, if I want to profile an application called hello.exe and log all profiling data to a log file named hello.log, I would use the command line

clrprofiler -o hello.log -p hello.exe

where the –o switch specifies the log filename and the –p switch specifies the executable to be profiled.

In subsequent chapters, we will utilize both the command line and user interface (UI) to illustrate the power of the CLR Profiler.

2. Performance Counters

Performance counters are an important part of the troubleshooting process. During the .NET framework installation process, a collection of performance counters is installed. These performance counters represent a goldmine of information when analyzing .NET application behavior. To view the performance counters, the Windows Performance Monitor can be used. Table 1 lists all the performance counter categories that are part of the .NET runtime.

Table 1. .NET 2.0 Performance Counters Categories
Performance Counter CategoryDescription
ExceptionsPerformance counters related to exceptions thrown by .NET applications
InteroperabilityPerformance counters related to a .NET application’s relationship to COM, COM+, and external libraries
Just-in-time CompilationPerformance counters related to the Just In Time (JIT) compiler
LoaderPerformance counters related to the loading of .NET entities (assemblies, types)
Lock and ThreadPerformance counters related to threads and locking behaviors
MemoryPerformance counters related to the garbage collector (GC) and memory utilization
NetworkingPerformance counters related to the data a .NET application sends and receives over the network
RemotingPerformance counters related to the remote objects that a .NET application uses
SecurityPerformance counters related to the security checks and balances that the .NET framework performs

Throughout the book, the .NET performance counters will be utilized to analyze .NET applications. Figure 3 shows an example of a performance counter view when ran on an instance of the CLR Profiler (CLRProfiler.exe).

Figure 3. Performance counter showing the total committed bytes in the CLR Profiler instance
Top 10
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
The latest Audi TT : New angles for TT
Era of million-dollar luxury cars
Game Review : Hearthstone - Blackrock Mountain
Game Review : Battlefield Hardline
Google Chromecast
Keyboards for Apple iPad Air 2 (part 3) - Logitech Ultrathin Keyboard Cover for iPad Air 2
Keyboards for Apple iPad Air 2 (part 2) - Zagg Slim Book for iPad Air 2
Keyboards for Apple iPad Air 2 (part 1) - Belkin Qode Ultimate Pro Keyboard Case for iPad Air 2
Michael Kors Designs Stylish Tech Products for Women
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
Popular Tags
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Exchange Server Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe Photoshop CorelDRAW X5 CorelDraw 10 windows Phone 7 windows Phone 8 Iphone