JIT hooks
There are several hooks in the pypyjit
module that may help you withunderstanding what’s pypy’s JIT doing while running your program. Thereare three functions related to that coming from the pypyjit
module:
setcompile_hook
(_callable, operations=True)- Set a compiling hook that will be called each time a loop is compiled.
The callable will be called with the pypyjit.JitLoopInfo
object.Refer to it’s documentation for details.
Note that jit hook is not reentrant. It means that if the codeinside the jit hook is itself jitted, it will get compiled, but thejit hook won’t be called for that.
if operations=False, no list of operations will be available. Usefulif the hook is supposed to be very lighweight.
setabort_hook
(_hook)- Set a hook (callable) that will be called each time there is tracingaborted due to some reason.
The hook will be invoked with the siagnture:hook(jitdriver_name, greenkey, reason, oplist)
Reason is a string, the meaning of other arguments is the sameas attributes on JitLoopInfo object
get_stats_snapshot
()- Get the jit status in the specific moment in time. Note that thisis eager - the attribute access is not lazy, if you need new statsyou need to call this function again. You might want to call
enable_debug
to get more information. It returns an instanceofJitInfoSnapshot
- class
JitInfoSnapshot
A class describing current snapshot. Usable attributes:
counters
- internal JIT integer counterscounter_times
- internal JIT float counters, notably time spentTRACING and in the JIT BACKENDloop_run_times
- counters for number of times loops are run, onlyworks whenenable_debug
is called.
- class
JitLoopInfo
A class containing information about the compiled loop. Usable attributes:
operations
- list of operations, if requestedjitdriver_name
- the name of jitdriver associated with this loopgreenkey
- a key at which the loop got compiled (e.g. code position,is_being_profiled, pycode tuple for python jitdriver)loop_no
- loop cardinal numberbridge_no
- id of the fail descrtype
- “entry bridge”, “loop” or “bridge”asmaddr
- an address in raw memory where assembler residesasmlen
- length of raw memory with assembler associated