• 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: default avatarTony Jones <tonyj@suse.de>
    Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
    Tested-by: default 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    9acd16ab
Name
Last commit
Last update
..
c++ Loading commit data...
cs-etm-decoder Loading commit data...
include Loading commit data...
intel-pt-decoder Loading commit data...
libunwind Loading commit data...
scripting-engines Loading commit data...
Build Loading commit data...
PERF-VERSION-GEN Loading commit data...
annotate.c Loading commit data...
annotate.h Loading commit data...
arm-spe-pkt-decoder.c Loading commit data...
arm-spe-pkt-decoder.h Loading commit data...
arm-spe.c Loading commit data...
arm-spe.h Loading commit data...
auxtrace.c Loading commit data...
auxtrace.h Loading commit data...
block-range.c Loading commit data...
block-range.h Loading commit data...
bpf-loader.c Loading commit data...
bpf-loader.h Loading commit data...
bpf-prologue.c Loading commit data...
bpf-prologue.h Loading commit data...
branch.c Loading commit data...
branch.h Loading commit data...
build-id.c Loading commit data...
build-id.h Loading commit data...
cache.h Loading commit data...
call-path.c Loading commit data...
call-path.h Loading commit data...
callchain.c Loading commit data...
callchain.h Loading commit data...
cgroup.c Loading commit data...
cgroup.h Loading commit data...
cloexec.c Loading commit data...
cloexec.h Loading commit data...
color.c Loading commit data...
color.h Loading commit data...
comm.c Loading commit data...
comm.h Loading commit data...
compress.h Loading commit data...
config.c Loading commit data...
config.h Loading commit data...
counts.c Loading commit data...
counts.h Loading commit data...
cpumap.c Loading commit data...
cpumap.h Loading commit data...
cs-etm.c Loading commit data...
cs-etm.h Loading commit data...
ctype.c Loading commit data...
data-convert-bt.c Loading commit data...
data-convert-bt.h Loading commit data...
data-convert.h Loading commit data...
data.c Loading commit data...
data.h Loading commit data...
db-export.c Loading commit data...
db-export.h Loading commit data...
debug.c Loading commit data...
debug.h Loading commit data...
demangle-java.c Loading commit data...
demangle-java.h Loading commit data...
demangle-rust.c Loading commit data...
demangle-rust.h Loading commit data...
drv_configs.c Loading commit data...
drv_configs.h Loading commit data...
dso.c Loading commit data...
dso.h Loading commit data...
dump-insn.c Loading commit data...
dump-insn.h Loading commit data...
dwarf-aux.c Loading commit data...
dwarf-aux.h Loading commit data...
dwarf-regs.c Loading commit data...
env.c Loading commit data...
env.h Loading commit data...
event.c Loading commit data...
event.h Loading commit data...
evlist.c Loading commit data...
evlist.h Loading commit data...
evsel.c Loading commit data...
evsel.h Loading commit data...
evsel_fprintf.c Loading commit data...
expr.h Loading commit data...
expr.y Loading commit data...
find-map.c Loading commit data...
genelf.c Loading commit data...
genelf.h Loading commit data...
genelf_debug.c Loading commit data...
generate-cmdlist.sh Loading commit data...
get_current_dir_name.c Loading commit data...
group.h Loading commit data...
header.c Loading commit data...
header.h Loading commit data...
help-unknown-cmd.c Loading commit data...
help-unknown-cmd.h Loading commit data...
hist.c Loading commit data...
hist.h Loading commit data...
intel-bts.c Loading commit data...
intel-bts.h Loading commit data...
intel-pt.c Loading commit data...
intel-pt.h Loading commit data...
intlist.c Loading commit data...
intlist.h Loading commit data...
jit.h Loading commit data...
jitdump.c Loading commit data...
jitdump.h Loading commit data...
kvm-stat.h Loading commit data...
levenshtein.c Loading commit data...
levenshtein.h Loading commit data...
llvm-utils.c Loading commit data...
llvm-utils.h Loading commit data...
lzma.c Loading commit data...
machine.c Loading commit data...
machine.h Loading commit data...
map.c Loading commit data...
map.h Loading commit data...
mem-events.c Loading commit data...
mem-events.h Loading commit data...
mem2node.c Loading commit data...
mem2node.h Loading commit data...
memswap.c Loading commit data...
memswap.h Loading commit data...
metricgroup.c Loading commit data...
metricgroup.h Loading commit data...
mmap.c Loading commit data...
mmap.h Loading commit data...
namespaces.c Loading commit data...
namespaces.h Loading commit data...
ordered-events.c Loading commit data...
ordered-events.h Loading commit data...
parse-branch-options.c Loading commit data...
parse-branch-options.h Loading commit data...
parse-events.c Loading commit data...
parse-events.h Loading commit data...
parse-events.l Loading commit data...
parse-events.y Loading commit data...
parse-regs-options.c Loading commit data...
parse-regs-options.h Loading commit data...
path.c Loading commit data...
path.h Loading commit data...
perf-hooks-list.h Loading commit data...
perf-hooks.c Loading commit data...
perf-hooks.h Loading commit data...
perf_regs.c Loading commit data...
perf_regs.h Loading commit data...
pmu.c Loading commit data...
pmu.h Loading commit data...
pmu.l Loading commit data...
pmu.y Loading commit data...
print_binary.c Loading commit data...
print_binary.h Loading commit data...
probe-event.c Loading commit data...
probe-event.h Loading commit data...
probe-file.c Loading commit data...
probe-file.h Loading commit data...
probe-finder.c Loading commit data...
probe-finder.h Loading commit data...
pstack.c Loading commit data...
pstack.h Loading commit data...
python-ext-sources Loading commit data...
python.c Loading commit data...
rb_resort.h Loading commit data...
rblist.c Loading commit data...
rblist.h Loading commit data...
record.c Loading commit data...
rwsem.c Loading commit data...
rwsem.h Loading commit data...
s390-cpumsf-kernel.h Loading commit data...
s390-cpumsf.c Loading commit data...
s390-cpumsf.h Loading commit data...
sane_ctype.h Loading commit data...
session.c Loading commit data...
session.h Loading commit data...
setns.c Loading commit data...
setup.py Loading commit data...
smt.c Loading commit data...
smt.h Loading commit data...
sort.c Loading commit data...
sort.h Loading commit data...
srccode.c Loading commit data...
srccode.h Loading commit data...
srcline.c Loading commit data...
srcline.h Loading commit data...
stat-display.c Loading commit data...
stat-shadow.c Loading commit data...
stat.c Loading commit data...
stat.h Loading commit data...
strbuf.c Loading commit data...
strbuf.h Loading commit data...
strfilter.c Loading commit data...
strfilter.h Loading commit data...
string.c Loading commit data...
string2.h Loading commit data...
strlist.c Loading commit data...
strlist.h Loading commit data...
svghelper.c Loading commit data...
svghelper.h Loading commit data...
symbol-elf.c Loading commit data...
symbol-minimal.c Loading commit data...
symbol.c Loading commit data...
symbol.h Loading commit data...
symbol_fprintf.c Loading commit data...
syscalltbl.c Loading commit data...
syscalltbl.h Loading commit data...
target.c Loading commit data...
target.h Loading commit data...
term.c Loading commit data...
term.h Loading commit data...
thread-stack.c Loading commit data...
thread-stack.h Loading commit data...
thread.c Loading commit data...
thread.h Loading commit data...
thread_map.c Loading commit data...
thread_map.h Loading commit data...
time-utils.c Loading commit data...
time-utils.h Loading commit data...
tool.h Loading commit data...
top.c Loading commit data...
top.h Loading commit data...
trace-event-info.c Loading commit data...
trace-event-parse.c Loading commit data...
trace-event-read.c Loading commit data...
trace-event-scripting.c Loading commit data...
trace-event.c Loading commit data...
trace-event.h Loading commit data...
trigger.h Loading commit data...
tsc.c Loading commit data...
tsc.h Loading commit data...
units.c Loading commit data...
units.h Loading commit data...
unwind-libdw.c Loading commit data...
unwind-libdw.h Loading commit data...
unwind-libunwind-local.c Loading commit data...
unwind-libunwind.c Loading commit data...
unwind.h Loading commit data...
usage.c Loading commit data...
util-cxx.h Loading commit data...
util.c Loading commit data...
util.h Loading commit data...
values.c Loading commit data...
values.h Loading commit data...
vdso.c Loading commit data...
vdso.h Loading commit data...
xyarray.c Loading commit data...
xyarray.h Loading commit data...
zlib.c Loading commit data...