Microsoft’s CLRProfiler is a tool you can use to analyze the behavior of your managed applications. I’ve used it a number of times and it can be pretty helpfull in profiling your apps. According to Microsoft, these are its strengths and weaknesses:

Highlights



  • CLRProfiler is a tool that is focused on analyzing what is going on in the garbage collector heap:

    • Which methods allocate which types of objects?
    • Which objects survive?
    • What is on the heap?
    • What keeps objects alive?

  • Additionally:

    • The call graph feature lets you see who is calling whom how often.
    • Which methods, classes, modules get pulled in by whom

  • The tool can profile applications, services, and ASP.NET pages.
  • The tool can control profiling:

    • You can add comments that can also serve as time markers.
    • You can turn allocation and call logging on or off.
    • 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.

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.

Internals overview



  • The tool uses the public profiling interfaces that the CLR exposes. These work by loading a COM component 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 (such as “C:WINDOWSTemppipe_1636.log”).
  • The GUI (Windows Forms application) analyzes the log file and displays various views.

I also found this video about the CLRProfiler, but I haven’t had time to watch it yet…