Diagnostics used by the package ecosystem
This page documents "hooks" embedded in Julia that are primarily used by external tools. Many of these tools are designed to perform analyses that are too complicated to be made part of Julia proper.
SnoopCompile
SnoopCompile "snoops" on Julia's compiler to extract information for analysis about invalidations and type-inference. There are a few internals it uses for different purposes:
recording invalidations:
Base.StaticData.debug_method_invalidationandccall(:jl_debug_method_invalidation, ...): these record different modes of invalidation. Users of SnoopCompile will transiently turn these on when, e.g., loading packages. Each produces a standard log format; messing with the log format might require a complementary pull request to SnoopCompile. SnoopCompile will process these logs and generate trees of invalidated CodeInstances that are attributable to specific changes in the method tables or bindings.observing inference:
ccall(:jl_set_newly_inferred, ...)andccall(:jl_set_inference_entrance_backtraces, ...): these are used to understand how inference gets triggered. The main purpose is to allow performance diagnostics to understand sources of TTFX. The second of theseccalls records a backtrace on every entrance to type-inference, so that SnoopCompile can determine the caller of a dynamically-dispatched call. This is needed to attribute "cause" for new type inference.The
jl_set_inference_entrance_backtracesfunction accepts an array where inference entrance events will be recorded. Each inference event stores two consecutive array elements: first theCodeInstanceobject, then the backtrace representation. So for N inference events, the array will contain 2N elements arranged as:[ci₁, bt₁, ci₂, bt₂, ..., ciₙ, btₙ].Note that the backtrace elements
btᵢcontain raw backtrace data that typically needs to be processed usingstacktrace(Base._reformat_bt(btᵢ...)). to convert them into a usable stack trace format for analysis.