• Home
  • Raw
  • Download

Lines Matching +full:monitor +full:- +full:script +full:- +full:pid

1 .. highlight:: shell-session
14 domain-specific languages allowing a user to write scripts which:
16 - filter which processes are to be observed
17 - gather data from the processes of interest
18 - generate reports on the data
21 known as "probes", that can be observed by a DTrace or SystemTap script,
22 making it easier to monitor what the CPython processes on a system are
25 .. impl-detail::
34 ---------------------------
36 macOS comes with built-in support for DTrace. On Linux, in order to
42 $ yum install systemtap-sdt-devel
46 $ sudo apt-get install systemtap-sdt-dev
49 CPython must then be :option:`configured with the --with-dtrace option
50 <--with-dtrace>`:
52 .. code-block:: none
54 checking for --with-dtrace... yes
60 $ python3.6 -q &
61 $ sudo dtrace -l -P python$! # or: dtrace -l -m python3.6
64 29564 python18035 python3.6 _PyEval_EvalFrameDefault function-entry
65 29565 python18035 python3.6 dtrace_function_entry function-entry
66 29566 python18035 python3.6 _PyEval_EvalFrameDefault function-return
67 29567 python18035 python3.6 dtrace_function_return function-return
68 29568 python18035 python3.6 collect gc-done
69 29569 python18035 python3.6 collect gc-start
78 $ readelf -S ./python | grep .note.stapsdt
82 (with the :option:`--enable-shared` configure option), you
85 $ readelf -S libpython3.3dm.so.1.0 | grep .note.stapsdt
90 $ readelf -n ./python
108 Arguments: -4@%ebx
113 Arguments: -8@%rax
118 Arguments: 8@%rbp 8@%r12 -4@%eax
123 Arguments: 8@%rbp 8@%r12 -4@%eax
127 tracing hooks used by a SystemTap script.
131 --------------------
133 The following example DTrace script can be used to show the call/return
134 hierarchy of a Python script, only tracing within the invocation of
135 a function called "start". In other words, import-time function
138 .. code-block:: none
142 python$target:::function-entry
145 self->trace = 1;
148 python$target:::function-entry
149 /self->trace/
152 printf("%*s", self->indent, "");
154 self->indent++;
157 python$target:::function-return
158 /self->trace/
160 self->indent--;
162 printf("%*s", self->indent, "");
166 python$target:::function-return
169 self->trace = 0;
174 $ sudo dtrace -q -s call_stack.d -c "python3.6 script.py"
178 .. code-block:: none
180 156641360502280 function-entry:call_stack.py:start:23
181 156641360518804 function-entry: call_stack.py:function_1:1
182 156641360532797 function-entry: call_stack.py:function_3:9
183 156641360546807 function-return: call_stack.py:function_3:10
184 156641360563367 function-return: call_stack.py:function_1:2
185 156641360578365 function-entry: call_stack.py:function_2:5
186 156641360591757 function-entry: call_stack.py:function_1:1
187 156641360605556 function-entry: call_stack.py:function_3:9
188 156641360617482 function-return: call_stack.py:function_3:10
189 156641360629814 function-return: call_stack.py:function_1:2
190 156641360642285 function-return: call_stack.py:function_2:6
191 156641360656770 function-entry: call_stack.py:function_3:9
192 156641360669707 function-return: call_stack.py:function_3:10
193 156641360687853 function-entry: call_stack.py:function_4:13
194 156641360700719 function-return: call_stack.py:function_4:14
195 156641360719640 function-entry: call_stack.py:function_5:18
196 156641360732567 function-return: call_stack.py:function_5:21
197 156641360747370 function-return:call_stack.py:start:28
201 ------------------------
203 The low-level way to use the SystemTap integration is to use the static
207 For example, this SystemTap script can be used to show the call/return
208 hierarchy of a Python script:
210 .. code-block:: none
227 thread_indent(-1), funcname, filename, lineno);
233 show-call-hierarchy.stp \
234 -c "./python test.py"
238 .. code-block:: none
249 - time in microseconds since start of script
250 - name of executable
251 - PID of process
253 and the remainder indicates the call/return hierarchy as the script executes.
255 For a :option:`--enable-shared` build of CPython, the markers are contained within the
259 .. code-block:: none
265 .. code-block:: none
269 (assuming a :ref:`debug build <debug-build>` of CPython 3.6)
273 ------------------------
278 It is only triggered for pure-Python (bytecode) functions.
281 tracing script as positional arguments, which must be accessed using
295 exception). It is only triggered for pure-Python (bytecode) functions.
302 the equivalent of line-by-line tracing with a Python profiler. It is
343 -----------------
345 The higher-level way to use the SystemTap integration is to use a "tapset":
346 SystemTap's equivalent of a library, which hides some of the lower-level
349 Here is a tapset file, based on a non-shared build of CPython:
351 .. code-block:: none
354 Provide a higher-level wrapping around the function__entry and
379 It is only triggered for pure-Python (bytecode) functions.
385 ``return``, or via an exception). It is only triggered for pure-Python
390 --------
391 This SystemTap script uses the tapset above to more cleanly implement the
392 example given above of tracing the Python function-call hierarchy, without
395 .. code-block:: none
406 thread_indent(-1), funcname, filename, lineno);
410 The following script uses the tapset above to provide a top-like view of all
414 .. code-block:: none
420 fn_calls[pid(), filename, funcname, lineno] += 1;
426 "PID", "FILENAME", "LINE", "FUNCTION", "CALLS")
427 foreach ([pid, filename, funcname, lineno] in fn_calls- limit 20) {
429 pid, filename, lineno, funcname,
430 fn_calls[pid, filename, funcname, lineno]);