• Tony Jones's avatar
    perf script python: Add trace_context extension module to sys.modules · 9acd16ab
    Tony Jones authored
    [ Upstream commit cc437642 ]
    
    In Python3, the result of PyModule_Create (called from
    scripts/python/Perf-Trace-Util/Context.c) is not automatically added to
    sys.modules.  See: https://bugs.python.org/issue4592
    
    Below is the observed behavior without the fix:
    
      # ldd /usr/bin/perf | grep -i python
    	libpython3.6m.so.1.0 => /usr/lib64/libpython3.6m.so.1.0 (0x00007f8e1dfb2000)
    
      # perf record /bin/false
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.015 MB perf.data (17 samples) ]
    
      # perf script -g python | cat
      generated Python script: perf-script.py
    
      # perf script -s ./perf-script.py
      Traceback (most recent call last):
        File "./perf-script.py", line 18, in <module>
          from perf_trace_context import *
      ModuleNotFoundError: No module named 'perf_trace_context'
      Error running python script ./perf-script.py
      #
    
    Committer notes:
    
    To build with python3 use:
    
      $ make -C tools/perf PYTHON=python3
    
    Use a non-const variable to pass the 'name' arg to
    PyImport_AppendInittab(), as python2.6 has that as 'char *', which ends
    up trowing this in some environments:
    
       CC       /tmp/build/perf/util/parse-branch-options.o
      util/scripting-engines/trace-event-python.c: In function 'python_start_script':
      util/scripting-engines/trace-event-python.c:1520:2: error: passing argument 1 of 'PyImport_AppendInittab' discards 'const' qualifier from pointer target type [-Werror]
        PyImport_AppendInittab("perf_trace_context", initfunc);
        ^
      In file included from /usr/include/python2.6/Python.h:130:0,
                       from util/scripting-engines/trace-event-python.c:22:
      /usr/include/python2.6/import.h:54:17: note: expected 'char *' but argument is of type 'const char *'
       PyAPI_FUNC(int) PyImport_AppendInittab(char *name, void (*initfunc)(void));
                       ^
      cc1: all warnings being treated as errors
    Signed-off-by: 's avatarTony Jones <tonyj@suse.de>
    Acked-by: 's avatarJiri Olsa <jolsa@kernel.org>
    Tested-by: 's avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Jaroslav Škarvada <jskarvad@redhat.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
    Cc: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
    Fixes: 66dfdff0 ("perf tools: Add Python 3 support")
    Link: http://lkml.kernel.org/r/20190124005229.16146-2-tonyj@suse.deSigned-off-by: 's avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
    9acd16ab
Name
Last commit
Last update
..
Documentation Loading commit data...
arch Loading commit data...
bench Loading commit data...
examples/bpf Loading commit data...
include/bpf Loading commit data...
jvmti Loading commit data...
pmu-events Loading commit data...
python Loading commit data...
scripts Loading commit data...
tests Loading commit data...
trace Loading commit data...
ui Loading commit data...
util Loading commit data...
.gitignore Loading commit data...
Build Loading commit data...
CREDITS Loading commit data...
MANIFEST Loading commit data...
Makefile Loading commit data...
Makefile.config Loading commit data...
Makefile.perf Loading commit data...
builtin-annotate.c Loading commit data...
builtin-bench.c Loading commit data...
builtin-buildid-cache.c Loading commit data...
builtin-buildid-list.c Loading commit data...
builtin-c2c.c Loading commit data...
builtin-config.c Loading commit data...
builtin-data.c Loading commit data...
builtin-diff.c Loading commit data...
builtin-evlist.c Loading commit data...
builtin-ftrace.c Loading commit data...
builtin-help.c Loading commit data...
builtin-inject.c Loading commit data...
builtin-kallsyms.c Loading commit data...
builtin-kmem.c Loading commit data...
builtin-kvm.c Loading commit data...
builtin-list.c Loading commit data...
builtin-lock.c Loading commit data...
builtin-mem.c Loading commit data...
builtin-probe.c Loading commit data...
builtin-record.c Loading commit data...
builtin-report.c Loading commit data...
builtin-sched.c Loading commit data...
builtin-script.c Loading commit data...
builtin-stat.c Loading commit data...
builtin-timechart.c Loading commit data...
builtin-top.c Loading commit data...
builtin-trace.c Loading commit data...
builtin-version.c Loading commit data...
builtin.h Loading commit data...
check-headers.sh Loading commit data...
command-list.txt Loading commit data...
design.txt Loading commit data...
perf-archive.sh Loading commit data...
perf-completion.sh Loading commit data...
perf-read-vdso.c Loading commit data...
perf-sys.h Loading commit data...
perf-with-kcore.sh Loading commit data...
perf.c Loading commit data...
perf.h Loading commit data...