| 1 |
================================== |
| 2 |
VMProf: a profiler for RPython VMs |
| 3 |
================================== |
| 4 |
|
| 5 |
|
| 6 |
from rpython.rlib import rvmprof |
| 7 |
|
| 8 |
|
| 9 |
Your VM must have an interpreter for "code" objects, which can be |
| 10 |
of any RPython instance. |
| 11 |
|
| 12 |
Use this as a decorator on the mainloop of the interpreter, to tell vmprof |
| 13 |
when you enter and leave a "code" object: |
| 14 |
|
| 15 |
def vmprof_execute_code(name, get_code_fn, result_class=None): |
| 16 |
|
| 17 |
See its docstring in rvmprof.py. |
| 18 |
|
| 19 |
|
| 20 |
The class of code objects needs to be registered by calling the |
| 21 |
function ``rpython.rlib.rvmprof.register_code_object_class()`` |
| 22 |
(once, before translation). It is a global function in __init__.py, |
| 23 |
but see the docstring of the method in rvmprof.py. |
| 24 |
|
| 25 |
|
| 26 |
To support adding new code objects at run-time, whenever a code object is |
| 27 |
instantiated, call the function ``rpython.rlib.rvmprof.register_code()``. |
| 28 |
|
| 29 |
If you need JIT support, you also need to add a jitdriver method |
| 30 |
``get_unique_id(*greenkey)``, where you call |
| 31 |
``rpython.rlib.rvmprof.get_unique_code()``. |
| 32 |
|
| 33 |
|
| 34 |
Enable/disable the profiler at runtime with: |
| 35 |
|
| 36 |
def enable(fileno, interval): |
| 37 |
def disable(): |
| 38 |
|
| 39 |
The file descriptor must remain open until the profiler is disabled. |
| 40 |
The profiler must be disabled before the program exit, otherwise the |
| 41 |
file is incompletely written. |
| 42 |
|
| 43 |
You should close the file descriptor after disabling the profiler; it is |
| 44 |
not automatically closed. |