Skip to content

Commit 4b27051

Browse files
committed
update documentation
1 parent 1d9d23d commit 4b27051

1 file changed

Lines changed: 13 additions & 27 deletions

File tree

docs/native.rst

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,25 @@ as a command line switch.
1010
**NOTE** be sure to provide debugging symbols for your native functions, otherwise
1111
you will not see the symbol name of your e.g. C program.
1212

13-
In Program Activation
14-
---------------------
15-
16-
Whenever vmprof is enabled during the execution of a specific program part,
17-
sometimes it will not sample the python level frames that have already
18-
been entered. See the following example::
19-
20-
# myprogram.py
21-
...
22-
def func():
23-
vmporf.enable(fileno, ..., native=True)
24-
another_func()
25-
vmprof.disable()
26-
27-
If vmprof has never been activated before, the frames just before ``another_func()`` will
28-
not be recorded.
29-
30-
The technical reason for this behaviour is: The
31-
frame evaulation function is patched (e.g. it adds a trampoline to
32-
PyEval_EvalFrameEx on CPython 2.7). All frames that have been activated to that
33-
point, will not have a trampoline inserted, and thus will be ignored by the stack
34-
sampling. To overcome this issue, invoke the whole program from command line::
35-
36-
$ python -m vmprof ...
37-
3813
Technical Design
3914
----------------
4015

4116
Native sampling utilizes ``libunwind`` in the signal handler to unwind the stack.
4217

18+
Each stack frame is inspected until the frame evaluation function is encountered. Then the stack walking
19+
switches back to the traditional Python frame walking. Callbacks (Python frame -> ... C frame ... -> Python frame ->
20+
C frame)
21+
will not display intermediate native functions. It would give the impression that the first C frame was never called,
22+
but it will show the second C frame.
23+
24+
Earlier Implementation
25+
----------------------
26+
27+
Prior to 0.4.3 the following logic was implemented (see e.g. commit 3912330b509d).
28+
It was removed because it could not be implemented on Mac OS X
29+
(libunwind misses register/cancel functions for generated machine code).
30+
4331
To find the corresponding ``PyFrameObject`` during stack unwinding vmprof inserts a trampoline on CPython (called ``vmprof_eval``) and places it just before ``PyEval_EvalFrameEx``. It is a callee trampoline saving the ``PyFrameObject`` in the callee saved register ``%rbx``. On Python 3.6+ the frame evaluation `PEP 523`_ is utilized as trampoline.
4432

4533
.. _`PEP 523`: https://www.python.org/dev/peps/pep-0523/
4634

47-
Symbols that are exposed from CPython/PyPy internally are ignored and not contained in the resulting profile. During stack sampling, instruction pointers that point into the virtual memory region of CPython/PyPy are not recorded.
48-

0 commit comments

Comments
 (0)