NProfiler instructs the .NET runtime in the process to be profiled to load our profiler DLL and instantiate a class from this DLL. Our code can then respond to events in the .NET runtime, such as module loading, JIT compilation, garbage collection, etc. Our code can also create new .NET methods or inject instructions into existing methods (instrumentation). The profiler DLL then sends the collected profiling data back to the NProfiler UI via IPC or a network connection.
The .NET runtime loads a profiler DLL if specific environment variables are set.
NProfiler sets the following environment variables for profiled processes:
The COR_ environment variables are used by the old .NET Desktop runtime (up to .NET 4.*). The CORECLR_ variables are used by the new .NET Core runtime.
The environment variables are set in different ways depending on the profiled application type:
<environmentVariables> element in the global applicationHost.config file.If you select the application type “Attach to Running .NET 4+ Process”, no environment variables can be set because the process to be profiled is already running and the .NET runtime may already have been loaded. In this case, a message is sent to the target .NET process, which causes the .NET runtime to load our profiler DLL and instantiate the profiler callback class.