1+ .. highlight :: shell-session
2+
13.. _instrumentation :
24
35===============================================
@@ -20,9 +22,6 @@ known as "probes", that can be observed by a DTrace or SystemTap script,
2022making it easier to monitor what the CPython processes on a system are
2123doing.
2224
23- .. I'm using ".. code-block:: c" for SystemTap scripts, as "c" is syntactically
24- the closest match that Sphinx supports
25-
2625.. impl-detail ::
2726
2827 DTrace markers are implementation details of the CPython interpreter.
@@ -40,14 +39,16 @@ development tools must be installed.
4039
4140On a Linux machine, this can be done via::
4241
43- yum install systemtap-sdt-devel
42+ $ yum install systemtap-sdt-devel
4443
4544or::
4645
47- sudo apt-get install systemtap-sdt-dev
46+ $ sudo apt-get install systemtap-sdt-dev
47+
4848
49+ CPython must then be configured ``--with-dtrace ``:
4950
50- CPython must then be configured ` --with-dtrace `::
51+ .. code-block :: none
5152
5253 checking for --with-dtrace... yes
5354
@@ -71,22 +72,18 @@ Python provider::
7172On Linux, you can verify if the SystemTap static markers are present in
7273the built binary by seeing if it contains a ".note.stapsdt" section.
7374
74- .. code-block :: bash
75+ ::
7576
7677 $ readelf -S ./python | grep .note.stapsdt
7778 [30] .note.stapsdt NOTE 0000000000000000 00308d78
7879
7980If you've built Python as a shared library (with --enable-shared), you
80- need to look instead within the shared library. For example:
81-
82- .. code-block :: bash
81+ need to look instead within the shared library. For example::
8382
8483 $ readelf -S libpython3.3dm.so.1.0 | grep .note.stapsdt
8584 [29] .note.stapsdt NOTE 0000000000000000 00365b68
8685
87- Sufficiently modern readelf can print the metadata:
88-
89- .. code-block :: bash
86+ Sufficiently modern readelf can print the metadata::
9087
9188 $ readelf -n ./python
9289
@@ -136,7 +133,7 @@ hierarchy of a Python script, only tracing within the invocation of
136133a function called "start". In other words, import-time function
137134invocations are not going to be listed:
138135
139- .. code-block :: c
136+ .. code-block :: none
140137
141138 self int indent;
142139
@@ -170,13 +167,13 @@ invocations are not going to be listed:
170167 self->trace = 0;
171168 }
172169
173- It can be invoked like this:
174-
175- .. code-block :: bash
170+ It can be invoked like this::
176171
177172 $ sudo dtrace -q -s call_stack.d -c "python3.6 script.py"
178173
179- The output looks like this::
174+ The output looks like this:
175+
176+ .. code-block :: none
180177
181178 156641360502280 function-entry:call_stack.py:start:23
182179 156641360518804 function-entry: call_stack.py:function_1:1
@@ -208,7 +205,7 @@ containing them.
208205For example, this SystemTap script can be used to show the call/return
209206hierarchy of a Python script:
210207
211- .. code-block :: c
208+ .. code-block :: none
212209
213210 probe process("python").mark("function__entry") {
214211 filename = user_string($arg1);
@@ -228,15 +225,15 @@ hierarchy of a Python script:
228225 thread_indent(-1), funcname, filename, lineno);
229226 }
230227
231- It can be invoked like this:
232-
233- .. code-block :: bash
228+ It can be invoked like this::
234229
235230 $ stap \
236231 show-call-hierarchy.stp \
237232 -c "./python test.py"
238233
239- The output looks like this::
234+ The output looks like this:
235+
236+ .. code-block :: none
240237
241238 11408 python(8274): => __contains__ in Lib/_abcoll.py:362
242239 11414 python(8274): => __getitem__ in Lib/os.py:425
@@ -325,7 +322,7 @@ details of the static markers.
325322
326323Here is a tapset file, based on a non-shared build of CPython:
327324
328- .. code-block :: c
325+ .. code-block :: none
329326
330327 /*
331328 Provide a higher-level wrapping around the function__entry and
@@ -369,7 +366,7 @@ This SystemTap script uses the tapset above to more cleanly implement the
369366example given above of tracing the Python function-call hierarchy, without
370367needing to directly name the static markers:
371368
372- .. code-block :: c
369+ .. code-block :: none
373370
374371 probe python.function.entry
375372 {
@@ -388,7 +385,7 @@ The following script uses the tapset above to provide a top-like view of all
388385running CPython code, showing the top 20 most frequently-entered bytecode
389386frames, each second, across the whole system:
390387
391- .. code-block :: c
388+ .. code-block :: none
392389
393390 global fn_calls;
394391
0 commit comments