Skip to main content

Module profiler

Module profiler 

Source
Available on crate feature coreclr only.
Expand description

A minimal CoreCLR profiler, implemented as COM objects by hand.

Registered as a startup profiler (the host sets CORECLR_ENABLE_PROFILING=1, CORECLR_PROFILER={CLSID_STRING} and CORECLR_PROFILER_PATH to the .so that re-exports dll_get_class_object as DllGetClassObject), the runtime loads it and calls ICorProfilerCallback::Initialize, where we grab ICorProfilerInfo and ask to monitor JIT compilation and to enable ReJIT.

This is the registration layer. ReJIT (replacing a method’s IL with hao’s) and native code-address lookup (for patching machine code with iced) build on the ICorProfilerInfo captured here.

COM on Linux uses the C calling convention; every callback returns an HRESULT, so unused vtable slots share one stub that returns S_OK.

Structs§

Guid
A COM interface id / class id.

Constants§

CLSID_STRING
The string form of our profiler CLSID, for CORECLR_PROFILER.

Functions§

dll_get_class_object⚠
The entry CoreCLR looks up by name in the profiler library. A host re-exports it as DllGetClassObject.
native_code
The native code address and size of a method, for patching it in place (for example with iced). module_substring matches a loaded module’s name, and token is the method’s metadata token (mdMethodDef). Returns None until the method has been JIT-compiled.
watch_module
Log JITed methods of modules whose name contains substring (e.g. the game assembly). Without this, module loads are still logged but JITs are not.