History

perf script: Fix Python support when no libtraceevent

Python scripting can be used without libtraceevent. In particular, scripting for Intel PT does not use tracepoints, and so does not need libtraceevent support. Alter the build and employ conditional compilation to allow Python scripting without libtraceevent. Example: Before: $ ldd `which perf` | grep -i python $ ldd `which perf` | grep -i libtraceevent $ perf record -e intel_pt//u uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.031 MB perf.data ] $ perf script intel-pt-events.py |& head -3 Error: Couldn't find script `intel-pt-events.py' See perf script -l for available scripts. After: $ ldd `which perf` | grep -i python libpython3.10.so.1.0 => /lib/x86_64-linux-gnu/libpython3.10.so.1.0 (0x00007f4bac400000) $ ldd `which perf` | grep -i libtraceevent $ perf script intel-pt-events.py | head Intel PT Branch Trace, Power Events, Event Trace and PTWRITE Switch In 8021/8021 [000] 11234.097713404 0/0 perf-exec 8021/8021 [000] 11234.098041726 psb offset: 0x0 0 [unknown] ([unknown]) perf-exec 8021/8021 [000] 11234.098041726 cbr 45 freq: 4505 MHz (161%) 0 [unknown] ([unknown]) uname 8021/8021 [000] 11234.098082170 branches:uH tr strt 0 [unknown] ([unknown]) => 7f3a8b9422b0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) uname 8021/8021 [000] 11234.098082379 branches:uH tr end 7f3a8b9422b0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) => 0 [unknown] ([unknown]) uname 8021/8021 [000] 11234.098083629 branches:uH tr strt 0 [unknown] ([unknown]) => 7f3a8b9422b0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) uname 8021/8021 [000] 11234.098083629 branches:uH call 7f3a8b9422b3 _start+0x3 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) => 7f3a8b943050 _dl_start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) uname 8021/8021 [000] 11234.098083837 branches:uH tr end 7f3a8b943060 _dl_start+0x10 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) => 0 [unknown] ([unknown]) IPC: 0.01 (9/938) uname 8021/8021 [000] 11234.098084670 branches:uH tr strt 0 [unknown] ([unknown]) => 7f3a8b943060 _dl_start+0x10 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2)

Adrian Hunter committed 3 years ago

Commit 80c3a7d1 parent 4c290d49 files · +72 −30Browse files

Showing the changes to tools/perf/scripts/python (2 of 9 files). Show all

Unified · Split

2 files
  1. tools/perf/scripts/python/Perf-Trace-Util/Build +1 −1
  2. tools/perf/scripts/python/Perf-Trace-Util/Context.c +4 −0
tools/perf/scripts/python/Perf-Trace-Util/Build+1−1
@@ -1,3 +1,3 @@
1−perf-$(CONFIG_LIBTRACEEVENT) += Context.o
1+perf-y += Context.o
22
33 CFLAGS_Context.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs
tools/perf/scripts/python/Perf-Trace-Util/Context.c+4−0
@@ -59,6 +59,7 @@ static struct scripting_context *get_scripting_context(PyObject *args) · 58 unmodified lines
5959 return get_args(args, "context", NULL);
6060 }
6161
62+#ifdef HAVE_LIBTRACEEVENT
6263 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
6364 {
6465 struct scripting_context *c = get_scripting_context(args);
@@ -90,6 +91,7 @@ static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, · 25 unmodified lines
9091
9192 return Py_BuildValue("i", common_lock_depth(c));
9293 }
94+#endif
9395
9496 static PyObject *perf_sample_insn(PyObject *obj, PyObject *args)
9597 {
@@ -178,12 +180,14 @@ static PyObject *perf_sample_srccode(PyObject *obj, PyObject *args) · 82 unmodified lines
178180 }
179181
180182 static PyMethodDef ContextMethods[] = {
183+#ifdef HAVE_LIBTRACEEVENT
181184 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
182185 "Get the common preempt count event field value."},
183186 { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
184187 "Get the common flags event field value."},
185188 { "common_lock_depth", perf_trace_context_common_lock_depth,
186189 METH_VARARGS, "Get the common lock depth event field value."},
190+#endif
187191 { "perf_sample_insn", perf_sample_insn,
188192 METH_VARARGS, "Get the machine code instruction."},
189193 { "perf_set_itrace_options", perf_set_itrace_options,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t