Debian Codegraph @

pypy/doc/jit-hooks.rst

raw
1 .. _jit-hooks:
2
3 JIT hooks
4 =========
5
6 There are several hooks in the ``pypyjit`` module that may help you with
7 understanding what pypy's JIT is doing while running your program:
8
9 .. function:: dont_trace_here(next_instr, is_being_profiled, pycode)
10
11 .. function:: get_jitcell_at_key(next_instr, is_being_profiled, pycode)
12
13 .. function:: get_stats_asmmemmgr()
14
15 Returns the raw memory currently used by the JIT backend,
16 as a pair (total_memory_allocated, memory_in_use).
17
18 .. function:: residual_call(callable, *args, **keywords)
19
20 For testing. Invokes callable(...), but without letting
21 the JIT follow the call.
22
23 .. function:: set_compile_hook(callable, operations=True)
24
25 Set a compiling hook that will be called each time a loop is compiled.
26
27 The callable will be called with the ``pypyjit.JitLoopInfo`` object.
28 Refer to it's documentation for details.
29
30 Note that jit hook is not reentrant. It means that if the code
31 inside the jit hook is itself jitted, it will get compiled, but the
32 jit hook won't be called for that.
33
34 if operations=False, no list of operations will be available. Useful
35 if the hook is supposed to be very lightweight.
36
37 .. function:: set_abort_hook(hook)
38
39 Set a hook (callable) that will be called each time there is tracing
40 aborted due to some reason.
41
42 The hook will be invoked with the siagnture:
43 ``hook(jitdriver_name, greenkey, reason, oplist)``
44
45 Reason is a string, the meaning of other arguments is the same
46 as attributes on JitLoopInfo object
47
48 .. function:: set_trace_too_long_hook(hook)
49
50 Set a hook (callable) that will be called each time we abort
51 tracing because the trace is too long.
52
53 The hook will be called with the signature:
54 ``hook(jitdriver_name, greenkey)``
55
56
57 .. function:: enable_debug()
58
59 Start recording debugging counters for ``get_stats_snapshot``
60
61 Currently disabled.
62
63 .. function:: disable_debug()
64
65 Stop recording debugging counters for ``get_stats_snapshot``
66
67 Currently disabled.
68
69 .. function:: get_stats_snapshot()
70
71 Get the jit status in the specific moment in time. Note that this
72 is eager - the attribute access is not lazy, if you need new stats
73 you need to call this function again. You might want to call
74 ``enable_debug`` to get more information. It returns an instance
75 of ``JitInfoSnapshot``
76
77 .. class:: JitInfoSnapshot
78
79 A class describing current snapshot. Usable attributes:
80
81 * ``counters`` - internal JIT integer counters
82
83 * ``counter_times`` - internal JIT float counters, notably time spent
84 TRACING and in the JIT BACKEND
85
86 * ``loop_run_times`` - counters for number of times loops are run, only
87 works when ``enable_debug`` is called.
88
89 .. class:: JitLoopInfo
90
91 A class containing information about the compiled loop. Usable attributes:
92
93 * ``operations`` - list of operations, if requested
94
95 * ``jitdriver_name`` - the name of jitdriver associated with this loop
96
97 * ``greenkey`` - a key at which the loop got compiled (e.g. code position,
98 is_being_profiled, pycode tuple for python jitdriver)
99
100 * ``loop_no`` - loop cardinal number
101
102 * ``bridge_no`` - id of the fail descr
103
104 * ``type`` - "entry bridge", "loop" or "bridge"
105
106 * ``asmaddr`` - an address in raw memory where assembler resides
107
108 * ``asmlen`` - length of raw memory with assembler associated
109
110 Resetting the JIT
111 =================
112
113 .. function:: releaseall()
114
115 Marks all current machine code objects as ready to release. They will be
116 released at the next GC (unless they are currently in use in the stack of
117 one of the threads). Doing ``pypyjit.releaseall(); gc.collect()`` is a
118 heavy hammer that forces the JIT roughly back to the state of a newly
119 started PyPy.
120
121 .. function:: set_param(*args, **keywords)
122
123 Configure the tunable JIT parameters, parameter names are listed in :ref:`Jit Help<jit-help>` :
124
125 * ``set_param(name=value, ...)`` as keyword arguments
126
127 * ``set_param("name=value,name=value")`` as a user-supplied string
128
129 * ``set_param("off")`` disable the jit
130
131 * ``set_param("default")`` restore all defaults
132