CLRProfiler
Peter Sollich
Common Language Runtime Performance Architect
Microsoft Corporation
October 2003, updated October 2005
1
Legal Information
This is a preliminary document and may be changed substantially prior to final commercial release of
the software described herein.
The information contained in this document represents the current view of Microsoft Corporation on
the issues discussed as of the date of publication. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft
cannot guarantee the accuracy of any information presented after the date of publication.
This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES,
EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the
rights under copyright, no part of this document may be reproduced, stored in or introduced into a
retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying,
recording, or otherwise), or for any purpose, without the express written permission of Microsoft
Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property
rights covering subject matter in this document. Except as expressly provided in any written license
agreement from Microsoft, the furnishing of this document does not give you any license to these
patents, trademarks, copyrights, or other intellectual property.
2003, 2007 Microsoft Corporation. All rights reserved.
Microsoft is a registered trademark of Microsoft Corporation in the United States and/or other
countries.
The names of actual companies and products mentioned herein may be the trademarks of their
respective owners.
2
Contents
Legal Information.......................................................................................................................2
Contents......................................................................................................................................3
Overview.....................................................................................................................................4
Highlights................................................................................................................................4
Lowlights...............................................................................................................................4
Changes in the new version....................................................................................................4
Internals overview...................................................................................................................5
CLRProfiler UI...........................................................................................................................6
The File Menu.........................................................................................................................7
Command-line interface..........................................................................................................7
Edit Menu................................................................................................................................9
Views......................................................................................................................................9
Summary...........................................................................................................................10
Histogram Allocated Types..............................................................................................13
Histogram Relocated Types..............................................................................................15
Objects by Address...........................................................................................................16
Histogram by Age.............................................................................................................19
Allocation Graph...............................................................................................................21
Assembly Graph................................................................................................................33
Function Graph.................................................................................................................33
Module Graph...................................................................................................................33
Class Graph.......................................................................................................................33
Heap Graph.......................................................................................................................34
Call Graph.........................................................................................................................40
Time Line..........................................................................................................................42
Comments.........................................................................................................................47
Call Tree View..................................................................................................................47
Common garbage collection problems and how they are reflected in the views......................52
Programs that allocate too much...........................................................................................53
Holding on to memory for too long......................................................................................64
Tracking down memory leaks...............................................................................................78
CLRProfiler API.......................................................................................................................92
Producing reports from the command line..............................................................................100
Some CLRProfiler Internals....................................................................................................103
Environment variables........................................................................................................103
Log file format....................................................................................................................104
FAQ.........................................................................................................................................107
3
Overview
CLRProfiler is a tool that you can use to analyze the behavior of your managed applications.
Like any such tool, it has specific strengths and weaknesses.
Highlights
CLRProfiler is a tool that is focused on analyzing what is going on in the garbage
collector heap:
o Which methods allocate which types of objects?
o Which objects survive?
o What is on the heap?
o What keeps objects alive?
Additionally:
o The call graph feature lets you see who is calling whom how often.
o Which methods, classes, modules get pulled in by whom
The tool can profile applications, services, and ASP.NET pages.
The profiled application can control profiling:
o You can add comments that can also serve as time markers.
o You can turn allocation and call logging on or off.
o You can trigger a heap dump.
The log files produced are self-contained – you do not need to save symbol files and
the like to later analyze the log file.
There is also a command-line interface allowing log files to be produced in batch
mode, and allowing you to produce text file reports.
Lowlights
CLRProfiler is an intrusive tool; seeing a 10 to 100x slowdown in the application
being profiled is not unusual. Therefore, it is not the right tool to find out where time
is spent – use other profilers for that.
Log files can get huge. By default, every allocation and every call is logged, which
can consume gigabytes of disk space. However, allocation and call logging can be
turned on and off selectively either by the application or in the CLRProfiler UI.
CLRProfiler cannot “attach” to an application that is already running.
Changes in the new version
There have been quite a few changes since the last version, including:
After profiling or loading a log file, a new Summary Page gives you an overview
about the behavior of the profiled application. From the summary page, you can open
the most popular views.
There are now many more command line options, allowing you to produce simple
reports without any mouse click in the GUI. This is primarily useful in automatic
testing.
CLRProfiler now also keeps track of GC handles, and so can be used to find GC
handle leaks.
CLRProfiler has been updated to support generics.
4
The interface between the CLR and CLRProfiler has been enhanced so that
CLRProfiler now has more exact information about the garbage collected heap - for
example, it now knows where the boundaries between generations are, or when
objects die, where before, it had to use heuristics to guess this information.
The heap graph view can now optionally show all reference paths to an object instance
or group of instances - this is sometimes useful while tracking down memory leaks.
The log file format has been enhanced to convey the additional information mentioned
above - for details see the "Log file format" section.
CLRProfiler now also works on x64 and IA64 systems.
CLRProfiler's support for profiling ASP.NET applications and managed services has
been improved so that in most cases, profiling works fine even when not running
under the SYSTEM account.
Internals overview
The tool uses the public profiling interfaces that the CLR exposes. These work by
loading a COM component (implemented by "profilerOBJ.dll") that then gets called
whenever a significant event happens – a method gets called, an object gets allocated,
a garbage collection gets triggered, and so on.
The COM component writes information about these events into a log file (with
names such as “C:\WINDOWS\Temp\pipe_1636.log”).
The GUI (CLRProfiler.exe - a Windows Forms application) analyzes the log file and
displays various views.
5