You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/native.rst
+13-27Lines changed: 13 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,39 +10,25 @@ as a command line switch.
10
10
**NOTE** be sure to provide debugging symbols for your native functions, otherwise
11
11
you will not see the symbol name of your e.g. C program.
12
12
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
-
38
13
Technical Design
39
14
----------------
40
15
41
16
Native sampling utilizes ``libunwind`` in the signal handler to unwind the stack.
42
17
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
+
43
31
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.
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.
0 commit comments