|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
A code profiler is a software tool, implemented as a DLL, which is called by the runtime system during the execution of an image. The profiler receives notifications each time a function is entered or exited, as well as when other events occur that are of interest to the programmer. By gathering statistics on these events, a profiler can build a comprehensive picture of which routines used the most CPU time, when garbage collections occurred, if exceptions were thrown, and so on.
The runtime system connects a profiler to a process during process initialization. To determine what to do, the runtime system checks two environment variables: COR_ENABLE_PROFILING and COR_PROFILER.
If COR_ENABLE_PROFILING is absent or is set to the value 0, the runtime system will not connect the process to the profiler. Otherwise, the runtime system will connect the process to the profiler whose specified class identifier (CLSID) is the value of COR_PROFILER.
For example, the command line causes the runtime system to create an instance of the profiler COM class with this CLSID and connect it to the process.
The profiler must implement the ICorProfilerCallback interface, which the runtime system subsequently calls to apprise the profiler of interesting events.