| 1 |
A JIT-aware profiler |
| 2 |
==================== |
| 3 |
|
| 4 |
Goal: have a profiler which is aware of the PyPy JIT and which shows which |
| 5 |
percentage of the time have been spent in which loops. |
| 6 |
|
| 7 |
Long term goal: integrate the data collected by the profiler with the |
| 8 |
jitviewer. |
| 9 |
|
| 10 |
The idea is record an event in the PYPYLOG every time we enter and exit a loop |
| 11 |
or a bridge. |
| 12 |
|
| 13 |
Expected output |
| 14 |
---------------- |
| 15 |
|
| 16 |
[100] {jit-profile-enter |
| 17 |
loop1 # e.g. an entry bridge |
| 18 |
[101] jit-profile-enter} |
| 19 |
... |
| 20 |
[200] {jit-profile-enter |
| 21 |
loop0 # JUMP from loop1 to loop0 |
| 22 |
[201] jit-profile-enter} |
| 23 |
... |
| 24 |
[500] {jit-profile-exit |
| 25 |
loop0 # e.g. because of a failing guard |
| 26 |
[501] jit-profile-exit} |
| 27 |
|
| 28 |
In this example, the exiting from loop1 is implicit because we are entering |
| 29 |
loop0. So, we spent 200-100=100 ticks in the entry bridge, and 500-200=300 |
| 30 |
ticks in the actual loop. |
| 31 |
|
| 32 |
What to do about "inner" bridges? |
| 33 |
---------------------------------- |
| 34 |
|
| 35 |
"Inner bridges" are those bridges which jump back to the loop where they |
| 36 |
originate from. There are two possible ways of dealing with them: |
| 37 |
|
| 38 |
1. we ignore them: we record when we enter the loop, but not when we jump to |
| 39 |
a compiled inner bridge. The exit event will be recorded only in case of |
| 40 |
a non-compiled guard failure or a JUMP to another loop |
| 41 |
|
| 42 |
2. we record the enter/exit of each inner bridge |
| 43 |
|
| 44 |
The disadvantage of solution (2) is that there are certain loops which takes |
| 45 |
bridges at everty single iteration. So, in this case we would record a huge |
| 46 |
number of events, possibly adding a lot of overhead and thus making the |
| 47 |
profiled data useless. |
| 48 |
|
| 49 |
|
| 50 |
Detecting the enter to/exit from a loop |
| 51 |
---------------------------------------- |
| 52 |
|
| 53 |
Ways to enter: |
| 54 |
|
| 55 |
- just after the tracing/compilation |
| 56 |
|
| 57 |
- from the interpreter, if the loop has already been compiled |
| 58 |
|
| 59 |
- from another loop, via a JUMP operation |
| 60 |
|
| 61 |
- from a hot guard failure (which we ignore, in case we choose solution |
| 62 |
(1) above) |
| 63 |
|
| 64 |
- XXX: am I missing anything? |
| 65 |
|
| 66 |
Ways to exit: |
| 67 |
|
| 68 |
- guard failure (entering blackhole) |
| 69 |
|
| 70 |
- guard failure (jumping to a bridge) (ignored in case of solution (1)) |
| 71 |
|
| 72 |
- jump to another loop |
| 73 |
|
| 74 |
- XXX: am I missing anything? |
| 75 |
|
| 76 |
|
| 77 |
About call_assembler: I think that at the beginning, we should just ignore |
| 78 |
call_assembler: the time spent inside the call will be accounted to the loop |
| 79 |
calling it. |