Enabling Profiling

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.

set Cor_Profiler={32E2F4DA-1BEA-47ea-88F9-C5DAF691C94A}

The profiler must implement the ICorProfilerCallback interface, which the runtime system subsequently calls to apprise the profiler of interesting events.

See Also

Debugging and Profiling | Enabling JIT-attach Debugging | Making an Image Easier to Debug