perf/core improvements and fixes
Subsystems (5)
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit c978b9460fe1d4a1e1effa0abd6bd69b18a098a8:
Merge tag 'perf-core-for-mingo-5.1-20190225' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2019-02-28 08:29:50 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-5.1-20190307
for you to fetch changes up to b8f7d86b5849ea7bb84bddc0345a3799049764d4:
perf data: Force perf_data__open|close zero data->file.path (2019-03-06 18:21:00 -0300)
----------------------------------------------------------------
perf bpf:
Arnaldo Carvalho de Melo:
- Automatically add BTF ELF markers to 'perf trace' BPF programs, so that tools such as 'bpftool map dump' can pretty print map keys and values.
perf c2c:
Jiri Olsa:
- Fix report for empty NUMA node.
perf diff:
Jin Yao:
- Support --time, --cpu, --pid and --tid filter options.
perf probe:
Arnaldo Carvalho de Melo:
- Clarify error message about not finding kernel modules debuginfo.
perf record:
Jiri Olsa:
- Fixup probing for max attr.precise_ip.
perf trace:
Arnaldo Carvalho de Melo:
- Add missing %s lost in the 'msg_flags' recvmmsg arg when adding prefix suppression logic.
perf annotate:
Arnaldo Carvalho de Melo:
- Calculate the max instruction name, align column to that, removing the hardcoded max 6 chars and cope with instructions with names longer than that, such as vpmovmskb, vpcmpeqb, etc.
kernel:
Song Liu:
- Consider events with attr.bpf_event set as side-band.
Gustavo A. R. Silva:
- Mark expected switch fall-through in perf_event_parse_addr_filter().
Libraries:
Jiri Olsa:
- Fix leaks and double frees on error paths.
libtraceevent:
Tony Jones:
- Fix buffer overflow in arg_eval().
python scripting:
Tony Jones:
- More python3 fixes.
Trivial:
Yang Wei:
- Remove needless extra semicolon in clang C++ glue code.
Intel PT/BTS:
Adrian Hunter:
- Improve auxtrace address filter error message when there is no DSO.
- Fix divide by zero when TSC is not available.
- Further improvements to the export to sqlite/posgresql python scripts and to the GUI sqlviewer, exporting 'parent_id' so that we have enable the creation of call trees.
Andi Kleen:
- Generalize function to copy from thread addr space from intel-bts code.
----------------------------------------------------------------
Adrian Hunter (10):
perf auxtrace: Improve address filter error message when there is no DSO perf intel-pt: Fix divide by zero when TSC is not available
perf db-export: Add calls parent_id to enable creation of call trees
perf scripts python: export-to-sqlite.py: Export calls parent_id
perf scripts python: export-to-postgresql.py: Fix invalid input syntax for integer error perf scripts python: export-to-postgresql.py: Export calls parent_id
perf scripts python: exported-sql-viewer.py: Factor out TreeWindowBase perf scripts python: exported-sql-viewer.py: Improve TreeModel abstraction perf scripts python: exported-sql-viewer.py: Factor out CallGraphModelBase perf scripts python: exported-sql-viewer.py: Add call tree
Andi Kleen (1):
perf thread: Generalize function to copy from thread addr space from intel-bts code
Arnaldo Carvalho de Melo (4):
perf probe: Clarify error message about not finding kernel modules debuginfo perf beauty msg_flags: Add missing %s lost when adding prefix suppression logic perf bpf: Automatically add BTF ELF markers
perf annotate: Calculate the max instruction name, align column to that
Gustavo A. R. Silva (1):
perf: Mark expected switch fall-through
Jin Yao (4):
perf time-utils: Refactor time range parsing code perf diff: Support --time filter option perf diff: Support --cpu filter option perf diff: Support --pid/--tid filter options
Jiri Olsa (7):
perf c2c: Fix c2c report for empty numa node
perf hist: Add error path into hist_entry__init perf hist: Fix memory leak of srcline
perf tools: Read and store caps/max_precise in perf_pmu perf evsel: Probe for precise_ip with simple attr perf session: Fix double free in perf_data__close perf data: Force perf_data__open|close zero data->file.path
Song Liu (1):
perf, bpf: Consider events with attr.bpf_event as side-band events
Tony Jones (6):
tools lib traceevent: Fix buffer overflow in arg_eval perf script python: Remove mixed indentation
perf script python: Add Python3 support to futex-contention.py perf script python: add Python3 support to check-perf-trace.py perf script python: Add Python3 support to event_analyzing_sample.py perf script python: Add Python3 support to intel-pt-events.py
Yang Wei (1):
perf clang: Remove needless extra semicolon
kernel/events/core.c | 4 +- tools/lib/traceevent/event-parse.c | 2 +- tools/perf/Documentation/perf-diff.txt | 56 ++++ tools/perf/arch/arm64/annotate/instructions.c | 2 +- tools/perf/arch/s390/annotate/instructions.c | 2 +- tools/perf/builtin-c2c.c | 8 +- tools/perf/builtin-diff.c | 168 +++++++++- tools/perf/builtin-report.c | 38 +-- tools/perf/builtin-script.c | 39 +-- tools/perf/include/bpf/bpf.h | 8 +- tools/perf/scripts/python/check-perf-trace.py | 76 ++--- tools/perf/scripts/python/compaction-times.py | 8 +- .../perf/scripts/python/event_analyzing_sample.py | 48 +-- tools/perf/scripts/python/export-to-postgresql.py | 16 +- tools/perf/scripts/python/export-to-sqlite.py | 12 +- tools/perf/scripts/python/exported-sql-viewer.py | 354 ++++++++++++++++----- .../perf/scripts/python/failed-syscalls-by-pid.py | 38 +-- tools/perf/scripts/python/futex-contention.py | 10 +- tools/perf/scripts/python/intel-pt-events.py | 60 ++-- tools/perf/scripts/python/mem-phys-addr.py | 7 +- tools/perf/scripts/python/net_dropmonitor.py | 2 +- tools/perf/scripts/python/netdev-times.py | 12 +- tools/perf/scripts/python/sched-migration.py | 6 +- tools/perf/scripts/python/sctop.py | 13 +- tools/perf/scripts/python/stackcollapse.py | 2 +- tools/perf/scripts/python/syscall-counts-by-pid.py | 47 ++- tools/perf/scripts/python/syscall-counts.py | 31 +- tools/perf/trace/beauty/msg_flags.c | 2 +- tools/perf/util/annotate.c | 74 +++-- tools/perf/util/annotate.h | 7 +- tools/perf/util/auxtrace.c | 3 +- tools/perf/util/c++/clang.cpp | 2 +- tools/perf/util/data.c | 4 +- tools/perf/util/db-export.c | 15 +- tools/perf/util/db-export.h | 3 +- tools/perf/util/evlist.c | 25 +- tools/perf/util/evsel.c | 8 - tools/perf/util/hist.c | 51 +-- tools/perf/util/intel-bts.c | 20 +- tools/perf/util/intel-pt.c | 2 + tools/perf/util/pmu.c | 14 + tools/perf/util/pmu.h | 1 + tools/perf/util/probe-event.c | 9 +- .../util/scripting-engines/trace-event-python.c | 8 +- tools/perf/util/session.c | 4 +- tools/perf/util/thread-stack.c | 16 +- tools/perf/util/thread-stack.h | 6 +- tools/perf/util/thread.c | 23 ++ tools/perf/util/thread.h | 3 + tools/perf/util/time-utils.c | 51 ++- tools/perf/util/time-utils.h | 6 + 51 files changed, 978 insertions(+), 448 deletions(-)
Test results:
The first ones are container based builds of tools/perf with and without libelf support. Where clang is available, it is also used to build perf with/without libelf, and building with LIBCLANGLLVM=1 (built-in clang) with gcc and clang when clang and its devel libraries are installed.
The objtool and samples/bpf/ builds are disabled now that I'm switching from using the sources in a local volume to fetching them from a http server to build it inside the container, to make it easier to build in a container cluster. Those will come back later.
Several are cross builds, the ones with -x-ARCH and the android one, and those may not have all the features built, due to lack of multi-arch devel packages, available and being used so far on just a few, like debian:experimental-x-{arm64,mipsel}.
The 'perf test' one will perform a variety of tests exercising tools/perf/util/, tools/lib/{bpf,traceevent,etc}, as well as run perf commands with a variety of command line event specifications to then intercept the sys_perf_event syscall to check that the perf_event_attr fields are set up as expected, among a variety of other unit tests.
Then there is the 'make -C tools/perf build-test' ones, that build tools/perf/ with a variety of feature sets, exercising the build with an incomplete set of features as well as with a complete one. It is planned to have it run on each of the containers mentioned above, using some container orchestration infrastructure. Get in contact if interested in helping having this in place.
$ export PERF_TARBALL=http://192.168.124.1/perf/perf-5.0.0-rc8.tar.xz # dm 1 alpine:3.4 : Ok gcc (Alpine 5.3.0) 5.3.0 2 alpine:3.5 : Ok gcc (Alpine 6.2.1) 6.2.1 20160822 3 alpine:3.6 : Ok gcc (Alpine 6.3.0) 6.3.0 4 alpine:3.7 : Ok gcc (Alpine 6.4.0) 6.4.0 5 alpine:3.8 : Ok gcc (Alpine 6.4.0) 6.4.0 6 alpine:3.9 : Ok gcc (Alpine 8.2.0) 8.2.0 7 alpine:edge : Ok gcc (Alpine 8.2.0) 8.2.0 8 amazonlinux:1 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28) 9 amazonlinux:2 : Ok gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) 10 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 11 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 12 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 13 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23) 14 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) 15 clearlinux:latest : Ok gcc (Clear Linux OS for Intel Architecture) 8.2.1 20180502 16 debian:7 : Ok gcc (Debian 4.7.2-5) 4.7.2 17 debian:8 : Ok gcc (Debian 4.9.2-10+deb8u2) 4.9.2 18 debian:9 : Ok gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 19 debian:experimental : Ok gcc (Debian 8.2.0-17) 8.2.1 20190204 20 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 8.2.0-11) 8.2.0 21 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 8.2.0-11) 8.2.0 22 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 8.2.0-16) 8.2.0 23 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7) 24 fedora:21 : Ok gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) 25 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 26 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 27 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) 28 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 29 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1) 30 fedora:26 : Ok gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2) 31 fedora:27 : Ok gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6) 32 fedora:28 : Ok gcc (GCC) 8.2.1 20181215 (Red Hat 8.2.1-6) 33 fedora:29 : Ok gcc (GCC) 8.2.1 20181215 (Red Hat 8.2.1-6) 34 fedora:30 : Ok gcc (GCC) 9.0.1 20190203 (Red Hat 9.0.1-0.3) 35 fedora:rawhide : Ok gcc (GCC) 9.0.1 20190209 (Red Hat 9.0.1-0.4) 36 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 7.3.0-r3 p1.4) 7.3.0 37 mageia:5 : Ok gcc (GCC) 4.9.2 38 mageia:6 : Ok gcc (Mageia 5.5.0-1.mga6) 5.5.0 39 opensuse:13.2 : Ok gcc (SUSE Linux) 4.8.3 20140627 [gcc-4_8-branch revision 212064] 40 opensuse:15.0 : Ok gcc (SUSE Linux) 7.3.1 20180323 [gcc-7-branch revision 258812] 41 opensuse:15.1 : Ok gcc (SUSE Linux) 7.4.0 42 opensuse:42.1 : Ok gcc (SUSE Linux) 4.8.5 43 opensuse:42.2 : Ok gcc (SUSE Linux) 4.8.5 44 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5 45 opensuse:tumbleweed : Ok gcc (SUSE Linux) 8.2.1 20190103 [gcc-8-branch revision 267549] 46 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23.0.1) 47 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36.0.1) 48 ubuntu:12.04.5 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 49 ubuntu:14.04.4 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4 50 ubuntu:14.04.4-x-linaro-arm64 : Ok aarch64-linux-gnu-gcc (Linaro GCC 5.5-2017.10) 5.5.0 51 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609 52 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 53 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 54 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 55 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 56 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 57 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 58 ubuntu:17.10 : Ok gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0 59 ubuntu:18.04 : Ok gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 60 ubuntu:18.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04) 7.3.0 61 ubuntu:18.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04) 7.3.0 62 ubuntu:18.04-x-m68k : Ok m68k-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 63 ubuntu:18.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 64 ubuntu:18.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 65 ubuntu:18.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 66 ubuntu:18.04-x-riscv64 : Ok riscv64-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 67 ubuntu:18.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 68 ubuntu:18.04-x-sh4 : Ok sh4-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 69 ubuntu:18.04-x-sparc64 : Ok sparc64-linux-gnu-gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0 70 ubuntu:18.10 : Ok gcc (Ubuntu 8.2.0-7ubuntu1) 8.2.0 71 ubuntu:19.04 : Ok gcc (Ubuntu 8.2.0-20ubuntu1) 8.2.0 72 ubuntu:19.04-x-alpha : Ok alpha-linux-gnu-gcc (Ubuntu 8.2.0-20ubuntu1) 8.2.0 73 ubuntu:19.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 8.2.0-20ubuntu1) 8.2.0 74 ubuntu:19.04-x-hppa : Ok hppa-linux-gnu-gcc (Ubuntu 8.2.0-20ubuntu1) 8.2.0 #
# uname -a
Linux quaco 5.0.0+ #1 SMP Thu Mar 7 10:32:55 -03 2019 x86_64 x86_64 x86_64 GNU/Linux
# git log --oneline -1
b8f7d86b5849 perf data: Force perf_data__open|close zero data->file.path
# perf version --build-options
perf version 5.0.rc8.gb8f7d8
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
glibc: [ on ] # HAVE_GLIBC_SUPPORT
gtk2: [ on ] # HAVE_GTK2_SUPPORT
syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
libbfd: [ on ] # HAVE_LIBBFD_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
# perf test
1: vmlinux symtab matches kallsyms : Ok
2: Detect openat syscall event : Ok
3: Detect openat syscall event on all cpus : Ok
4: Read samples using the mmap interface : Ok
5: Test data source output : Ok
6: Parse event definition strings : Ok
7: Simple expression parser : Ok
8: PERF_RECORD_* events & perf_sample fields : Ok
9: Parse perf pmu format : Ok
10: DSO data read : Ok
11: DSO data cache : Ok
12: DSO data reopen : Ok
13: Roundtrip evsel->name : Ok
14: Parse sched tracepoints fields : Ok
15: syscalls:sys_enter_openat event fields : Ok
16: Setup struct perf_event_attr : Ok
17: Match and link multiple hists : Ok
18: 'import perf' in python : Ok
19: Breakpoint overflow signal handler : Ok
20: Breakpoint overflow sampling : Ok
21: Breakpoint accounting : Ok
22: Watchpoint :
22.1: Read Only Watchpoint : Skip
22.2: Write Only Watchpoint : Ok
22.3: Read / Write Watchpoint : Ok
22.4: Modify Watchpoint : Ok
23: Number of exit events of a simple workload : Ok
24: Software clock events period values : Ok
25: Object code reading : Ok
26: Sample parsing : Ok
27: Use a dummy software event to keep tracking : Ok
28: Parse with no sample_id_all bit set : Ok
29: Filter hist entries : Ok
30: Lookup mmap thread : Ok
31: Share thread mg : Ok
32: Sort output of hist entries : Ok
33: Cumulate child hist entries : Ok
34: Track with sched_switch : Ok
35: Filter fds with revents mask in a fdarray : Ok
36: Add fd to a fdarray, making it autogrow : Ok
37: kmod_path__parse : Ok
38: Thread map : Ok
39: LLVM search and compile :
39.1: Basic BPF llvm compile : Ok
39.2: kbuild searching : Ok
39.3: Compile source for BPF prologue generation : Ok
39.4: Compile source for BPF relocation : Ok
40: Session topology : Ok
41: BPF filter :
41.1: Basic BPF filtering : Ok
41.2: BPF pinning : Ok
41.3: BPF prologue generation : Ok
41.4: BPF relocation checker : Ok
42: Synthesize thread map : Ok
43: Remove thread map : Ok
44: Synthesize cpu map : Ok
45: Synthesize stat config : Ok
46: Synthesize stat : Ok
47: Synthesize stat round : Ok
48: Synthesize attr update : Ok
49: Event times : Ok
50: Read backward ring buffer : Ok
51: Print cpu map : Ok
52: Probe SDT events : Ok
53: is_printable_array : Ok
54: Print bitmap : Ok
55: perf hooks : Ok
56: builtin clang support : Skip (not compiled in)
57: unit_number__scnprintf : Ok
58: mem2node : Ok
59: x86 rdpmc : Ok
60: Convert perf time to TSC : Ok
61: DWARF unwind : Ok
62: x86 instruction decoder - new instructions : Ok
63: x86 bp modify : Ok
64: probe libc's inet_pton & backtrace it with ping : Ok
65: Use vfs_getname probe to get syscall args filenames : Ok
66: Add vfs_getname probe to get syscall args filenames : Ok
67: Check open filename arg using perf trace + vfs_getname: Ok $ make -C tools/perf build-test
make: Entering directory '/home/acme/git/perf/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_with_babeltrace_O: make LIBBABELTRACE=1
make_debug_O: make DEBUG=1
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_no_libpython_O: make NO_LIBPYTHON=1
make_no_demangle_O: make NO_DEMANGLE=1
make_pure_O: make
make_no_backtrace_O: make NO_BACKTRACE=1
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_no_libnuma_O: make NO_LIBNUMA=1
make_perf_o_O: make perf.o
make_install_bin_O: make install-bin
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_no_libaudit_O: make NO_LIBAUDIT=1
make_no_libunwind_O: make NO_LIBUNWIND=1
make_no_newt_O: make NO_NEWT=1
make_no_libperl_O: make NO_LIBPERL=1
make_no_libbpf_O: make NO_LIBBPF=1
make_no_gtk2_O: make NO_GTK2=1
make_doc_O: make doc
make_with_clangllvm_O: make LIBCLANGLLVM=1
make_cscope_O: make cscope
make_static_O: make LDFLAGS=-static
make_no_libelf_O: make NO_LIBELF=1
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_no_libbionic_O: make NO_LIBBIONIC=1
make_clean_all_O: make clean all
make_install_O: make install
make_tags_O: make tags
make_install_prefix_O: make install prefix=/tmp/krava
make_util_map_o_O: make util/map.o
make_minimal_O: make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_help_O: make help
make_no_auxtrace_O: make NO_AUXTRACE=1
make_no_slang_O: make NO_SLANG=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$Arnaldo Carvalho de Melo
maintainerPATCH 1/35 perf, bpf: Consider events with attr.bpf_event as side-band events
From: Song Liu <[email protected]>
Events with attr.bpf_event set should be considered as side-band events, as they carry information about BPF programs.
--- kernel/events/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/events/core.c +2 -1
@@ -4238,7 +4238,8 @@ static bool is_sb_event(struct perf_event *event)if (attr->mmap || attr->mmap_data || attr->mmap2 || attr->comm || attr->comm_exec || attr->task || attr->ksymbol || - attr->context_switch) + attr->context_switch || + attr->bpf_event)return true;return false; }
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 2/35 perf probe: Clarify error message about not finding kernel modules debuginfo
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
'perf probe' supports using just the kernel module name, but that will work only when the module is loaded, or using the full pathname to the file with the DWARF debug info, but the warning was cryptic:
Before:
# perf probe -m cls_flower -L fl_change
Failed to find the path for cls_flower: No such file or directory
Error: Failed to show lines.
#After:
# perf probe -m cls_flower -L fl_change
Module cls_flower is not loaded, please specify its full path name.
Error: Failed to show lines.
# perf probe -m /lib/modules/5.0.0-rc7+/kernel/net/sched/cls_flower.ko -L fl_change | head -7
<fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0>
0 static int fl_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca,
void **arg, bool ovr, struct netlink_ext_ack *extack)
4 {
5 struct cls_fl_head *head = rtnl_dereference(tp->root);
#The behaviour doesn't change when the module is loaded:
# modprobe cls_flower
# perf probe -m cls_flower -L fl_change | head -7
<fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0>
0 static int fl_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca,
void **arg, bool ovr, struct netlink_ext_ack *extack)
4 {
5 struct cls_fl_head *head = rtnl_dereference(tp->root);
#--- tools/perf/util/probe-event.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/util/probe-event.c +6 -3
@@ -472,9 +472,12 @@ static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi,strcpy (reason,"(unknown)" ); }else dso__strerror_load (dso, reason,STRERR_BUFSIZE ); -if (!silent) -pr_err ("Failed to find the path for %s: %s\n" , - module ?:"kernel" , reason); +if (!silent) { +if (module) +pr_err ("Module %s is not loaded, please specify its full path name.\n" , module); +else +pr_err ("Failed to find the path for the kernel: %s\n" , reason); + }return NULL ; } path = dso->long_name;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 3/35 tools lib traceevent: Fix buffer overflow in arg_eval
In reply to Arnaldo Carvalho de MeloFrom: Tony Jones <[email protected]>
Fix buffer overflow observed when running perf test.
The overflow is when trying to evaluate "1ULL << (64 - 1)" which is resulting in -9223372036854775808 which overflows the 20 character buffer.
If is possible this bug has been reported before but I still don't see any fix checked in:
See: https://www.spinics.net/lists/linux-perf-users/msg07714.html
--- tools/lib/traceevent/event-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +1 -1
@@ -2457,7 +2457,7 @@ static int arg_num_eval(struct tep_print_arg *arg, long long *val)static char *arg_eval (struct tep_print_arg *arg) {long long val; -static char buf[20 ]; +static char buf[24 ];switch (arg->type) {case TEP_PRINT_ATOM :
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 4/35 perf: Mark expected switch fall-through
In reply to Arnaldo Carvalho de MeloFrom: "Gustavo A. R. Silva" <[email protected]>
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.
This patch fixes the following warning:
kernel/events/core.c: In function ‘perf_event_parse_addr_filter’:
kernel/events/core.c:9154:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
kernel = 1;
~~~~~~~^~~
kernel/events/core.c:9156:3: note: here
case IF_SRC_FILEADDR:
^~~~Warning level 3 was used: -Wimplicit-fallthrough=3
This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.
--- kernel/events/core.c | 1 + 1 file changed, 1 insertion(+)
kernel/events/core.c +1 -0
@@ -9175,6 +9175,7 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,case IF_SRC_KERNELADDR :case IF_SRC_KERNEL : kernel =1 ; +/* fall through */ case IF_SRC_FILEADDR :case IF_SRC_FILE :
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 5/35 perf time-utils: Refactor time range parsing code
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Jiri points out that we don't need any time checking and time string parsing if the --time option is not set. That makes sense.
This patch refactors the time range parsing code, move the duplicated code from perf report and perf script to time_utils and check if --time option is set before parsing the time string. This patch is no logic change expected. So the usage of --time is same as before.
For example:
Select the first and second 10% time slices:
perf report --time 10%/1,10%/2
perf script --time 10%/1,10%/2
Select the slices from 0% to 10% and from 30% to 40%:
perf report --time 0%-10%,30%-40%
perf script --time 0%-10%,30%-40%
Select the time slices from timestamp 3971 to 3973
perf report --time 3971,3973
perf script --time 3971,3973
Committer testing:
Using the above examples, check before and after to see if it remains the same:
$ perf record -F 10000 -- find . -name "*.[ch]" -exec cat {} + > /dev/null
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 1.626 MB perf.data (42392 samples) ]
$
$ perf report --time 10%/1,10%/2 > /tmp/report.before.1
$ perf script --time 10%/1,10%/2 > /tmp/script.before.1
$ perf report --time 0%-10%,30%-40% > /tmp/report.before.2
$ perf script --time 0%-10%,30%-40% > /tmp/script.before.2
$ perf report --time 180457.375844,180457.377717 > /tmp/report.before.3
$ perf script --time 180457.375844,180457.377717 > /tmp/script.before.3For example, the 3rd test produces this slice:
$ cat /tmp/script.before.3
cat 3147 180457.375844: 2143 cycles:uppp: 7f79362590d9 cfree@GLIBC_2.2.5+0x9 (/usr/lib64/libc-2.28.so)
cat 3147 180457.375986: 2245 cycles:uppp: 558b70f3d86e [unknown] (/usr/bin/cat)
cat 3147 180457.376012: 2164 cycles:uppp: 7f7936257430 _int_malloc+0x8c0 (/usr/lib64/libc-2.28.so)
cat 3147 180457.376140: 2921 cycles:uppp: 558b70f3a554 [unknown] (/usr/bin/cat)
cat 3147 180457.376296: 2844 cycles:uppp: 7f7936258abe malloc+0x4e (/usr/lib64/libc-2.28.so)
cat 3147 180457.376431: 2717 cycles:uppp: 558b70f3b0ca [unknown] (/usr/bin/cat)
cat 3147 180457.376667: 2630 cycles:uppp: 558b70f3d86e [unknown] (/usr/bin/cat)
cat 3147 180457.376795: 2442 cycles:uppp: 7f79362bff55 read+0x15 (/usr/lib64/libc-2.28.so)
cat 3147 180457.376927: 2376 cycles:uppp: ffffffff9aa00163 [unknown] ([unknown])
cat 3147 180457.376954: 2307 cycles:uppp: 7f7936257438 _int_malloc+0x8c8 (/usr/lib64/libc-2.28.so)
cat 3147 180457.377116: 3091 cycles:uppp: 7f7936258a70 malloc+0x0 (/usr/lib64/libc-2.28.so)
cat 3147 180457.377362: 2945 cycles:uppp: 558b70f3a3b0 [unknown] (/usr/bin/cat)
cat 3147 180457.377517: 2727 cycles:uppp: 558b70f3a9aa [unknown] (/usr/bin/cat)
$Install 'coreutils-debuginfo' to see cat's guts (symbols), but then, the above chunk translates into this 'perf report' output:
$ cat /tmp/report.before.3
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 13 of event 'cycles:uppp' (time slices: 180457.375844,180457.377717)
# Event count (approx.): 33552
#
# Overhead Command Shared Object Symbol
# ........ ....... ................ ......................
#
17.69% cat libc-2.28.so [.] malloc
14.53% cat cat [.] 0x000000000000586e
13.33% cat libc-2.28.so [.] _int_malloc
8.78% cat cat [.] 0x00000000000023b0
8.71% cat cat [.] 0x0000000000002554
8.13% cat cat [.] 0x00000000000029aa
8.10% cat cat [.] 0x00000000000030ca
7.28% cat libc-2.28.so [.] read
7.08% cat [unknown] [k] 0xffffffff9aa00163
6.39% cat libc-2.28.so [.] cfree@GLIBC_2.2.5 #
# (Tip: Order by the overhead of source file name and line number: perf report -s srcline) #
$
Now lets see after applying this patch, nothing should change:
$ perf report --time 10%/1,10%/2 > /tmp/report.after.1 $ perf script --time 10%/1,10%/2 > /tmp/script.after.1 $ perf report --time 0%-10%,30%-40% > /tmp/report.after.2 $ perf script --time 0%-10%,30%-40% > /tmp/script.after.2 $ perf report --time 180457.375844,180457.377717 > /tmp/report.after.3 $ perf script --time 180457.375844,180457.377717 > /tmp/script.after.3 $ diff -u /tmp/report.before.1 /tmp/report.after.1 $ diff -u /tmp/script.before.1 /tmp/script.after.1 $ diff -u /tmp/report.before.2 /tmp/report.after.2 --- /tmp/report.before.2 2019-03-01 11:01:53.526094883 -0300 +++ /tmp/report.after.2 2019-03-01 11:09:18.231770467 -0300 @@ -352,5 +352,5 @@
#
-# (Tip: Generate a script for your data: perf script -g <lang>) +# (Tip: Treat branches as callchains: perf report --branch-history)
#
$ diff -u /tmp/script.before.2 /tmp/script.after.2 $ diff -u /tmp/report.before.3 /tmp/report.after.3 --- /tmp/report.before.3 2019-03-01 11:03:08.890045588 -0300 +++ /tmp/report.after.3 2019-03-01 11:09:40.660224002 -0300 @@ -22,5 +22,5 @@
#
-# (Tip: Order by the overhead of source file name and line number: perf report -s srcline) +# (Tip: List events using substring match: perf list <keyword>)
#
$ diff -u /tmp/script.before.3 /tmp/script.after.3 $
Cool, just the 'perf report' tips changed, QED.
--- tools/perf/builtin-report.c | 38 ++++++--------------------- tools/perf/builtin-script.c | 39 ++++++--------------------- tools/perf/util/time-utils.c | 51 +++++++++++++++++++++++++++++++++++- tools/perf/util/time-utils.h | 6 +++++ 4 files changed, 72 insertions(+), 62 deletions(-)
tools/perf/builtin-report.c +8 -30
@@ -1375,36 +1375,13 @@ int cmd_report(int argc, const char **argv)if (symbol__init (&session->header.env) <0 ) goto error; - report.ptime_range =perf_time__range_alloc (report.time_str, - &report.range_size); -if (!report.ptime_range) { - ret = -ENOMEM ; - goto error; - } - -if (perf_time__parse_str (report.ptime_range, report.time_str) !=0 ) { -if (session->evlist->first_sample_time ==0 && - session->evlist->last_sample_time ==0 ) { -pr_err ("HINT: no first/last sample time found in perf data.\n" -"Please use latest perf binary to execute 'perf record'\n" -"(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); - ret = -EINVAL ; - goto error; - } - - report.range_num =perf_time__percent_parse_str ( - report.ptime_range, report.range_size, - report.time_str, - session->evlist->first_sample_time, - session->evlist->last_sample_time); - -if (report.range_num <0 ) { -pr_err ("Invalid time string\n" ); - ret = -EINVAL ; +if (report.time_str) { + ret =perf_time__parse_for_ranges (report.time_str, session, + &report.ptime_range, + &report.range_size, + &report.range_num); +if (ret <0 ) goto error; - } - }else { - report.range_num =1 ; } if (session->tevent.pevent &&
@@ -1426,7 +1403,8 @@ int cmd_report(int argc, const char **argv) ret =0 ; error: -zfree (&report.ptime_range); +if (report.ptime_range) +zfree (&report.ptime_range);perf_session__delete (session);return ret;
tools/perf/builtin-script.c +8 -31
@@ -3699,37 +3699,13 @@ int cmd_script(int argc, const char **argv)if (err <0 ) goto out_delete; - script.ptime_range =perf_time__range_alloc (script.time_str, - &script.range_size); -if (!script.ptime_range) { - err = -ENOMEM ; - goto out_delete; - } - -/* needs to be parsed after looking up reference time */ -if (perf_time__parse_str (script.ptime_range, script.time_str) !=0 ) { -if (session->evlist->first_sample_time ==0 && - session->evlist->last_sample_time ==0 ) { -pr_err ("HINT: no first/last sample time found in perf data.\n" -"Please use latest perf binary to execute 'perf record'\n" -"(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); - err = -EINVAL ; - goto out_delete; - } - - script.range_num =perf_time__percent_parse_str ( - script.ptime_range, script.range_size, - script.time_str, - session->evlist->first_sample_time, - session->evlist->last_sample_time); - -if (script.range_num <0 ) { -pr_err ("Invalid time string\n" ); - err = -EINVAL ; +if (script.time_str) { + err =perf_time__parse_for_ranges (script.time_str, session, + &script.ptime_range, + &script.range_size, + &script.range_num); +if (err <0 ) goto out_delete; - } - }else { - script.range_num =1 ; } err =__cmd_script (&script);
@@ -3737,7 +3713,8 @@ int cmd_script(int argc, const char **argv)flush_scripting (); out_delete: -zfree (&script.ptime_range); +if (script.ptime_range) +zfree (&script.ptime_range);perf_evlist__free_stats (session->evlist);perf_session__delete (session);
tools/perf/util/time-utils.c +50 -1
69 lines not on this page · raw message
tools/perf/util/time-utils.h +6 -0
@@ -23,6 +23,12 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);bool perf_time__ranges_skip_sample (struct perf_time_interval *ptime_buf,int num,u64 timestamp); +struct perf_session ; + +int perf_time__parse_for_ranges (const char *str,struct perf_session *session, +struct perf_time_interval **ranges, +int *range_size,int *range_num); +int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz);int fetch_current_timestamp (char *buf,size_t sz);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 6/35 perf auxtrace: Improve address filter error message when there is no DSO
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The message does not indicate the possibility that the symbol is not found because the file does not exist.
Before:
$ perf record -e intel_pt//u --filter 'filter strcmp / strcpy @ foo ' ls Symbol 'strcmp' not found. Note that symbols must be functions. Failed to parse address filter: 'filter strcmp / strcpy @ foo ' Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>] Where multiple filters are separated by space or comma.
After:
$ perf record -e intel_pt//u --filter 'filter strcmp / strcpy @ foo ' ls File 'foo' not found or has no symbols. Symbol 'strcmp' not found. Note that symbols must be functions. Failed to parse address filter: 'filter strcmp / strcpy @ foo ' Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>] Where multiple filters are separated by space or comma.
--- tools/perf/util/auxtrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/auxtrace.c +2 -1
@@ -1918,7 +1918,8 @@ static struct dso *load_dso(const char *name)if (!map)return NULL ; -map__load (map); +if (map__load (map) <0 ) +pr_err ("File '%s' not found or has no symbols.\n" , name); dso =dso__get (map->dso);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 7/35 perf intel-pt: Fix divide by zero when TSC is not available
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
When TSC is not available, "timeless" decoding is used but a divide by zero occurs if perf_time_to_tsc() is called.
Ensure the divisor is not zero.
--- tools/perf/util/intel-pt.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/intel-pt.c +2 -0
@@ -2531,6 +2531,8 @@ int intel_pt_process_auxtrace_info(union perf_event *event, } pt->timeless_decoding =intel_pt_timeless_decoding (pt); +if (pt->timeless_decoding && !pt->tc.time_mult) + pt->tc.time_mult =1 ; pt->have_tsc =intel_pt_have_tsc (pt); pt->sampling_mode = false; pt->est_tsc = !pt->timeless_decoding;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 8/35 perf db-export: Add calls parent_id to enable creation of call trees
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The call_path can be used to find the parent symbol for a call but not the exact parent call. To do that add parent_id to the call_return export. This enables the creation of a call tree from the exported data.
--- tools/perf/util/db-export.c | 15 ++++++++++----- tools/perf/util/db-export.h | 3 ++- .../util/scripting-engines/trace-event-python.c | 8 +++++--- tools/perf/util/thread-stack.c | 16 ++++++++++++++-- tools/perf/util/thread-stack.h | 6 ++++-- 5 files changed, 35 insertions(+), 13 deletions(-)
tools/perf/util/db-export.c +10 -5
@@ -510,18 +510,23 @@ int db_export__call_path(struct db_export *dbe, struct call_path *cp)return 0 ; } -int db_export__call_return (struct db_export *dbe,struct call_return *cr) +int db_export__call_return (struct db_export *dbe,struct call_return *cr, +u64 *parent_db_id) {int err; -if (cr->db_id) -return 0 ; - err =db_export__call_path (dbe, cr->cp);if (err)return err; - cr->db_id = ++dbe->call_return_last_db_id; +if (!cr->db_id) + cr->db_id = ++dbe->call_return_last_db_id; + +if (parent_db_id) { +if (!*parent_db_id) + *parent_db_id = ++dbe->call_return_last_db_id; + cr->parent_db_id = *parent_db_id; + }if (dbe->export_call_return)return dbe->export_call_return (dbe, cr);
tools/perf/util/db-export.h +2 -1
@@ -104,6 +104,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,int db_export__branch_types (struct db_export *dbe);int db_export__call_path (struct db_export *dbe,struct call_path *cp); -int db_export__call_return (struct db_export *dbe,struct call_return *cr); +int db_export__call_return (struct db_export *dbe,struct call_return *cr, +u64 *parent_db_id);#endif
tools/perf/util/scripting-engines/trace-event-python.c +5 -3
@@ -1173,7 +1173,7 @@ static int python_export_call_return(struct db_export *dbe,u64 comm_db_id = cr->comm ? cr->comm->db_id :0 ;PyObject *t; - t =tuple_new (11 ); + t =tuple_new (12 );tuple_set_u64 (t,0 , cr->db_id);tuple_set_u64 (t,1 , cr->thread->db_id);
@@ -1186,6 +1186,7 @@ static int python_export_call_return(struct db_export *dbe,tuple_set_u64 (t,8 , cr->return_ref);tuple_set_u64 (t,9 , cr->cp->parent->db_id);tuple_set_s32 (t,10 , cr->flags); +tuple_set_u64 (t,11 , cr->parent_db_id);call_object (tables->call_return_handler, t,"call_return_table" );
@@ -1194,11 +1195,12 @@ static int python_export_call_return(struct db_export *dbe,return 0 ; } -static int python_process_call_return (struct call_return *cr,void *data) +static int python_process_call_return (struct call_return *cr,u64 *parent_db_id, +void *data) {struct db_export *dbe = data; -return db_export__call_return (dbe, cr); +return db_export__call_return (dbe, cr, parent_db_id); } static void python_process_general_event(struct perf_sample *sample,
tools/perf/util/thread-stack.c +14 -2
@@ -49,6 +49,7 @@ enum retpoline_state_t {* @timestamp: timestamp (if known) * @ref: external reference (e.g. db_id of sample) * @branch_count: the branch count when the entry was created +* @db_id: id used for db-export * @cp: call path * @no_call: a 'call' was not seen * @trace_end: a 'call' but trace ended
@@ -59,6 +60,7 @@ struct thread_stack_entry {u64 timestamp;u64 ref;u64 branch_count; +u64 db_id;struct call_path *cp;bool no_call;bool trace_end;
@@ -280,12 +282,14 @@ static int thread_stack__call_return(struct thread *thread, .comm = ts->comm, .db_id = 0, }; +u64 *parent_db_id; tse = &ts->stack[idx]; cr.cp = tse->cp; cr.call_time = tse->timestamp; cr.return_time = timestamp; cr.branch_count = ts->branch_count - tse->branch_count; + cr.db_id = tse->db_id; cr.call_ref = tse->ref; cr.return_ref = ref;if (tse->no_call)
@@ -295,7 +299,14 @@ static int thread_stack__call_return(struct thread *thread,if (tse->non_call) cr.flags |=CALL_RETURN_NON_CALL ; -return crp->process (&cr, crp->data); +/* +* The parent db_id must be assigned before exporting the child. Note +* it is not possible to export the parent first because its information +* is not yet complete because its 'return' has not yet been processed. +*/ + parent_db_id = idx ? &(tse -1 )->db_id :NULL ; + +return crp->process (&cr, parent_db_id, crp->data); }static int __thread_stack__flush (struct thread *thread,struct thread_stack *ts)
@@ -484,7 +495,7 @@ void thread_stack__sample(struct thread *thread, int cpu, }struct call_return_processor * -call_return_processor__new (int (*process)(struct call_return *cr,void *data), +call_return_processor__new (int (*process)(struct call_return *cr,u64 *parent_db_id,void *data),void *data) {struct call_return_processor *crp;
@@ -537,6 +548,7 @@ static int thread_stack__push_cp(struct thread_stack *ts, u64 ret_addr, tse->no_call = no_call; tse->trace_end = trace_end; tse->non_call = false; + tse->db_id =0 ;return 0 ; }
tools/perf/util/thread-stack.h +4 -2
@@ -55,6 +55,7 @@ enum {* @call_ref: external reference to 'call' sample (e.g. db_id) * @return_ref: external reference to 'return' sample (e.g. db_id) * @db_id: id used for db-export +* @parent_db_id: id of parent call used for db-export * @flags: Call/Return flags */ struct call_return {
@@ -67,6 +68,7 @@ struct call_return {u64 call_ref;u64 return_ref;u64 db_id; +u64 parent_db_id;u32 flags; };
@@ -79,7 +81,7 @@ struct call_return {*/ struct call_return_processor {struct call_path_root *cpr; -int (*process)(struct call_return *cr,void *data); +int (*process)(struct call_return *cr,u64 *parent_db_id,void *data);void *data; };
@@ -93,7 +95,7 @@ void thread_stack__free(struct thread *thread);size_t thread_stack__depth (struct thread *thread,int cpu);struct call_return_processor * -call_return_processor__new (int (*process)(struct call_return *cr,void *data), +call_return_processor__new (int (*process)(struct call_return *cr,u64 *parent_db_id,void *data),void *data);void call_return_processor__free (struct call_return_processor *crp); int thread_stack__process(struct thread *thread, struct comm *comm,
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 9/35 perf scripts python: export-to-sqlite.py: Export calls parent_id
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Export to the 'calls' table the newly created 'parent_id'.
--- tools/perf/scripts/python/export-to-sqlite.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/perf/scripts/python/export-to-sqlite.py +8 -4
@@ -222,7 +222,8 @@ if perf_db_export_calls: 'call_id bigint,' 'return_id bigint,' 'parent_call_path_id bigint,' - 'flags integer)') + 'flags integer,' + 'parent_id bigint)') # printf was added to sqlite in version 3.8.3 sqlite_has_printf = False
@@ -321,7 +322,8 @@ if perf_db_export_calls: 'call_id,' 'return_id,' 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE flags END AS flags,' - 'parent_call_path_id' + 'parent_call_path_id,' + 'parent_id' ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id') do_query(query, 'CREATE VIEW samples_view AS '
@@ -373,7 +375,7 @@ if perf_db_export_calls or perf_db_export_callchains: call_path_query.prepare("INSERT INTO call_paths VALUES (?, ?, ?, ?)") if perf_db_export_calls: call_query = QSqlQuery(db) - call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") def trace_begin(): print datetime.datetime.today(), "Writing records..."
@@ -388,6 +390,7 @@ def trace_begin(): sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) if perf_db_export_calls or perf_db_export_callchains: call_path_table(0, 0, 0, 0) + call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) unhandled_count = 0
@@ -397,6 +400,7 @@ def trace_end(): print datetime.datetime.today(), "Adding indexes" if perf_db_export_calls: do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') + do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') if (unhandled_count): print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
@@ -452,4 +456,4 @@ def call_path_table(*x): bind_exec(call_path_query, 4, x) def call_return_table(*x): - bind_exec(call_query, 11, x) + bind_exec(call_query, 12, x)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 10/35 perf scripts python: export-to-postgresql.py: Fix invalid input syntax for integer error
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Fix SQL query error "invalid input syntax for integer":
Traceback (most recent call last):
File "tools/perf/scripts/python/export-to-postgresql.py", line 465, in <module>
do_query(query, 'CREATE VIEW calls_view AS '
File "tools/perf/scripts/python/export-to-postgresql.py", line 274, in do_query
raise Exception("Query failed: " + q.lastError().text())
Exception: Query failed: ERROR: invalid input syntax for integer: "" LINE 1: ...ch_count,call_id,return_id,CASE WHEN flags=0 THEN '' WHEN fl...
^
(22P02) QPSQL: Unable to create query
Error running python script tools/perf/scripts/python/export-to-postgresql.py
--- tools/perf/scripts/python/export-to-postgresql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/export-to-postgresql.py +1 -1
@@ -478,7 +478,7 @@ if perf_db_export_calls: 'branch_count,' 'call_id,' 'return_id,' - 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE flags END AS flags,' + 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE CAST ( flags AS VARCHAR(6) ) END AS flags,' 'parent_call_path_id' ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 11/35 perf scripts python: export-to-postgresql.py: Export calls parent_id
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Export to the 'calls' table the newly created 'parent_id' and create an index for it.
--- tools/perf/scripts/python/export-to-postgresql.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tools/perf/scripts/python/export-to-postgresql.py +9 -5
@@ -394,7 +394,8 @@ if perf_db_export_calls: 'call_id bigint,' 'return_id bigint,' 'parent_call_path_id bigint,' - 'flags integer)') + 'flags integer,' + 'parent_id bigint)') do_query(query, 'CREATE VIEW machines_view AS ' 'SELECT '
@@ -479,7 +480,8 @@ if perf_db_export_calls: 'call_id,' 'return_id,' 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE CAST ( flags AS VARCHAR(6) ) END AS flags,' - 'parent_call_path_id' + 'parent_call_path_id,' + 'calls.parent_id' ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id') do_query(query, 'CREATE VIEW samples_view AS '
@@ -575,6 +577,7 @@ def trace_begin(): sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) if perf_db_export_calls or perf_db_export_callchains: call_path_table(0, 0, 0, 0) + call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) unhandled_count = 0
@@ -657,6 +660,7 @@ def trace_end(): 'ADD CONSTRAINT returnfk FOREIGN KEY (return_id) REFERENCES samples (id),' 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)') do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') + do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') if (unhandled_count): print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
@@ -728,7 +732,7 @@ def call_path_table(cp_id, parent_id, symbol_id, ip, *x): value = struct.pack(fmt, 4, 8, cp_id, 8, parent_id, 8, symbol_id, 8, ip) call_path_file.write(value) -def call_return_table(cr_id, thread_id, comm_id, call_path_id, call_time, return_time, branch_count, call_id, return_id, parent_call_path_id, flags, *x): - fmt = "!hiqiqiqiqiqiqiqiqiqiqii" - value = struct.pack(fmt, 11, 8, cr_id, 8, thread_id, 8, comm_id, 8, call_path_id, 8, call_time, 8, return_time, 8, branch_count, 8, call_id, 8, return_id, 8, parent_call_path_id, 4, flags) +def call_return_table(cr_id, thread_id, comm_id, call_path_id, call_time, return_time, branch_count, call_id, return_id, parent_call_path_id, flags, parent_id, *x): + fmt = "!hiqiqiqiqiqiqiqiqiqiqiiiq" + value = struct.pack(fmt, 12, 8, cr_id, 8, thread_id, 8, comm_id, 8, call_path_id, 8, call_time, 8, return_time, 8, branch_count, 8, call_id, 8, return_id, 8, parent_call_path_id, 4, flags, 8, parent_id) call_file.write(value)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 12/35 perf scripts python: exported-sql-viewer.py: Factor out TreeWindowBase
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Factor out a base class TreeWindowBase from CallGraphWindow, so that TreeWindowBase can be reused.
--- .../scripts/python/exported-sql-viewer.py | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +31 -19
@@ -693,28 +693,16 @@ class VBox(): def Widget(self): return self.vbox -# Context-sensitive call graph window - -class CallGraphWindow(QMdiSubWindow): - - def __init__(self, glb, parent=None): - super(CallGraphWindow, self).__init__(parent) +# Tree window base - self.model = LookupCreateModel("Context-Sensitive Call Graph", lambda x=glb: CallGraphModel(x)) +class TreeWindowBase(QMdiSubWindow): - self.view = QTreeView() - self.view.setModel(self.model) - - for c, w in ((0, 250), (1, 100), (2, 60), (3, 70), (4, 70), (5, 100)): - self.view.setColumnWidth(c, w) - - self.find_bar = FindBar(self, self) - - self.vbox = VBox(self.view, self.find_bar.Widget()) - - self.setWidget(self.vbox.Widget()) + def __init__(self, parent=None): + super(TreeWindowBase, self).__init__(parent) - AddSubWindow(glb.mainwindow.mdi_area, self, "Context-Sensitive Call Graph") + self.model = None + self.view = None + self.find_bar = None def DisplayFound(self, ids): if not len(ids):
@@ -747,6 +735,30 @@ class CallGraphWindow(QMdiSubWindow): if not found: self.find_bar.NotFound() + +# Context-sensitive call graph window + +class CallGraphWindow(TreeWindowBase): + + def __init__(self, glb, parent=None): + super(CallGraphWindow, self).__init__(parent) + + self.model = LookupCreateModel("Context-Sensitive Call Graph", lambda x=glb: CallGraphModel(x)) + + self.view = QTreeView() + self.view.setModel(self.model) + + for c, w in ((0, 250), (1, 100), (2, 60), (3, 70), (4, 70), (5, 100)): + self.view.setColumnWidth(c, w) + + self.find_bar = FindBar(self, self) + + self.vbox = VBox(self.view, self.find_bar.Widget()) + + self.setWidget(self.vbox.Widget()) + + AddSubWindow(glb.mainwindow.mdi_area, self, "Context-Sensitive Call Graph") + # Child data item finder class ChildDataItemFinder():
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 13/35 perf scripts python: exported-sql-viewer.py: Improve TreeModel abstraction
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Instead of passing the tree root, get it from a method that can be implemented in any derived class.
--- .../perf/scripts/python/exported-sql-viewer.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +11 -6
@@ -167,9 +167,10 @@ class Thread(QThread): class TreeModel(QAbstractItemModel): - def __init__(self, root, parent=None): + def __init__(self, glb, parent=None): super(TreeModel, self).__init__(parent) - self.root = root + self.glb = glb + self.root = self.GetRoot() self.last_row_read = 0 def Item(self, parent):
@@ -562,8 +563,10 @@ class CallGraphRootItem(CallGraphLevelItemBase): class CallGraphModel(TreeModel): def __init__(self, glb, parent=None): - super(CallGraphModel, self).__init__(CallGraphRootItem(glb), parent) - self.glb = glb + super(CallGraphModel, self).__init__(glb, parent) + + def GetRoot(self): + return CallGraphRootItem(self.glb) def columnCount(self, parent=None): return 7
@@ -1339,8 +1342,7 @@ class BranchModel(TreeModel): progress = Signal(object) def __init__(self, glb, event_id, where_clause, parent=None): - super(BranchModel, self).__init__(BranchRootItem(), parent) - self.glb = glb + super(BranchModel, self).__init__(glb, parent) self.event_id = event_id self.more = True self.populated = 0
@@ -1364,6 +1366,9 @@ class BranchModel(TreeModel): self.fetcher.done.connect(self.Update) self.fetcher.Fetch(glb_chunk_sz) + def GetRoot(self): + return BranchRootItem() + def columnCount(self, parent=None): return 8
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 14/35 perf scripts python: exported-sql-viewer.py: Factor out CallGraphModelBase
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Factor out a base class CallGraphModelBase from CallGraphModel, so that CallGraphModelBase can be reused.
--- .../scripts/python/exported-sql-viewer.py | 100 ++++++++++-------- 1 file changed, 55 insertions(+), 45 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +55 -45
@@ -558,26 +558,12 @@ class CallGraphRootItem(CallGraphLevelItemBase): self.child_items.append(child_item) self.child_count += 1 -# Context-sensitive call graph data model +# Context-sensitive call graph data model base -class CallGraphModel(TreeModel): +class CallGraphModelBase(TreeModel): def __init__(self, glb, parent=None): - super(CallGraphModel, self).__init__(glb, parent) - - def GetRoot(self): - return CallGraphRootItem(self.glb) - - def columnCount(self, parent=None): - return 7 - - def columnHeader(self, column): - headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "] - return headers[column] - - def columnAlignment(self, column): - alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ] - return alignment[column] + super(CallGraphModelBase, self).__init__(glb, parent) def FindSelect(self, value, pattern, query): if pattern:
@@ -597,34 +583,7 @@ class CallGraphModel(TreeModel): match = " GLOB '" + str(value) + "'" else: match = " = '" + str(value) + "'" - QueryExec(query, "SELECT call_path_id, comm_id, thread_id" - " FROM calls" - " INNER JOIN call_paths ON calls.call_path_id = call_paths.id" - " INNER JOIN symbols ON call_paths.symbol_id = symbols.id" - " WHERE symbols.name" + match + - " GROUP BY comm_id, thread_id, call_path_id" - " ORDER BY comm_id, thread_id, call_path_id") - - def FindPath(self, query): - # Turn the query result into a list of ids that the tree view can walk - # to open the tree at the right place. - ids = [] - parent_id = query.value(0) - while parent_id: - ids.insert(0, parent_id) - q2 = QSqlQuery(self.glb.db) - QueryExec(q2, "SELECT parent_id" - " FROM call_paths" - " WHERE id = " + str(parent_id)) - if not q2.next(): - break - parent_id = q2.value(0) - # The call path root is not used - if ids[0] == 1: - del ids[0] - ids.insert(0, query.value(2)) - ids.insert(0, query.value(1)) - return ids + self.DoFindSelect(query, match) def Found(self, query, found): if found:
@@ -678,6 +637,57 @@ class CallGraphModel(TreeModel): def FindDone(self, thread, callback, ids): callback(ids) +# Context-sensitive call graph data model + +class CallGraphModel(CallGraphModelBase): + + def __init__(self, glb, parent=None): + super(CallGraphModel, self).__init__(glb, parent) + + def GetRoot(self): + return CallGraphRootItem(self.glb) + + def columnCount(self, parent=None): + return 7 + + def columnHeader(self, column): + headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "] + return headers[column] + + def columnAlignment(self, column): + alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ] + return alignment[column] + + def DoFindSelect(self, query, match): + QueryExec(query, "SELECT call_path_id, comm_id, thread_id" + " FROM calls" + " INNER JOIN call_paths ON calls.call_path_id = call_paths.id" + " INNER JOIN symbols ON call_paths.symbol_id = symbols.id" + " WHERE symbols.name" + match + + " GROUP BY comm_id, thread_id, call_path_id" + " ORDER BY comm_id, thread_id, call_path_id") + + def FindPath(self, query): + # Turn the query result into a list of ids that the tree view can walk + # to open the tree at the right place. + ids = [] + parent_id = query.value(0) + while parent_id: + ids.insert(0, parent_id) + q2 = QSqlQuery(self.glb.db) + QueryExec(q2, "SELECT parent_id" + " FROM call_paths" + " WHERE id = " + str(parent_id)) + if not q2.next(): + break + parent_id = q2.value(0) + # The call path root is not used + if ids[0] == 1: + del ids[0] + ids.insert(0, query.value(2)) + ids.insert(0, query.value(1)) + return ids + # Vertical widget layout class VBox():
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 15/35 perf scripts python: exported-sql-viewer.py: Add call tree
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add a new report to display a call tree. The Call Tree report is very similar to the Context-Sensitive Call Graph, but the data is not aggregated. Also the 'Count' column, which would be always 1, is replaced by the 'Call Time'.
Committer testing:
$ cat simple-retpoline.c /*
https://lkml.kernel.org/r/[email protected]
$ gcc -ggdb3 -Wall -Wextra -O2 -o simple-retpoline simple-retpoline.c $ objdump -d simple-retpoline */
__attribute__((noinline)) int bar(void)
{
return -1;
}
int foo(void)
{
return bar() + 1;
}
__attribute__((indirect_branch("thunk"))) int main()
{
int (*volatile fn)(void) = foo; fn();
return fn();
}
$
$ perf record -o simple-retpoline.perf.data -e intel_pt/cyc/u ./simple-retpoline
$ perf script -i simple-retpoline.perf.data --itrace=be -s ~acme/libexec/perf-core/scripts/python/export-to-sqlite.py simple-retpoline.db branches calls
$ python ~acme/libexec/perf-core/scripts/python/exported-sql-viewer.py simple-retpoline.dbAnd in the GUI select:
"Reports"
"Call Tree"
Call Path | Object | Call Time (ns) | Time (ns) | Time (%) | Branch Count | Brach Count (%) |
> simple-retpolin
> PID:TID
> _start ld-2.28.so 2193855505777 156267 100.0 10602 100.0
unknown unknown 2193855506010 2276 1.5 1 0.0
> _dl_start ld-2.28.so 2193855508286 137047 87.7 10088 95.2
> _dl_init ld-2.28.so 2193855645444 9142 5.9 326 3.1
> _start simple-retpoline 2193855654587 7457 4.8 182 1.7
> __libc_start_main <SNIP>
<SNIP>
> main simple-retpoline 2193855657493 32 0.5 12 6.7
> foo simple-retpoline 2193855657493 14 43.8 5 41.7
<SNIP>--- .../scripts/python/exported-sql-viewer.py | 195 +++++++++++++++++- 1 file changed, 186 insertions(+), 9 deletions(-)
tools/perf/scripts/python/exported-sql-viewer.py +186 -9
@@ -688,6 +688,150 @@ class CallGraphModel(CallGraphModelBase): ids.insert(0, query.value(1)) return ids +# Call tree data model level 2+ item base + +class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase): + + def __init__(self, glb, row, comm_id, thread_id, calls_id, time, branch_count, parent_item): + super(CallTreeLevelTwoPlusItemBase, self).__init__(glb, row, parent_item) + self.comm_id = comm_id + self.thread_id = thread_id + self.calls_id = calls_id + self.branch_count = branch_count + self.time = time + + def Select(self): + self.query_done = True; + if self.calls_id == 0: + comm_thread = " AND comm_id = " + str(self.comm_id) + " AND thread_id = " + str(self.thread_id) + else: + comm_thread = "" + query = QSqlQuery(self.glb.db) + QueryExec(query, "SELECT calls.id, name, short_name, call_time, return_time - call_time, branch_count" + " FROM calls" + " INNER JOIN call_paths ON calls.call_path_id = call_paths.id" + " INNER JOIN symbols ON call_paths.symbol_id = symbols.id" + " INNER JOIN dsos ON symbols.dso_id = dsos.id" + " WHERE calls.parent_id = " + str(self.calls_id) + comm_thread + + " ORDER BY call_time, calls.id") + while query.next(): + child_item = CallTreeLevelThreeItem(self.glb, self.child_count, self.comm_id, self.thread_id, query.value(0), query.value(1), query.value(2), query.value(3), int(query.value(4)), int(query.value(5)), self) + self.child_items.append(child_item) + self.child_count += 1 + +# Call tree data model level three item + +class CallTreeLevelThreeItem(CallTreeLevelTwoPlusItemBase): + + def __init__(self, glb, row, comm_id, thread_id, calls_id, name, dso, count, time, branch_count, parent_item): + super(CallTreeLevelThreeItem, self).__init__(glb, row, comm_id, thread_id, calls_id, time, branch_count, parent_item) + dso = dsoname(dso) + self.data = [ name, dso, str(count), str(time), PercentToOneDP(time, parent_item.time), str(branch_count), PercentToOneDP(branch_count, parent_item.branch_count) ] + self.dbid = calls_id + +# Call tree data model level two item + +class CallTreeLevelTwoItem(CallTreeLevelTwoPlusItemBase): + + def __init__(self, glb, row, comm_id, thread_id, pid, tid, parent_item): + super(CallTreeLevelTwoItem, self).__init__(glb, row, comm_id, thread_id, 0, 0, 0, parent_item) + self.data = [str(pid) + ":" + str(tid), "", "", "", "", "", ""] + self.dbid = thread_id + + def Select(self): + super(CallTreeLevelTwoItem, self).Select() + for child_item in self.child_items: + self.time += child_item.time + self.branch_count += child_item.branch_count + for child_item in self.child_items: + child_item.data[4] = PercentToOneDP(child_item.time, self.time) + child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count) + +# Call tree data model level one item + +class CallTreeLevelOneItem(CallGraphLevelItemBase): + + def __init__(self, glb, row, comm_id, comm, parent_item): + super(CallTreeLevelOneItem, self).__init__(glb, row, parent_item) + self.data = [comm, "", "", "", "", "", ""] + self.dbid = comm_id + + def Select(self): + self.query_done = True; + query = QSqlQuery(self.glb.db) + QueryExec(query, "SELECT thread_id, pid, tid" + " FROM comm_threads" + " INNER JOIN threads ON thread_id = threads.id" + " WHERE comm_id = " + str(self.dbid)) + while query.next(): + child_item = CallTreeLevelTwoItem(self.glb, self.child_count, self.dbid, query.value(0), query.value(1), query.value(2), self) + self.child_items.append(child_item) + self.child_count += 1 + +# Call tree data model root item + +class CallTreeRootItem(CallGraphLevelItemBase): + + def __init__(self, glb): + super(CallTreeRootItem, self).__init__(glb, 0, None) + self.dbid = 0 + self.query_done = True; + query = QSqlQuery(glb.db) + QueryExec(query, "SELECT id, comm FROM comms") + while query.next(): + if not query.value(0): + continue + child_item = CallTreeLevelOneItem(glb, self.child_count, query.value(0), query.value(1), self) + self.child_items.append(child_item) + self.child_count += 1 + +# Call Tree data model + +class CallTreeModel(CallGraphModelBase): + + def __init__(self, glb, parent=None): + super(CallTreeModel, self).__init__(glb, parent) + + def GetRoot(self): + return CallTreeRootItem(self.glb) + + def columnCount(self, parent=None): + return 7 + + def columnHeader(self, column): + headers = ["Call Path", "Object", "Call Time", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "] + return headers[column] + + def columnAlignment(self, column): + alignment = [ Qt.AlignLeft, Qt.AlignLeft, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight, Qt.AlignRight ] + return alignment[column] + + def DoFindSelect(self, query, match): + QueryExec(query, "SELECT calls.id, comm_id, thread_id" + " FROM calls" + " INNER JOIN call_paths ON calls.call_path_id = call_paths.id" + " INNER JOIN symbols ON call_paths.symbol_id = symbols.id" + " WHERE symbols.name" + match + + " ORDER BY comm_id, thread_id, call_time, calls.id") + + def FindPath(self, query): + # Turn the query result into a list of ids that the tree view can walk + # to open the tree at the right place. + ids = [] + parent_id = query.value(0) + while parent_id: + ids.insert(0, parent_id) + q2 = QSqlQuery(self.glb.db) + QueryExec(q2, "SELECT parent_id" + " FROM calls" + " WHERE id = " + str(parent_id)) + if not q2.next(): + break + parent_id = q2.value(0) + ids.insert(0, query.value(2)) + ids.insert(0, query.value(1)) + return ids + # Vertical widget layout class VBox():
@@ -772,6 +916,29 @@ class CallGraphWindow(TreeWindowBase): AddSubWindow(glb.mainwindow.mdi_area, self, "Context-Sensitive Call Graph") +# Call tree window + +class CallTreeWindow(TreeWindowBase): + + def __init__(self, glb, parent=None): + super(CallTreeWindow, self).__init__(parent) + + self.model = LookupCreateModel("Call Tree", lambda x=glb: CallTreeModel(x)) + + self.view = QTreeView() + self.view.setModel(self.model) + + for c, w in ((0, 230), (1, 100), (2, 100), (3, 70), (4, 70), (5, 100)): + self.view.setColumnWidth(c, w) + + self.find_bar = FindBar(self, self) + + self.vbox = VBox(self.view, self.find_bar.Widget()) + + self.setWidget(self.vbox.Widget()) + + AddSubWindow(glb.mainwindow.mdi_area, self, "Call Tree") + # Child data item finder class ChildDataItemFinder():
@@ -1890,10 +2057,10 @@ def GetEventList(db): # Is a table selectable -def IsSelectable(db, table): +def IsSelectable(db, table, sql = ""): query = QSqlQuery(db) try: - QueryExec(query, "SELECT * FROM " + table + " LIMIT 1") + QueryExec(query, "SELECT * FROM " + table + " " + sql + " LIMIT 1") except: return False return True
@@ -2302,9 +2469,10 @@ p.c2 { </style> <p class=c1><a href=#reports>1. Reports</a></p> <p class=c2><a href=#callgraph>1.1 Context-Sensitive Call Graph</a></p> -<p class=c2><a href=#allbranches>1.2 All branches</a></p> -<p class=c2><a href=#selectedbranches>1.3 Selected branches</a></p> -<p class=c2><a href=#topcallsbyelapsedtime>1.4 Top calls by elapsed time</a></p> +<p class=c2><a href=#calltree>1.2 Call Tree</a></p> +<p class=c2><a href=#allbranches>1.3 All branches</a></p> +<p class=c2><a href=#selectedbranches>1.4 Selected branches</a></p> +<p class=c2><a href=#topcallsbyelapsedtime>1.5 Top calls by elapsed time</a></p> <p class=c1><a href=#tables>2. Tables</a></p> <h1 id=reports>1. Reports</h1> <h2 id=callgraph>1.1 Context-Sensitive Call Graph</h2>
@@ -2340,7 +2508,10 @@ v- ls <h3>Find</h3> Ctrl-F displays a Find bar which finds function names by either an exact match or a pattern match. The pattern matching symbols are ? for any character and * for zero or more characters. -<h2 id=allbranches>1.2 All branches</h2> +<h2 id=calltree>1.2 Call Tree</h2> +The Call Tree report is very similar to the Context-Sensitive Call Graph, but the data is not aggregated. +Also the 'Count' column, which would be always 1, is replaced by the 'Call Time'. +<h2 id=allbranches>1.3 All branches</h2> The All branches report displays all branches in chronological order. Not all data is fetched immediately. More records can be fetched using the Fetch bar provided. <h3>Disassembly</h3>
@@ -2366,10 +2537,10 @@ sudo ldconfig Ctrl-F displays a Find bar which finds substrings by either an exact match or a regular expression match. Refer to Python documentation for the regular expression syntax. All columns are searched, but only currently fetched rows are searched. -<h2 id=selectedbranches>1.3 Selected branches</h2> +<h2 id=selectedbranches>1.4 Selected branches</h2> This is the same as the <a href=#allbranches>All branches</a> report but with the data reduced by various selection criteria. A dialog box displays available criteria which are AND'ed together. -<h3>1.3.1 Time ranges</h3> +<h3>1.4.1 Time ranges</h3> The time ranges hint text shows the total time range. Relative time ranges can also be entered in ms, us or ns. Also, negative values are relative to the end of trace. Examples: <pre>
@@ -2380,7 +2551,7 @@ ms, us or ns. Also, negative values are relative to the end of trace. Examples: -10ms- The last 10ms </pre> N.B. Due to the granularity of timestamps, there could be no branches in any given time range. -<h2 id=topcallsbyelapsedtime>1.4 Top calls by elapsed time</h2> +<h2 id=topcallsbyelapsedtime>1.5 Top calls by elapsed time</h2> The Top calls by elapsed time report displays calls in descending order of time elapsed between when the function was called and when it returned. The data is reduced by various selection criteria. A dialog box displays available criteria which are AND'ed together. If not all data is fetched, a Fetch bar is provided. Ctrl-F displays a Find bar.
@@ -2516,6 +2687,9 @@ class MainWindow(QMainWindow): if IsSelectable(glb.db, "calls"): reports_menu.addAction(CreateAction("Context-Sensitive Call &Graph", "Create a new window containing a context-sensitive call graph", self.NewCallGraph, self)) + if IsSelectable(glb.db, "calls", "WHERE parent_id >= 0"): + reports_menu.addAction(CreateAction("Call &Tree", "Create a new window containing a call tree", self.NewCallTree, self)) + self.EventMenu(GetEventList(glb.db), reports_menu) if IsSelectable(glb.db, "calls"):
@@ -2576,6 +2750,9 @@ class MainWindow(QMainWindow): def NewCallGraph(self): CallGraphWindow(self.glb, self) + def NewCallTree(self): + CallTreeWindow(self.glb, self) + def NewTopCalls(self): dialog = TopCallsDialog(self.glb, self) ret = dialog.exec_()
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 16/35 perf beauty msg_flags: Add missing %s lost when adding prefix suppression logic
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
When the prefix suppresion/enabling logic was added, I forgot to add an extra %, which ended up chopping off the strings:
Before:
# perf trace -e *mmsg --map-dump syscalls [299] = 1, [307] = 1, DNS Res~ver #3/14587 sendmmsg(106<socket:[3462393]>, 0x7f252b0fcaf0, 2, MSG_) = 2 chronyd/1053 recvmmsg(4, 0x558542ca5740, 4, MSG_, NULL) = 1 DNS Res~ver #2/14445 sendmmsg(106<socket:[3461475]>, 0x7f252ab09af0, 2, MSG_) = 2 DNS Res~ver #2/14444 sendmmsg(146<socket:[3457863]>, 0x7f2521a7aaf0, 2, MSG_) = 2 DNS Res~ver #2/14445 sendmmsg(106<socket:[3461475]>, 0x7f252ab09af0, 2, MSG_) = 2 DNS Res~ver #3/14587 sendmmsg(148<socket:[3460636]>, 0x7f252b0fcaf0, 2, MSG_) = 2 DNS Res~ver #2/14444 sendmmsg(146<socket:[3457863]>, 0x7f2521a7aaf0, 2, MSG_) = 2 ^C#
After:
# perf trace -e *mmsg --map-dump syscalls [299] = 1, [307] = 1, NetworkManager/17467 sendmmsg(22<socket:[3466493]>, 0x7f28927f9bb0, 2, MSG_NOSIGNAL) = 2 pool/17478 sendmmsg(10<socket:[3466523]>, 0x7f2769f95e90, 2, MSG_NOSIGNAL) = 2 DNS Res~ver #3/14587 sendmmsg(121<socket:[3466132]>, 0x7f252b0fcaf0, 2, MSG_NOSIGNAL) = 2 chronyd/1053 recvmmsg(4, 0x558542ca5740, 4, MSG_DONTWAIT, NULL) = 1 Socket Thread/17433 sendmmsg(121<socket:[3460903]>, 0x7f252668baf0, 2, MSG_NOSIGNAL) = 2 ^C#
--- tools/perf/trace/beauty/msg_flags.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/trace/beauty/msg_flags.c +1 -1
@@ -29,7 +29,7 @@ static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,return scnprintf (bf, size,"NONE" );#define P_MSG_FLAG (n) \ if (flags & MSG_##n) { \ - printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ + printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ flags &= ~MSG_##n; \ }
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 17/35 perf bpf: Automatically add BTF ELF markers
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The libbpf loader expects that some __btf_map_<MAP_NAME> structs be in place with the keys and values types of maps so that one can store the struct definitions and have them sent to the kernel via sys_bpf(fd, cmd = BTF_LOAD) and then later be retrievable via sys_bpf(fd, cmd = BPF_OBJ_GET_INFO_BY_FD) for use by tools such as 'bpftool map dump id MAP_ID'.
Since we already have this for defining maps in 'perf trace' BPF events:
bpf_map(name, _type, type_key, type_val, _max_entries)
As used in the tools/perf/examples/bpf/augmented_raw_syscalls.c:
--- 8< ---
struct syscall {
bool enabled;
};bpf_map(syscalls, ARRAY, int, struct syscall, 512);
--- 8< ---
All we need is to get all that already available info, piggyback on the 'bpf_map' define in tools/perf/include/bpf/bpf.h, that is included by 'perf trace' BPF programs and do that without requiring changes to the BPF programs already defining maps using 'bpf_map()'.
So this is what we have before this patch:
1) With this in ~/.perfconfig to dump .c events as .o, aka save a copy so that we can use the .o later as a pre-compiled BPF bytecode:
# grep '\[llvm\]' -A2 ~/.perfconfig [llvm] dump-obj = true clang-opt = -g
#
# clang --version clang version 9.0.0 (https://git.llvm.org/git/clang.git/ 7906282d3afec5dfdc2b27943fd6c0309086c507) (https://git.llvm.org/git/llvm.git/ a1b5de1ff8ae8bc79dc8e86e1f82565229bd0500) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /opt/llvm/bin
2) Note the -g there so that we get clang to generate debuginfo, and since the target is 'bpf' it will generate the BTF info in this clang version (9.0).
3) Run a simple 'perf record' specifiying as an event the augmented_raw_syscalls.c source code:
# perf record -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c sleep 1 LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.025 MB perf.data ]
# file /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o: ELF 64-bit LSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped
4) Look at the BTF structs encoded in it:
# pahole -F btf --sizes /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
syscall_enter_args 64 0
augmented_filename 264 0
syscall 1 0
syscall_exit_args 24 0
bpf_map 28 0
#
# pahole -F btf -C syscalls /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
# pahole -F btf -C syscall /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
struct syscall {
bool enabled; /* 0 1 *//* size: 1, cachelines: 1, members: 1 */ /* last cacheline: 1 bytes */
};
#
5) Ok, with just this we don't have the markers expected by the libbpf loader and when we run with this BPF bytecode, because we have:
# grep '\[trace\]' -A1 ~/.perfconfig [trace] add_events = /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o #
6) Lets do a 'perf trace' system wide session using this BPF program:
# perf trace -e *mmsg,open* Cache2 I/O/6885 openat(AT_FDCWD, "/home/acme/.cache/mozilla/firefox/ina67tev.default/cache2/entries/BA220AB2914006A7AE96D27BE6EA13DD77519FCA", O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR) = 106 Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121 Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121 Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121 Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121 DNS Res~ver #3/23340 openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 106 DNS Res~ver #3/23340 sendmmsg(106<socket:[3482690]>, 0x7f252f1fcaf0, 2, MSG_NOSIGNAL) = 2 Cache2 I/O/6885 openat(AT_FDCWD, "/home/acme/.cache/mozilla/firefox/ina67tev.default/cache2/entries/BA220AB2914006A7AE96D27BE6EA13DD77519FCA", O_RDWR) = 106 lighttpd/18915 openat(AT_FDCWD, "/proc/loadavg", O_RDONLY) = 12
7) While it runs lets see the maps that 'perf trace' + libbpf's BPF loader loaded into the kernel via sys_bpf(fd, BPF_BTF_LOAD, ...):
# bpftool map list | tail -6 149: perf_event_array name __augmented_sys flags 0x0 key 4B value 4B max_entries 8 memlock 4096B 150: array name syscalls flags 0x0 key 4B value 1B max_entries 512 memlock 8192B 151: hash name pids_filtered flags 0x0 key 4B value 1B max_entries 64 memlock 8192B #
8) Dump the "pids_filtered", map, that will have one entry per PID that 'perf trace' wants filtered, which includes its own, to avoid a tracing feedback loop (perf trace shows the syscalls it does which generates more syscalls that it has to show that...), it also auto-filters the 'gnome-terminal' and 'sshd' parent PIDs, for the same reason:
# bpftool map dump id 151 key: a5 0c 00 00 value: 01 key: 14 63 00 00 value: 01 Found 2 elements #
9) Since there is no BTF info available, it does a generic hex dump :-\
10) Now, with this patch applied, we'll do steps 3 to 6 again and look with pahole if there are extra structs encoded in BTF:
# pahole -F btf --sizes /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o syscall_enter_args 64 0 augmented_filename 264 0 syscall 1 0 syscall_exit_args 24 0 bpf_map 28 0 ____btf_map___augmented_syscalls__ 8 0 ____btf_map_syscalls 8 0 ____btf_map_pids_filtered 8 0 #
11) Yes, those __btf_map_ + the map names, lets see how they look like:
# pahole -F btf -C ____btf_map_syscalls /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
struct ____btf_map_syscalls {
int key; /* 0 4 */
struct syscall value; /* 4 1 *//* size: 8, cachelines: 1, members: 2 */ /* padding: 3 */ /* last cacheline: 8 bytes */
};
#
12) Lets repeat step 7 to get the new map ids:
# bpftool map list | tail -6 155: perf_event_array name __augmented_sys flags 0x0 key 4B value 4B max_entries 8 memlock 4096B 156: array name syscalls flags 0x0 key 4B value 1B max_entries 512 memlock 8192B 157: hash name pids_filtered flags 0x0 key 4B value 1B max_entries 64 memlock 8192B #
13) And finally lets dump the 'pids_filtered':
# bpftool map dump id 157
[{
"key": 3237,
"value": true
},{
"key": 26435,
"value": true
}
]
#Looks much better! BTF info was used to interpret the key as an integer and the value as a struct with just one boolean member, so to make it more compact, show just the 'true' value where we saw '01'.
Now to make 'perf trace --dump-map' to use BTF!
--- tools/perf/include/bpf/bpf.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/include/bpf/bpf.h +7 -1
@@ -24,7 +24,13 @@ struct bpf_map SEC("maps") name = { \ .key_size = sizeof(type_key), \ .value_size = sizeof(type_val), \ .max_entries = _max_entries, \ -} +}; \ +struct ____btf_map_##name { \ + type_key key; \ + type_val value; \ +}; \ +struct ____btf_map_##name __attribute__((section(".maps." #name), used)) \ + ____btf_map_##name = { }/* * FIXME: this should receive .max_entries as a parameter, as careful
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 18/35 perf clang: Remove needless extra semicolon
In reply to Arnaldo Carvalho de MeloFrom: Yang Wei <[email protected]>
Delete a superfluous semicolon in getBPFObjectFromModule().
--- tools/perf/util/c++/clang.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/c++/clang.cpp +1 -1
@@ -156,7 +156,7 @@ getBPFObjectFromModule(llvm::Module *Module) #endif if (NotAdded) { llvm::errs() << "TargetMachine can't emit a file of this type\n"; - return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);; + return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr); } PM.run(*Module);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 19/35 perf annotate: Calculate the max instruction name, align column to that
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We were hardcoding '6' as the max instruction name, and we have lots that are longer than that, see the diff from two 'P' printed TUI annotations for a libc function that uses instructions with long names, such as 'vpmovmskb' with its 9 chars:
--- __strcmp_avx2.annotation.before 2019-03-06 16:31:39.368020425 -0300
+++ __strcmp_avx2.annotation 2019-03-06 16:32:12.079450508 -0300
@@ -2,284 +2,284 @@
Event: cycles:ppp
Percent endbr64
- 0.10 mov %edi,%eax
+ 0.10 mov %edi,%eax
- xor %edx,%edx
+ xor %edx,%edx
- 3.54 vpxor %ymm7,%ymm7,%ymm7
+ 3.54 vpxor %ymm7,%ymm7,%ymm7
- or %esi,%eax
+ or %esi,%eax
- and $0xfff,%eax
+ and $0xfff,%eax
- cmp $0xf80,%eax
+ cmp $0xf80,%eax
- ↓ jg 370
+ ↓ jg 370
- 27.07 vmovdqu (%rdi),%ymm1
+ 27.07 vmovdqu (%rdi),%ymm1
- 7.97 vpcmpeqb (%rsi),%ymm1,%ymm0
+ 7.97 vpcmpeqb (%rsi),%ymm1,%ymm0
- 2.15 vpminub %ymm1,%ymm0,%ymm0
+ 2.15 vpminub %ymm1,%ymm0,%ymm0
- 4.09 vpcmpeqb %ymm7,%ymm0,%ymm0
+ 4.09 vpcmpeqb %ymm7,%ymm0,%ymm0
- 0.43 vpmovmskb %ymm0,%ecx
+ 0.43 vpmovmskb %ymm0,%ecx
- 1.53 test %ecx,%ecx
+ 1.53 test %ecx,%ecx
- ↓ je b0
+ ↓ je b0
- 5.26 tzcnt %ecx,%edx
+ 5.26 tzcnt %ecx,%edx
- 18.40 movzbl (%rdi,%rdx,1),%eax
+ 18.40 movzbl (%rdi,%rdx,1),%eax
- 7.09 movzbl (%rsi,%rdx,1),%edx
+ 7.09 movzbl (%rsi,%rdx,1),%edx
- 3.34 sub %edx,%eax
+ 3.34 sub %edx,%eax
2.37 vzeroupper
← retq
nop
- 50: tzcnt %ecx,%edx
+ 50: tzcnt %ecx,%edx
- movzbl 0x20(%rdi,%rdx,1),%eax
+ movzbl 0x20(%rdi,%rdx,1),%eax
- movzbl 0x20(%rsi,%rdx,1),%edx
+ movzbl 0x20(%rsi,%rdx,1),%edx
- sub %edx,%eax
+ sub %edx,%eax vzeroupper
← retq
- data16 nopw %cs:0x0(%rax,%rax,1)
+ data16 nopw %cs:0x0(%rax,%rax,1)
LPU-Reference: CAOBGo4z1KfmWeOm6Et0cnX5Z6DWsG2PQbAvRn1MhVPJmXHrc5g@mail.gmail.com
--- tools/perf/arch/arm64/annotate/instructions.c | 2 +- tools/perf/arch/s390/annotate/instructions.c | 2 +- tools/perf/util/annotate.c | 74 ++++++++++++------- tools/perf/util/annotate.h | 7 +- 4 files changed, 52 insertions(+), 33 deletions(-)
tools/perf/arch/arm64/annotate/instructions.c +1 -1
@@ -58,7 +58,7 @@ static int arm64_mov__parse(struct arch *arch __maybe_unused, }static int mov__scnprintf (struct ins *ins,char *bf,size_t size, -struct ins_operands *ops); +struct ins_operands *ops,int max_ins_name);static struct ins_ops arm64_mov_ops = { .parse = arm64_mov__parse,
tools/perf/arch/s390/annotate/instructions.c +1 -1
@@ -46,7 +46,7 @@ static int s390_call__parse(struct arch *arch, struct ins_operands *ops, }static int call__scnprintf (struct ins *ins,char *bf,size_t size, -struct ins_operands *ops); +struct ins_operands *ops,int max_ins_name);static struct ins_ops s390_call_ops = { .parse = s390_call__parse,
tools/perf/util/annotate.c +46 -28
178 lines not on this page · raw message
tools/perf/util/annotate.h +4 -3
@@ -59,14 +59,14 @@ struct ins_ops {void (*free)(struct ins_operands *ops);int (*parse)(struct arch *arch,struct ins_operands *ops,struct map_symbol *ms);int (*scnprintf)(struct ins *ins,char *bf,size_t size, -struct ins_operands *ops); +struct ins_operands *ops,int max_ins_name); };bool ins__is_jump (const struct ins *ins);bool ins__is_call (const struct ins *ins);bool ins__is_ret (const struct ins *ins);bool ins__is_lock (const struct ins *ins); -int ins__scnprintf (struct ins *ins,char *bf,size_t size,struct ins_operands *ops); +int ins__scnprintf (struct ins *ins,char *bf,size_t size,struct ins_operands *ops,int max_ins_name);bool ins__is_fused (struct arch *arch,const char *ins1,const char *ins2);#define ANNOTATION__IPC_WIDTH 6
@@ -219,7 +219,7 @@ int __annotation__scnprintf_samples_period(struct annotation *notes,struct perf_evsel *evsel, bool show_freq); -int disasm_line__scnprintf (struct disasm_line *dl,char *bf,size_t size,bool raw); +int disasm_line__scnprintf (struct disasm_line *dl,char *bf,size_t size,bool raw,int max_ins_name);size_t disasm__fprintf (struct list_head *head,FILE *fp);void symbol__calc_percent (struct symbol *sym,struct perf_evsel *evsel);
@@ -289,6 +289,7 @@ struct annotation {u8 target;u8 min_addr;u8 max_addr; +u8 max_ins_name; } widths;bool have_cycles;struct annotated_source *src;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 20/35 perf thread: Generalize function to copy from thread addr space from intel-bts code
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Add a utility function to fetch executable code. Convert one user over to it. There are more places doing that, but they do significantly different actions, so they are not easy to fit into a single library function.
Committer changes:
. No need to cast around, make 'buf' be a void pointer.
. Rename it to thread__memcpy() to reflect the fact it is about copying
a chunk of memory from a thread, i.e. from its address space.
. No need to have it in a separate object file, move it to thread.[ch]
. Check the return of map__load(), the original code didn't do it, but
since we're moving this around, check that as well.
--- tools/perf/util/intel-bts.c | 20 ++------------------ tools/perf/util/thread.c | 23 +++++++++++++++++++++++ tools/perf/util/thread.h | 3 +++ 3 files changed, 28 insertions(+), 18 deletions(-)
tools/perf/util/intel-bts.c +2 -18
@@ -328,35 +328,19 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip) {struct machine *machine = btsq->bts->machine;struct thread *thread; -struct addr_location al;unsigned char buf[INTEL_PT_INSN_BUF_SZ ];ssize_t len; -int x86_64; -uint8_t cpumode; +bool x86_64;int err =-1 ; -if (machine__kernel_ip (machine, ip)) - cpumode =PERF_RECORD_MISC_KERNEL ; -else - cpumode =PERF_RECORD_MISC_USER ; - thread =machine__find_thread (machine,-1 , btsq->tid);if (!thread)return -1 ; -if (!thread__find_map (thread, cpumode, ip, &al) || !al.map->dso) - goto out_put; - - len =dso__data_read_addr (al.map->dso, al.map, machine, ip, buf, -INTEL_PT_INSN_BUF_SZ ); + len =thread__memcpy (thread, machine, buf, ip,INTEL_PT_INSN_BUF_SZ , &x86_64);if (len <=0 ) goto out_put; -/* Load maps to ensure dso->is_64_bit has been updated */ -map__load (al.map); - - x86_64 = al.map->dso->is_64_bit; -if (intel_pt_get_insn (buf, len, x86_64, &btsq->intel_pt_insn)) goto out_put;
tools/perf/util/thread.c +23 -0
@@ -12,6 +12,7 @@#include "debug.h" #include "namespaces.h" #include "comm.h" +#include "map.h" #include "symbol.h" #include "unwind.h"
@@ -393,3 +394,25 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threareturn machine__find_thread (machine, thread->pid_, thread->pid_); } + +int thread__memcpy (struct thread *thread,struct machine *machine, +void *buf,u64 ip,int len,bool *is64bit) +{ +u8 cpumode =PERF_RECORD_MISC_USER ; +struct addr_location al; +long offset; + +if (machine__kernel_ip (machine, ip)) + cpumode =PERF_RECORD_MISC_KERNEL ; + +if (!thread__find_map (thread, cpumode, ip, &al) || !al.map->dso || + al.map->dso->data.status ==DSO_DATA_STATUS_ERROR || +map__load (al.map) <0 ) +return -1 ; + + offset = al.map->map_ip (al.map, ip); +if (is64bit) + *is64bit = al.map->dso->is_64_bit; + +return dso__data_read_offset (al.map->dso, machine, offset, buf, len); +}
tools/perf/util/thread.h +3 -0
@@ -113,6 +113,9 @@ struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,void thread__find_cpumode_addr_location (struct thread *thread,u64 addr,struct addr_location *al); +int thread__memcpy (struct thread *thread,struct machine *machine, +void *buf,u64 ip,int len,bool *is64bit); +static inline void *thread__priv (struct thread *thread) {return thread->priv;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 21/35 perf diff: Support --time filter option
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
To improve 'perf diff', implement a --time filter option to diff the samples within given time window.
It supports time percent with multiple time ranges. The time string format is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
For example:
Select the second 10% time slice to diff:
perf diff --time 10%/2
Select from 0% to 10% time slice to diff:
perf diff --time 0%-10%
Select the first and the second 10% time slices to diff:
perf diff --time 10%/1,10%/2
Select from 0% to 10% and 30% to 40% slices to diff:
perf diff --time 0%-10%,30%-40%
It also supports analysing samples within a given time window <start>,<stop>.
Times have the format seconds.microseconds.
If 'start' is not given (i.e., time string is ',x.y') then analysis starts at the beginning of the file.
If the stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file.
Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.
For example, we get the timestamp information from perf script.
perf script -i perf.data.old
mgen 13940 [000] 3946.361400: ...
perf script -i perf.data
mgen 13940 [000] 3971.150589 ...
perf diff --time 3946.361400,:3971.150589,
It analyzes the perf.data.old from the timestamp 3946.361400 to the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data.
v4:
---
Update abstime_str_dup(), let it return error if strdup is failed, and update __cmd_diff() accordingly.
--- tools/perf/Documentation/perf-diff.txt | 45 ++++++++ tools/perf/builtin-diff.c | 148 ++++++++++++++++++++++--- 2 files changed, 179 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-diff.txt +45 -0
@@ -118,6 +118,51 @@ OPTIONS sum of shown entries will be always 100%. "absolute" means it retains the original value before and after the filter is applied. +--time:: + Analyze samples within given time window. It supports time + percent with multiple time ranges. Time string is 'a%/n,b%/m,...' + or 'a%-b%,c%-%d,...'. + + For example: + + Select the second 10% time slice to diff: + + perf diff --time 10%/2 + + Select from 0% to 10% time slice to diff: + + perf diff --time 0%-10% + + Select the first and the second 10% time slices to diff: + + perf diff --time 10%/1,10%/2 + + Select from 0% to 10% and 30% to 40% slices to diff: + + perf diff --time 0%-10%,30%-40% + + It also supports analyzing samples within a given time window + <start>,<stop>. Times have the format seconds.microseconds. If 'start' + is not given (i.e., time string is ',x.y') then analysis starts at + the beginning of the file. If stop time is not given (i.e, time + string is 'x.y,') then analysis goes to the end of the file. Time string is + 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different + perf.data files. + + For example, we get the timestamp information from 'perf script'. + + perf script -i perf.data.old + mgen 13940 [000] 3946.361400: ... + + perf script -i perf.data + mgen 13940 [000] 3971.150589 ... + + perf diff --time 3946.361400,:3971.150589, + + It analyzes the perf.data.old from the timestamp 3946.361400 to + the end of perf.data.old and analyzes the perf.data from the + timestamp 3971.150589 to the end of perf.data. + COMPARISON ---------- The comparison is governed by the baseline file. The baseline perf.data
tools/perf/builtin-diff.c +134 -14
216 lines not on this page · raw message
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 22/35 perf diff: Support --cpu filter option
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
To improve 'perf diff', implement a --cpu filter option.
Multiple CPUs can be provided as a comma-separated list with no space:
0,1. Ranges of CPUs are specified with -: 0-2. Default is to report samples on all CPUs.
For example,
perf diff --cpu 0,1
It only diff the samples for CPU0 and CPU1.
--- tools/perf/Documentation/perf-diff.txt | 5 +++++ tools/perf/builtin-diff.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
tools/perf/Documentation/perf-diff.txt +5 -0
@@ -163,6 +163,11 @@ OPTIONS the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data. +--cpu:: Only diff samples for the list of CPUs provided. Multiple CPUs can + be provided as a comma-separated list with no space: 0,1. Ranges of + CPUs are specified with -: 0-2. Default is to report samples on all + CPUs. + COMPARISON ---------- The comparison is governed by the baseline file. The baseline perf.data
tools/perf/builtin-diff.c +16 -0
@@ -83,6 +83,9 @@ static unsigned int sort_compute = 1;static s64 compute_wdiff_w1;static s64 compute_wdiff_w2; +static const char *cpu_list; +static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); +enum {COMPUTE_DELTA ,COMPUTE_RATIO ,
@@ -354,6 +357,11 @@ static int diff__process_sample_event(struct perf_tool *tool,return -1 ; } +if (cpu_list && !test_bit (sample->cpu, cpu_bitmap)) { + ret =0 ; + goto out_put; + } +if (!hists__add_entry (hists, &al,NULL ,NULL ,NULL , sample, true)) {pr_warning ("problem incrementing symbol period, skipping event\n" ); goto out_put;
@@ -892,6 +900,13 @@ static int __cmd_diff(void) goto out_delete; } +if (cpu_list) { + ret =perf_session__cpu_bitmap (d->session, cpu_list, + cpu_bitmap); +if (ret <0 ) + goto out_delete; + } + ret =perf_session__process_events (d->session);if (ret) {pr_err ("Failed to process %s\n" , d->data.path);
@@ -969,6 +984,7 @@ static const struct option options[] = { "How to display percentage of filtered entries", parse_filter_percentage),OPT_STRING (0 ,"time" , &pdiff.time_str,"str" ,"Time span (time percent or absolute timestamp)" ), +OPT_STRING (0 ,"cpu" , &cpu_list,"cpu" ,"list of cpus to profile" ), OPT_END() };
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 23/35 perf diff: Support --pid/--tid filter options
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Using the existing symbol_conf.pid_list_str and symbol_conf.tid_list_str logic.
For example:
perf diff --tid 13965
It'll only diff the samples for thread 13965.
--- tools/perf/Documentation/perf-diff.txt | 6 ++++++ tools/perf/builtin-diff.c | 4 ++++ 2 files changed, 10 insertions(+)
tools/perf/Documentation/perf-diff.txt +6 -0
@@ -168,6 +168,12 @@ OPTIONS CPUs are specified with -: 0-2. Default is to report samples on all CPUs. +--pid=:: + Only diff samples for given process ID (comma separated list). + +--tid=:: + Only diff samples for given thread ID (comma separated list). + COMPARISON ---------- The comparison is governed by the baseline file. The baseline perf.data
tools/perf/builtin-diff.c +4 -0
@@ -985,6 +985,10 @@ static const struct option options[] = {OPT_STRING (0 ,"time" , &pdiff.time_str,"str" ,"Time span (time percent or absolute timestamp)" ),OPT_STRING (0 ,"cpu" , &cpu_list,"cpu" ,"list of cpus to profile" ), +OPT_STRING (0 ,"pid" , &symbol_conf.pid_list_str,"pid[,pid...]" , +"only consider symbols in these pids" ), +OPT_STRING (0 ,"tid" , &symbol_conf.tid_list_str,"tid[,tid...]" , +"only consider symbols in these tids" ), OPT_END() };
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 24/35 perf script python: Remove mixed indentation
In reply to Arnaldo Carvalho de MeloFrom: Tony Jones <[email protected]>
Remove mixed indentation in Python scripts. Revert to either all tabs (most common form) or all spaces (4 or 8) depending on what was the intent of the original commit. This is necessary to complete Python3 support as it will flag an error if it encounters mixed indentation.
--- tools/perf/scripts/python/check-perf-trace.py | 65 +++++++++---------- tools/perf/scripts/python/compaction-times.py | 8 +-- .../scripts/python/event_analyzing_sample.py | 6 +- .../scripts/python/failed-syscalls-by-pid.py | 38 +++++------ tools/perf/scripts/python/futex-contention.py | 2 +- tools/perf/scripts/python/intel-pt-events.py | 32 ++++----- tools/perf/scripts/python/mem-phys-addr.py | 7 +- tools/perf/scripts/python/net_dropmonitor.py | 2 +- tools/perf/scripts/python/netdev-times.py | 12 ++-- tools/perf/scripts/python/sched-migration.py | 6 +- tools/perf/scripts/python/sctop.py | 13 ++-- tools/perf/scripts/python/stackcollapse.py | 2 +- .../scripts/python/syscall-counts-by-pid.py | 47 +++++++------- tools/perf/scripts/python/syscall-counts.py | 31 +++++---- 14 files changed, 136 insertions(+), 135 deletions(-)
tools/perf/scripts/python/check-perf-trace.py +32 -33
@@ -23,60 +23,59 @@ def trace_begin(): pass def trace_end(): - print_unhandled() + print_unhandled() def irq__softirq_entry(event_name, context, common_cpu, - common_secs, common_nsecs, common_pid, common_comm, - common_callchain, vec): - print_header(event_name, common_cpu, common_secs, common_nsecs, - common_pid, common_comm) + common_secs, common_nsecs, common_pid, common_comm, + common_callchain, vec): + print_header(event_name, common_cpu, common_secs, common_nsecs, + common_pid, common_comm) - print_uncommon(context) + print_uncommon(context) - print "vec=%s\n" % \ - (symbol_str("irq__softirq_entry", "vec", vec)), + print "vec=%s\n" % (symbol_str("irq__softirq_entry", "vec", vec)), def kmem__kmalloc(event_name, context, common_cpu, - common_secs, common_nsecs, common_pid, common_comm, - common_callchain, call_site, ptr, bytes_req, bytes_alloc, - gfp_flags): - print_header(event_name, common_cpu, common_secs, common_nsecs, - common_pid, common_comm) + common_secs, common_nsecs, common_pid, common_comm, + common_callchain, call_site, ptr, bytes_req, bytes_alloc, + gfp_flags): + print_header(event_name, common_cpu, common_secs, common_nsecs, + common_pid, common_comm) - print_uncommon(context) + print_uncommon(context) - print "call_site=%u, ptr=%u, bytes_req=%u, " \ + print "call_site=%u, ptr=%u, bytes_req=%u, " \ "bytes_alloc=%u, gfp_flags=%s\n" % \ (call_site, ptr, bytes_req, bytes_alloc, - flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)), def trace_unhandled(event_name, context, event_fields_dict): - try: - unhandled[event_name] += 1 - except TypeError: - unhandled[event_name] = 1 + try: + unhandled[event_name] += 1 + except TypeError: + unhandled[event_name] = 1 def print_header(event_name, cpu, secs, nsecs, pid, comm): print "%-20s %5u %05u.%09u %8u %-20s " % \ - (event_name, cpu, secs, nsecs, pid, comm), + (event_name, cpu, secs, nsecs, pid, comm), # print trace fields not included in handler args def print_uncommon(context): - print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \ - % (common_pc(context), trace_flag_str(common_flags(context)), \ - common_lock_depth(context)) + print "common_preempt_count=%d, common_flags=%s, " \ + "common_lock_depth=%d, " % \ + (common_pc(context), trace_flag_str(common_flags(context)), + common_lock_depth(context)) def print_unhandled(): - keys = unhandled.keys() - if not keys: - return + keys = unhandled.keys() + if not keys: + return - print "\nunhandled events:\n\n", + print "\nunhandled events:\n\n", - print "%-40s %10s\n" % ("event", "count"), - print "%-40s %10s\n" % ("----------------------------------------", \ - "-----------"), + print "%-40s %10s\n" % ("event", "count"), + print "%-40s %10s\n" % ("----------------------------------------", \ + "-----------"), - for event_name in keys: - print "%-40s %10d\n" % (event_name, unhandled[event_name]) + for event_name in keys: + print "%-40s %10d\n" % (event_name, unhandled[event_name])
tools/perf/scripts/python/compaction-times.py +4 -4
@@ -216,15 +216,15 @@ def compaction__mm_compaction_migratepages(event_name, context, common_cpu, pair(nr_migrated, nr_failed), None, None) def compaction__mm_compaction_isolate_freepages(event_name, context, common_cpu, - common_secs, common_nsecs, common_pid, common_comm, - common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken): + common_secs, common_nsecs, common_pid, common_comm, + common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken): chead.increment_pending(common_pid, None, pair(nr_scanned, nr_taken), None) def compaction__mm_compaction_isolate_migratepages(event_name, context, common_cpu, - common_secs, common_nsecs, common_pid, common_comm, - common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken): + common_secs, common_nsecs, common_pid, common_comm, + common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken): chead.increment_pending(common_pid, None, None, pair(nr_scanned, nr_taken))
tools/perf/scripts/python/event_analyzing_sample.py +3 -3
@@ -37,7 +37,7 @@ con = sqlite3.connect("/dev/shm/perf.db") con.isolation_level = None def trace_begin(): - print "In trace_begin:\n" + print "In trace_begin:\n" # # Will create several tables at the start, pebs_ll is for PEBS data with
@@ -102,7 +102,7 @@ def insert_db(event): event.ip, event.status, event.dse, event.dla, event.lat)) def trace_end(): - print "In trace_end:\n" + print "In trace_end:\n" # We show the basic info for the 2 type of event classes show_general_events() show_pebs_ll()
@@ -187,4 +187,4 @@ def show_pebs_ll(): print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) def trace_unhandled(event_name, context, event_fields_dict): - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
tools/perf/scripts/python/failed-syscalls-by-pid.py +19 -19
@@ -58,22 +58,22 @@ def syscalls__sys_exit(event_name, context, common_cpu, raw_syscalls__sys_exit(**locals()) def print_error_totals(): - if for_comm is not None: - print("\nsyscall errors for %s:\n" % (for_comm)) - else: - print("\nsyscall errors:\n") - - print("%-30s %10s" % ("comm [pid]", "count")) - print("%-30s %10s" % ("------------------------------", "----------")) - - comm_keys = syscalls.keys() - for comm in comm_keys: - pid_keys = syscalls[comm].keys() - for pid in pid_keys: - print("\n%s [%d]" % (comm, pid)) - id_keys = syscalls[comm][pid].keys() - for id in id_keys: - print(" syscall: %-16s" % syscall_name(id)) - ret_keys = syscalls[comm][pid][id].keys() - for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]), reverse = True): - print(" err = %-20s %10d" % (strerror(ret), val)) + if for_comm is not None: + print("\nsyscall errors for %s:\n" % (for_comm)) + else: + print("\nsyscall errors:\n") + + print("%-30s %10s" % ("comm [pid]", "count")) + print("%-30s %10s" % ("------------------------------", "----------")) + + comm_keys = syscalls.keys() + for comm in comm_keys: + pid_keys = syscalls[comm].keys() + for pid in pid_keys: + print("\n%s [%d]" % (comm, pid)) + id_keys = syscalls[comm][pid].keys() + for id in id_keys: + print(" syscall: %-16s" % syscall_name(id)) + ret_keys = syscalls[comm][pid][id].keys() + for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]), reverse = True): + print(" err = %-20s %10d" % (strerror(ret), val))
tools/perf/scripts/python/futex-contention.py +1 -1
@@ -46,5 +46,5 @@ def trace_end(): for (tid, lock) in lock_waits: min, max, avg, count = lock_waits[tid, lock] print "%s[%d] lock %x contended %d times, %d avg ns" % \ - (process_names[tid], tid, lock, count, avg) + (process_names[tid], tid, lock, count, avg)
tools/perf/scripts/python/intel-pt-events.py +16 -16
@@ -85,22 +85,22 @@ def print_common_ip(sample, symbol, dso): print "%16x %s (%s)" % (ip, symbol, dso) def process_event(param_dict): - event_attr = param_dict["attr"] - sample = param_dict["sample"] - raw_buf = param_dict["raw_buf"] - comm = param_dict["comm"] - name = param_dict["ev_name"] - - # Symbol and dso info are not always resolved - if (param_dict.has_key("dso")): - dso = param_dict["dso"] - else: - dso = "[unknown]" - - if (param_dict.has_key("symbol")): - symbol = param_dict["symbol"] - else: - symbol = "[unknown]" + event_attr = param_dict["attr"] + sample = param_dict["sample"] + raw_buf = param_dict["raw_buf"] + comm = param_dict["comm"] + name = param_dict["ev_name"] + + # Symbol and dso info are not always resolved + if (param_dict.has_key("dso")): + dso = param_dict["dso"] + else: + dso = "[unknown]" + + if (param_dict.has_key("symbol")): + symbol = param_dict["symbol"] + else: + symbol = "[unknown]" if name == "ptwrite": print_common_start(comm, sample, name)
tools/perf/scripts/python/mem-phys-addr.py +4 -3
@@ -44,12 +44,13 @@ def print_memory_type(): print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), end='') print("%-40s %10s %10s\n" % ("----------------------------------------", "-----------", "-----------"), - end=''); + end=''); total = sum(load_mem_type_cnt.values()) for mem_type, count in sorted(load_mem_type_cnt.most_common(), \ key = lambda kv: (kv[1], kv[0]), reverse = True): - print("%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total), - end='') + print("%-40s %10d %10.1f%%\n" % + (mem_type, count, 100 * count / total), + end='') def trace_begin(): parse_iomem()
tools/perf/scripts/python/net_dropmonitor.py +1 -1
@@ -7,7 +7,7 @@ import os import sys sys.path.append(os.environ['PERF_EXEC_PATH'] + \ - '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import *
tools/perf/scripts/python/netdev-times.py +7 -5
@@ -124,14 +124,16 @@ def print_receive(hunk): event = event_list[i] if event['event_name'] == 'napi_poll': print(PF_NAPI_POLL % - (diff_msec(base_t, event['event_t']), event['dev'])) + (diff_msec(base_t, event['event_t']), + event['dev'])) if i == len(event_list) - 1: print("") else: print(PF_JOINT) else: print(PF_NET_RECV % - (diff_msec(base_t, event['event_t']), event['skbaddr'], + (diff_msec(base_t, event['event_t']), + event['skbaddr'], event['len'])) if 'comm' in event.keys(): print(PF_WJOINT)
@@ -256,7 +258,7 @@ def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, callchain, i all_event_list.append(event_info) def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, callchain, napi, - dev_name, work=None, budget=None): + dev_name, work=None, budget=None): event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, napi, dev_name, work, budget) all_event_list.append(event_info)
@@ -353,7 +355,7 @@ def handle_irq_softirq_exit(event_info): if irq_list == [] or event_list == 0: return rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time, - 'irq_list':irq_list, 'event_list':event_list} + 'irq_list':irq_list, 'event_list':event_list} # merge information realted to a NET_RX softirq receive_hunk_list.append(rec_data)
@@ -390,7 +392,7 @@ def handle_netif_receive_skb(event_info): skbaddr, skblen, dev_name) = event_info if cpu in net_rx_dic.keys(): rec_data = {'event_name':'netif_receive_skb', - 'event_t':time, 'skbaddr':skbaddr, 'len':skblen} + 'event_t':time, 'skbaddr':skbaddr, 'len':skblen} event_list = net_rx_dic[cpu]['event_list'] event_list.append(rec_data) rx_skb_list.insert(0, rec_data)
tools/perf/scripts/python/sched-migration.py +3 -3
@@ -14,10 +14,10 @@ import sys from collections import defaultdict try: - from UserList import UserList + from UserList import UserList except ImportError: - # Python 3: UserList moved to the collections package - from collections import UserList + # Python 3: UserList moved to the collections package + from collections import UserList sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
tools/perf/scripts/python/sctop.py +7 -6
@@ -13,9 +13,9 @@ from __future__ import print_function import os, sys, time try: - import thread + import thread except ImportError: - import _thread as thread + import _thread as thread sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -75,11 +75,12 @@ def print_syscall_totals(interval): print("%-40s %10s" % ("event", "count")) print("%-40s %10s" % - ("----------------------------------------", - "----------")) + ("----------------------------------------", + "----------")) - for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \ - reverse = True): + for id, val in sorted(syscalls.items(), + key = lambda kv: (kv[1], kv[0]), + reverse = True): try: print("%-40s %10d" % (syscall_name(id), val)) except TypeError:
tools/perf/scripts/python/stackcollapse.py +1 -1
@@ -27,7 +27,7 @@ from collections import defaultdict from optparse import OptionParser, make_option sys.path.append(os.environ['PERF_EXEC_PATH'] + \ - '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import *
tools/perf/scripts/python/syscall-counts-by-pid.py +23 -24
60 lines not on this page · raw message
tools/perf/scripts/python/syscall-counts.py +15 -16
@@ -36,8 +36,8 @@ def trace_end(): print_syscall_totals() def raw_syscalls__sys_enter(event_name, context, common_cpu, - common_secs, common_nsecs, common_pid, common_comm, - common_callchain, id, args): + common_secs, common_nsecs, common_pid, common_comm, + common_callchain, id, args): if for_comm is not None: if common_comm != for_comm: return
@@ -47,20 +47,19 @@ def raw_syscalls__sys_enter(event_name, context, common_cpu, syscalls[id] = 1 def syscalls__sys_enter(event_name, context, common_cpu, - common_secs, common_nsecs, common_pid, common_comm, - id, args): + common_secs, common_nsecs, common_pid, common_comm, id, args): raw_syscalls__sys_enter(**locals()) def print_syscall_totals(): - if for_comm is not None: - print("\nsyscall events for %s:\n" % (for_comm)) - else: - print("\nsyscall events:\n") - - print("%-40s %10s" % ("event", "count")) - print("%-40s %10s" % ("----------------------------------------", - "-----------")) - - for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \ - reverse = True): - print("%-40s %10d" % (syscall_name(id), val)) + if for_comm is not None: + print("\nsyscall events for %s:\n" % (for_comm)) + else: + print("\nsyscall events:\n") + + print("%-40s %10s" % ("event", "count")) + print("%-40s %10s" % ("----------------------------------------", + "-----------")) + + for id, val in sorted(syscalls.items(), + key = lambda kv: (kv[1], kv[0]), reverse = True): + print("%-40s %10d" % (syscall_name(id), val))
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 25/35 perf script python: Add Python3 support to futex-contention.py
In reply to Arnaldo Carvalho de MeloFrom: Tony Jones <[email protected]>
Support both Python2 and Python3 in the futex-contention.py script
There may be differences in the ordering of output lines due to differences in dictionary ordering etc. However the format within lines should be unchanged.
The use of 'from __future__' implies the minimum supported Python2 version is now v2.6
--- tools/perf/scripts/python/futex-contention.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tools/perf/scripts/python/futex-contention.py +6 -4
@@ -10,6 +10,8 @@ # # Measures futex contention +from __future__ import print_function + import os, sys sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from Util import *
@@ -33,18 +35,18 @@ def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain, nr, ret): - if thread_blocktime.has_key(tid): + if tid in thread_blocktime: elapsed = nsecs(s, ns) - thread_blocktime[tid] add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed) del thread_blocktime[tid] del thread_thislock[tid] def trace_begin(): - print "Press control+C to stop and show the summary" + print("Press control+C to stop and show the summary") def trace_end(): for (tid, lock) in lock_waits: min, max, avg, count = lock_waits[tid, lock] - print "%s[%d] lock %x contended %d times, %d avg ns" % \ - (process_names[tid], tid, lock, count, avg) + print("%s[%d] lock %x contended %d times, %d avg ns" % + (process_names[tid], tid, lock, count, avg))
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 26/35 perf script python: add Python3 support to check-perf-trace.py
In reply to Arnaldo Carvalho de MeloFrom: Tony Jones <[email protected]>
Support both Python 2 and Python 3 in the check-perf-trace.py script.
There may be differences in the ordering of output lines due to differences in dictionary ordering etc. However the format within lines should be unchanged.
The use of from __future__ implies the minimum supported version of Python2 is now v2.6
--- tools/perf/scripts/python/check-perf-trace.py | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-)
tools/perf/scripts/python/check-perf-trace.py +17 -14
@@ -7,6 +7,8 @@ # events, etc. Basically, if this script runs successfully and # displays expected results, Python scripting support should be ok. +from __future__ import print_function + import os import sys
@@ -19,7 +21,7 @@ from perf_trace_context import * unhandled = autodict() def trace_begin(): - print "trace_begin" + print("trace_begin") pass def trace_end():
@@ -33,7 +35,7 @@ def irq__softirq_entry(event_name, context, common_cpu, print_uncommon(context) - print "vec=%s\n" % (symbol_str("irq__softirq_entry", "vec", vec)), + print("vec=%s" % (symbol_str("irq__softirq_entry", "vec", vec))) def kmem__kmalloc(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm,
@@ -44,10 +46,10 @@ def kmem__kmalloc(event_name, context, common_cpu, print_uncommon(context) - print "call_site=%u, ptr=%u, bytes_req=%u, " \ - "bytes_alloc=%u, gfp_flags=%s\n" % \ + print("call_site=%u, ptr=%u, bytes_req=%u, " + "bytes_alloc=%u, gfp_flags=%s" % (call_site, ptr, bytes_req, bytes_alloc, - flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)), + flag_str("kmem__kmalloc", "gfp_flags", gfp_flags))) def trace_unhandled(event_name, context, event_fields_dict): try:
@@ -56,26 +58,27 @@ def trace_unhandled(event_name, context, event_fields_dict): unhandled[event_name] = 1 def print_header(event_name, cpu, secs, nsecs, pid, comm): - print "%-20s %5u %05u.%09u %8u %-20s " % \ + print("%-20s %5u %05u.%09u %8u %-20s " % (event_name, cpu, secs, nsecs, pid, comm), + end=' ') # print trace fields not included in handler args def print_uncommon(context): - print "common_preempt_count=%d, common_flags=%s, " \ - "common_lock_depth=%d, " % \ + print("common_preempt_count=%d, common_flags=%s, " + "common_lock_depth=%d, " % (common_pc(context), trace_flag_str(common_flags(context)), - common_lock_depth(context)) + common_lock_depth(context))) def print_unhandled(): keys = unhandled.keys() if not keys: return - print "\nunhandled events:\n\n", + print("\nunhandled events:\n") - print "%-40s %10s\n" % ("event", "count"), - print "%-40s %10s\n" % ("----------------------------------------", \ - "-----------"), + print("%-40s %10s" % ("event", "count")) + print("%-40s %10s" % ("----------------------------------------", + "-----------")) for event_name in keys: - print "%-40s %10d\n" % (event_name, unhandled[event_name]) + print("%-40s %10d\n" % (event_name, unhandled[event_name]))
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 27/35 perf script python: Add Python3 support to event_analyzing_sample.py
In reply to Arnaldo Carvalho de MeloFrom: Tony Jones <[email protected]>
Support both Python2 and Python3 in the event_analyzing_sample.py script
There may be differences in the ordering of output lines due to differences in dictionary ordering etc. However the format within lines should be unchanged.
The use of 'from __future__' implies the minimum supported Python2 version is now v2.6
--- .../scripts/python/event_analyzing_sample.py | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-)
tools/perf/scripts/python/event_analyzing_sample.py +25 -23
@@ -15,6 +15,8 @@ # for a x86 HW PMU event: PEBS with load latency data. # +from __future__ import print_function + import os import sys import math
@@ -37,7 +39,7 @@ con = sqlite3.connect("/dev/shm/perf.db") con.isolation_level = None def trace_begin(): - print "In trace_begin:\n" + print("In trace_begin:\n") # # Will create several tables at the start, pebs_ll is for PEBS data with
@@ -76,12 +78,12 @@ def process_event(param_dict): name = param_dict["ev_name"] # Symbol and dso info are not always resolved - if (param_dict.has_key("dso")): + if ("dso" in param_dict): dso = param_dict["dso"] else: dso = "Unknown_dso" - if (param_dict.has_key("symbol")): + if ("symbol" in param_dict): symbol = param_dict["symbol"] else: symbol = "Unknown_symbol"
@@ -102,7 +104,7 @@ def insert_db(event): event.ip, event.status, event.dse, event.dla, event.lat)) def trace_end(): - print "In trace_end:\n" + print("In trace_end:\n") # We show the basic info for the 2 type of event classes show_general_events() show_pebs_ll()
@@ -123,29 +125,29 @@ def show_general_events(): # Check the total record number in the table count = con.execute("select count(*) from gen_events") for t in count: - print "There is %d records in gen_events table" % t[0] + print("There is %d records in gen_events table" % t[0]) if t[0] == 0: return - print "Statistics about the general events grouped by thread/symbol/dso: \n" + print("Statistics about the general events grouped by thread/symbol/dso: \n") # Group by thread commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)") - print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42) + print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)) for row in commq: - print "%16s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%16s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by symbol - print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58) + print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)) symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)") for row in symbolq: - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by dso - print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74) + print("\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)) dsoq = con.execute("select dso, count(dso) from gen_events group by dso order by -count(dso)") for row in dsoq: - print "%40s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%40s %8d %s" % (row[0], row[1], num2sym(row[1]))) # # This function just shows the basic info, and we could do more with the
@@ -156,35 +158,35 @@ def show_pebs_ll(): count = con.execute("select count(*) from pebs_ll") for t in count: - print "There is %d records in pebs_ll table" % t[0] + print("There is %d records in pebs_ll table" % t[0]) if t[0] == 0: return - print "Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n" + print("Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n") # Group by thread commq = con.execute("select comm, count(comm) from pebs_ll group by comm order by -count(comm)") - print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42) + print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)) for row in commq: - print "%16s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%16s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by symbol - print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58) + print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)) symbolq = con.execute("select symbol, count(symbol) from pebs_ll group by symbol order by -count(symbol)") for row in symbolq: - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by dse dseq = con.execute("select dse, count(dse) from pebs_ll group by dse order by -count(dse)") - print "\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58) + print("\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58)) for row in dseq: - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) # Group by latency latq = con.execute("select lat, count(lat) from pebs_ll group by lat order by lat") - print "\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58) + print("\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58)) for row in latq: - print "%32s %8d %s" % (row[0], row[1], num2sym(row[1])) + print("%32s %8d %s" % (row[0], row[1], num2sym(row[1]))) def trace_unhandled(event_name, context, event_fields_dict): - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + print (' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 28/35 perf script python: Add Python3 support to intel-pt-events.py
In reply to Arnaldo Carvalho de MeloFrom: Tony Jones <[email protected]>
Support both Python2 and Python3 in the intel-pt-events.py script
There may be differences in the ordering of output lines due to differences in dictionary ordering etc. However the format within lines should be unchanged.
The use of 'from __future__' implies the minimum supported Python2 version is now v2.6
--- tools/perf/scripts/python/intel-pt-events.py | 32 ++++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-)
tools/perf/scripts/python/intel-pt-events.py +19 -13
@@ -10,6 +10,8 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function + import os import sys import struct
@@ -22,34 +24,34 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ #from Core import * def trace_begin(): - print "Intel PT Power Events and PTWRITE" + print("Intel PT Power Events and PTWRITE") def trace_end(): - print "End" + print("End") def trace_unhandled(event_name, context, event_fields_dict): - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])) def print_ptwrite(raw_buf): data = struct.unpack_from("<IQ", raw_buf) flags = data[0] payload = data[1] exact_ip = flags & 1 - print "IP: %u payload: %#x" % (exact_ip, payload), + print("IP: %u payload: %#x" % (exact_ip, payload), end=' ') def print_cbr(raw_buf): data = struct.unpack_from("<BBBBII", raw_buf) cbr = data[0] f = (data[4] + 500) / 1000 p = ((cbr * 1000 / data[2]) + 5) / 10 - print "%3u freq: %4u MHz (%3u%%)" % (cbr, f, p), + print("%3u freq: %4u MHz (%3u%%)" % (cbr, f, p), end=' ') def print_mwait(raw_buf): data = struct.unpack_from("<IQ", raw_buf) payload = data[1] hints = payload & 0xff extensions = (payload >> 32) & 0x3 - print "hints: %#x extensions: %#x" % (hints, extensions), + print("hints: %#x extensions: %#x" % (hints, extensions), end=' ') def print_pwre(raw_buf): data = struct.unpack_from("<IQ", raw_buf)
@@ -57,13 +59,14 @@ def print_pwre(raw_buf): hw = (payload >> 7) & 1 cstate = (payload >> 12) & 0xf subcstate = (payload >> 8) & 0xf - print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), + print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), + end=' ') def print_exstop(raw_buf): data = struct.unpack_from("<I", raw_buf) flags = data[0] exact_ip = flags & 1 - print "IP: %u" % (exact_ip), + print("IP: %u" % (exact_ip), end=' ') def print_pwrx(raw_buf): data = struct.unpack_from("<IQ", raw_buf)
@@ -71,18 +74,21 @@ def print_pwrx(raw_buf): deepest_cstate = payload & 0xf last_cstate = (payload >> 4) & 0xf wake_reason = (payload >> 8) & 0xf - print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), + print("deepest cstate: %u last cstate: %u wake reason: %#x" % + (deepest_cstate, last_cstate, wake_reason), end=' ') def print_common_start(comm, sample, name): ts = sample["time"] cpu = sample["cpu"] pid = sample["pid"] tid = sample["tid"] - print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), + print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % + (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), + end=' ') def print_common_ip(sample, symbol, dso): ip = sample["ip"] - print "%16x %s (%s)" % (ip, symbol, dso) + print("%16x %s (%s)" % (ip, symbol, dso)) def process_event(param_dict): event_attr = param_dict["attr"]
@@ -92,12 +98,12 @@ def process_event(param_dict): name = param_dict["ev_name"] # Symbol and dso info are not always resolved - if (param_dict.has_key("dso")): + if "dso" in param_dict: dso = param_dict["dso"] else: dso = "[unknown]" - if (param_dict.has_key("symbol")): + if "symbol" in param_dict: symbol = param_dict["symbol"] else: symbol = "[unknown]"
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 29/35 perf c2c: Fix c2c report for empty numa node
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Ravi Bangoria reported that we fail with an empty NUMA node with the following message:
$ lscpu NUMA node0 CPU(s): NUMA node1 CPU(s): 0-4
$ sudo ./perf c2c report node/cpu topology bugFailed setup nodes
Fix this by detecting the empty node and keeping its CPU set empty.
--- tools/perf/builtin-c2c.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-c2c.c +6 -2
@@ -2056,6 +2056,12 @@ static int setup_nodes(struct perf_session *session)if (!set)return -ENOMEM ; + nodes[node] = set; + +/* empty node, skip */ +if (cpu_map__empty (map)) +continue ; +for (cpu =0 ; cpu < map->nr; cpu++) {set_bit (map->map[cpu], set);
@@ -2064,8 +2070,6 @@ static int setup_nodes(struct perf_session *session) cpu2node[map->map[cpu]] = node; } - - nodes[node] = set; }setup_nodes_header ();
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 30/35 perf hist: Add error path into hist_entry__init
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding error path into hist_entry__init to unify error handling, so every new member does not need to free everything else.
--- tools/perf/util/hist.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
tools/perf/util/hist.c +19 -20
@@ -396,11 +396,8 @@ static int hist_entry__init(struct hist_entry *he,* adding new entries. So we need to save a copy. */ he->branch_info =malloc (sizeof (*he->branch_info)); -if (he->branch_info ==NULL ) { -map__zput (he->ms.map); -free (he->stat_acc); -return -ENOMEM ; - } +if (he->branch_info ==NULL ) + goto err;memcpy (he->branch_info, template->branch_info,sizeof (*he->branch_info));
@@ -419,21 +416,8 @@ static int hist_entry__init(struct hist_entry *he,if (he->raw_data) { he->raw_data =memdup (he->raw_data, he->raw_size); - -if (he->raw_data ==NULL ) { -map__put (he->ms.map); -if (he->branch_info) { -map__put (he->branch_info->from.map); -map__put (he->branch_info->to.map); -free (he->branch_info); - } -if (he->mem_info) { -map__put (he->mem_info->iaddr.map); -map__put (he->mem_info->daddr.map); - } -free (he->stat_acc); -return -ENOMEM ; - } +if (he->raw_data ==NULL ) + goto err_infos; }INIT_LIST_HEAD (&he->pairs.node);thread__get (he->thread);
@@ -444,6 +428,21 @@ static int hist_entry__init(struct hist_entry *he, he->leaf = true;return 0 ; + +err_infos: +if (he->branch_info) { +map__put (he->branch_info->from.map); +map__put (he->branch_info->to.map); +free (he->branch_info); + } +if (he->mem_info) { +map__put (he->mem_info->iaddr.map); +map__put (he->mem_info->daddr.map); + } +err: +map__zput (he->ms.map); +free (he->stat_acc); +return -ENOMEM ; }static void *hist_entry__zalloc (size_t size)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 31/35 perf hist: Fix memory leak of srcline
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
We can't allocate he->srcline unconditionaly, only when new hist_entry is created. Moving he->srcline allocation into hist_entry__init function.
--- tools/perf/util/hist.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
tools/perf/util/hist.c +12 -2
@@ -419,6 +419,13 @@ static int hist_entry__init(struct hist_entry *he,if (he->raw_data ==NULL ) goto err_infos; } + +if (he->srcline) { + he->srcline =strdup (he->srcline); +if (he->srcline ==NULL ) + goto err_rawdata; + } +INIT_LIST_HEAD (&he->pairs.node);thread__get (he->thread); he->hroot_in =RB_ROOT_CACHED ;
@@ -429,6 +436,9 @@ static int hist_entry__init(struct hist_entry *he,return 0 ; +err_rawdata: +free (he->raw_data); + err_infos:if (he->branch_info) {map__put (he->branch_info->from.map);
@@ -605,7 +615,7 @@ __hists__add_entry(struct hists *hists, .map = al->map, .sym = al->sym, }, - .srcline = al->srcline ? strdup(al->srcline) : NULL, + .srcline = (char *) al->srcline, .socket = al->socket, .cpu = al->cpu, .cpumode = al->cpumode,
@@ -962,7 +972,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, .map = al->map, .sym = al->sym, }, - .srcline = al->srcline ? strdup(al->srcline) : NULL, + .srcline = (char *) al->srcline, .parent = iter->parent, .raw_data = sample->raw_data, .raw_size = sample->raw_size,
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 32/35 perf tools: Read and store caps/max_precise in perf_pmu
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Read the caps/max_precise value and store it in struct perf_pmu to be used when setting the maximum precise_ip field in following patch.
--- tools/perf/util/pmu.c | 14 ++++++++++++++ tools/perf/util/pmu.h | 1 + 2 files changed, 15 insertions(+)
tools/perf/util/pmu.c +14 -0
@@ -752,6 +752,19 @@ perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)return NULL ; } +static int pmu_max_precise (const char *name) +{ +char path[PATH_MAX ]; +int max_precise =-1 ; + +scnprintf (path,PATH_MAX , +"bus/event_source/devices/%s/caps/max_precise" , + name); + +sysfs__read_int (path, &max_precise); +return max_precise; +} +static struct perf_pmu *pmu_lookup (const char *name) {struct perf_pmu *pmu;
@@ -784,6 +797,7 @@ static struct perf_pmu *pmu_lookup(const char *name) pmu->name =strdup (name); pmu->type = type; pmu->is_uncore =pmu_is_uncore (name); + pmu->max_precise =pmu_max_precise (name);pmu_add_cpu_aliases (&aliases, pmu);INIT_LIST_HEAD (&pmu->format);
tools/perf/util/pmu.h +1 -0
@@ -26,6 +26,7 @@ struct perf_pmu {__u32 type;bool selectable;bool is_uncore; +int max_precise;struct perf_event_attr *default_config;struct cpu_map *cpus;struct list_head format;/* HEAD struct perf_pmu_format -> list */
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 33/35 perf evsel: Probe for precise_ip with simple attr
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Currently we probe for precise_ip with user specified perf_event_attr, which might fail because of unsupported kernel features, which would get disabled during the open time anyway.
Switching the probe to take place on simple hw cycles, so the following record sets proper precise_ip:
# perf record -e cycles:P ls # perf evlist -v cycles:P: size: 112, ... precise_ip: 3, ...
--- tools/perf/util/evlist.c | 25 ++++++++++++++++++++----- tools/perf/util/evsel.c | 8 -------- 2 files changed, 20 insertions(+), 13 deletions(-)
tools/perf/util/evlist.c +20 -5
@@ -230,18 +230,33 @@ void perf_evlist__set_leader(struct perf_evlist *evlist) } } -void perf_event_attr__set_max_precise_ip (struct perf_event_attr *attr) +void perf_event_attr__set_max_precise_ip (struct perf_event_attr *pattr) { - attr->precise_ip =3 ; +struct perf_event_attr attr = { + .type =PERF_TYPE_HARDWARE , + .config =PERF_COUNT_HW_CPU_CYCLES , + .exclude_kernel =1 , + .precise_ip =3 , + }; -while (attr->precise_ip !=0 ) { -int fd =sys_perf_event_open (attr,0 ,-1 ,-1 ,0 ); +event_attr_init (&attr); + +/* +* Unnamed union member, not supported as struct member named +* initializer in older compilers such as gcc 4.4.7 +*/ + attr.sample_period =1 ; + +while (attr.precise_ip !=0 ) { +int fd =sys_perf_event_open (&attr,0 ,-1 ,-1 ,0 );if (fd !=-1 ) {close (fd);break ; } - --attr->precise_ip; + --attr.precise_ip; } + + pattr->precise_ip = attr.precise_ip; }int __perf_evlist__add_default (struct perf_evlist *evlist,bool precise)
tools/perf/util/evsel.c +0 -8
@@ -294,20 +294,12 @@ struct perf_evsel *perf_evsel__new_cycles(bool precise)if (!precise) goto new_event; -/* -* Unnamed union member, not supported as struct member named -* initializer in older compilers such as gcc 4.4.7 -* -* Just for probing the precise_ip: -*/ - attr.sample_period =1 ;perf_event_attr__set_max_precise_ip (&attr);/* * Now let the usual logic to set up the perf_event_attr defaults * to kick in when we return and before perf_evsel__open() is called. */ - attr.sample_period =0 ; new_event: evsel =perf_evsel__new (&attr);if (evsel ==NULL )
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 34/35 perf session: Fix double free in perf_data__close
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
We can't call perf_data__close and subsequently perf_session__delete, because it will call perf_data__close again and cause double free for data->file.path.
$ perf report -i . incompatible file format (rerun with -v to learn more) free(): double free detected in tcache 2 Aborted (core dumped)
In fact we don't need to call perf_data__close at all, because at the time the got out_close is reached, session->data is already initialized, so the perf_data__close call will be triggered from perf_session__delete.
--- tools/perf/util/session.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/util/session.c +1 -3
@@ -140,7 +140,7 @@ struct perf_session *perf_session__new(struct perf_data *data,if (perf_data__is_read (data)) {if (perf_session__open (session) <0 ) - goto out_close; + goto out_delete;/* * set session attributes that are present in perf.data
@@ -181,8 +181,6 @@ struct perf_session *perf_session__new(struct perf_data *data,return session; - out_close: -perf_data__close (data); out_delete:perf_session__delete (session); out:
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 35/35 perf data: Force perf_data__open|close zero data->file.path
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Making sure the data->file.path is zeroed on perf_data__open error path and in perf_data__close, so we don't double free it in case someone call it twice.
--- tools/perf/util/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/data.c +2 -2
@@ -237,7 +237,7 @@ static int open_file(struct perf_data *data) open_file_read(data) : open_file_write(data);if (fd <0 ) { -free (data->file.path); +zfree (&data->file.path);return -1 ; }
@@ -270,7 +270,7 @@ int perf_data__open(struct perf_data *data)void perf_data__close (struct perf_data *data) { -free (data->file.path); +zfree (&data->file.path);close (data->file.fd); }
Signature · 1 line
2.20.1
Re: [PATCH 02/35] perf probe: Clarify error message about not finding kernel modules debuginfo
In reply to Arnaldo Carvalho de MeloQuoted 5 lines · On Thu, 7 Mar 2019 14:44:00 -0300 Arnaldo Carvalho de Melo <[email protected]>…
From: Arnaldo Carvalho de Melo <[email protected]>
'perf probe' supports using just the kernel module name, but that will work only when the module is loaded, or using the full pathname to the file with the DWARF debug info, but the warning was cryptic:
Agreed, this looks good to me.
Thank you!
Quoted 70 lines
Before:
# perf probe -m cls_flower -L fl_change Failed to find the path for cls_flower: No such file or directory Error: Failed to show lines. #After:
# perf probe -m cls_flower -L fl_change Module cls_flower is not loaded, please specify its full path name. Error: Failed to show lines. # perf probe -m /lib/modules/5.0.0-rc7+/kernel/net/sched/cls_flower.ko -L fl_change | head -7 <fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0> 0 static int fl_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, void **arg, bool ovr, struct netlink_ext_ack *extack) 4 { 5 struct cls_fl_head *head = rtnl_dereference(tp->root); #The behaviour doesn't change when the module is loaded:
# modprobe cls_flower # perf probe -m cls_flower -L fl_change | head -7 <fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0> 0 static int fl_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, void **arg, bool ovr, struct netlink_ext_ack *extack) 4 { 5 struct cls_fl_head *head = rtnl_dereference(tp->root); #Cc Adrian Hunter <[email protected]>Cc Jiri Olsa <[email protected]>Cc Marcelo Ricardo Leitner <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/probe-event.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/perf/util/probe-event.c +6
-3@@ -472,9 +472,12 @@ static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi,strcpy (reason,"(unknown)" ); }else dso__strerror_load (dso, reason,STRERR_BUFSIZE ); -if (!silent) -pr_err ("Failed to find the path for %s: %s\n" , - module ?:"kernel" , reason); +if (!silent) { +if (module) +pr_err ("Module %s is not loaded, please specify its full path name.\n" , module); +else +pr_err ("Failed to find the path for the kernel: %s\n" , reason); + }return NULL ; } path = dso->long_name;Signature · 1 line
2.20.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
Re: [PATCH 02/35] perf probe: Clarify error message about not finding kernel modules debuginfo
Em Fri, Mar 08, 2019 at 08:30:33AM +0900, Masami Hiramatsu escreveu:
Quoted 5 lines
Quoted 2 lines · On Thu, 7 Mar 2019 14:44:00 -0300 Arnaldo Carvalho de Melo <[email protected]>…
From: Arnaldo Carvalho de Melo <[email protected]>
Quoted 7 lines
Quoted 3 lines
'perf probe' supports using just the kernel module name, but that will work only when the module is loaded, or using the full pathname to the file with the DWARF debug info, but the warning was cryptic:
Agreed, this looks good to me.
Acked-by Masami Hiramatsu <[email protected]>
Thanks for checking!
- Arnaldo
Quoted 76 lines
Thank you!
Quoted 70 lines
Before:
# perf probe -m cls_flower -L fl_change Failed to find the path for cls_flower: No such file or directory Error: Failed to show lines. #After:
# perf probe -m cls_flower -L fl_change Module cls_flower is not loaded, please specify its full path name. Error: Failed to show lines. # perf probe -m /lib/modules/5.0.0-rc7+/kernel/net/sched/cls_flower.ko -L fl_change | head -7 <fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0> 0 static int fl_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, void **arg, bool ovr, struct netlink_ext_ack *extack) 4 { 5 struct cls_fl_head *head = rtnl_dereference(tp->root); #The behaviour doesn't change when the module is loaded:
# modprobe cls_flower # perf probe -m cls_flower -L fl_change | head -7 <fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0> 0 static int fl_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, void **arg, bool ovr, struct netlink_ext_ack *extack) 4 { 5 struct cls_fl_head *head = rtnl_dereference(tp->root); #Cc Adrian Hunter <[email protected]>Cc Jiri Olsa <[email protected]>Cc Marcelo Ricardo Leitner <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/probe-event.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/perf/util/probe-event.c +6
-3@@ -472,9 +472,12 @@ static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi,strcpy (reason,"(unknown)" ); }else dso__strerror_load (dso, reason,STRERR_BUFSIZE ); -if (!silent) -pr_err ("Failed to find the path for %s: %s\n" , - module ?:"kernel" , reason); +if (!silent) { +if (module) +pr_err ("Module %s is not loaded, please specify its full path name.\n" , module); +else +pr_err ("Failed to find the path for the kernel: %s\n" , reason); + }return NULL ; } path = dso->long_name;Signature · 1 line
2.20.1Signature · 1 line
Masami Hiramatsu <[email protected]>
Signature · 1 line
- Arnaldo
Quoted 216 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit
c978b9460fe1d4a1e1effa0abd6bd69b18a098a8:Merge tag 'perf-core-for-mingo-5.1-20190225' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxinto perf/core (2019-02-28 08:29:50 +0100)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-5.1-20190307for you to fetch changes up to
b8f7d86b5849ea7bb84bddc0345a3799049764d4:perf data: Force perf_data__open|close zero
data->file.path(2019-03-06 18:21:00 -0300)----------------------------------------------------------------
perf bpf:Arnaldo Carvalho de Melo:
- Automatically add BTF ELF markers to 'perf trace' BPF programs, so that tools such as 'bpftool map dump' can pretty print map keys and values.
perf c2c:
Jiri Olsa:
- Fix report for empty NUMA node.
perf diff:
Jin Yao:
- Support --time, --cpu, --pid and --tid filter options.
perf probe:
Arnaldo Carvalho de Melo:
- Clarify error message about not finding kernel modules debuginfo.
perf record:
Jiri Olsa:
- Fixup probing for max attr.precise_ip.
perf trace:
Arnaldo Carvalho de Melo:
- Add missing %s lost in the '
msg_flags' recvmmsg arg when adding prefix suppression logic.perf annotate:
Arnaldo Carvalho de Melo:
- Calculate the max instruction name, align column to that, removing the hardcoded max 6 chars and cope with instructions with names longer than that, such as vpmovmskb, vpcmpeqb, etc.
kernel:
Song Liu:
- Consider events with attr.bpf_event set as side-band.
Gustavo A. R. Silva:
- Mark expected switch fall-through in
perf_event_parse_addr_filter().Libraries:
Jiri Olsa:
- Fix leaks and double frees on error paths.
libtraceevent:
Tony Jones:
- Fix buffer overflow in
arg_eval().python scripting:
Tony Jones:
- More python3 fixes.
Trivial:
Yang Wei:
- Remove needless extra semicolon in clang C++ glue code.
Intel PT/BTS:
Adrian Hunter:
- Improve auxtrace address filter error message when there is no DSO.
- Fix divide by zero when TSC is not available.
- Further improvements to the export to sqlite/posgresql python scripts and to the GUI sqlviewer, exporting '
parent_id' so that we have enable the creation of call trees.Andi Kleen:
- Generalize function to copy from thread addr space from intel-bts code.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Adrian Hunter (10):
perf auxtrace: Improve address filter error message when there is no DSO perf intel-pt: Fix divide by zero when TSC is not available
perf db-export: Add callsparent_idto enable creation of call trees
perf scripts python:export-to-sqlite.py: Export callsparent_id
perf scripts python:export-to-postgresql.py: Fix invalid input syntax for integer error perf scripts python:export-to-postgresql.py: Export callsparent_id
perf scripts python:exported-sql-viewer.py: Factor out TreeWindowBase perf scripts python:exported-sql-viewer.py: Improve TreeModel abstraction perf scripts python:exported-sql-viewer.py: Factor out CallGraphModelBase perf scripts python:exported-sql-viewer.py: Add call treeAndi Kleen (1):
perf thread: Generalize function to copy from thread addr space from intel-bts codeArnaldo Carvalho de Melo (4):
perf probe: Clarify error message about not finding kernel modules debuginfo perf beautymsg_flags: Add missing %s lost when adding prefix suppression logic perf bpf: Automatically add BTF ELF markers
perf annotate: Calculate the max instruction name, align column to thatGustavo A. R. Silva (1):
perf: Mark expected switch fall-throughJin Yao (4):
perf time-utils: Refactor time range parsing code perf diff: Support --time filter option perf diff: Support --cpu filter option perf diff: Support --pid/--tid filter optionsJiri Olsa (7):
perf c2c: Fix c2c report for empty numa node
perf hist: Add error path intohist_entry__initperf hist: Fix memory leak of srcline
perf tools: Read and store caps/max_precise inperf_pmuperf evsel: Probe forprecise_ipwith simple attr perf session: Fix double free inperf_data__closeperf data: Force perf_data__open|close zerodata->file.pathSong Liu (1):
perf, bpf: Consider events with attr.bpf_event as side-band eventsTony Jones (6):
tools lib traceevent: Fix buffer overflow inarg_evalperf script python: Remove mixed indentation
perf script python: Add Python3 support tofutex-contention.pyperf script python: add Python3 support tocheck-perf-trace.pyperf script python: Add Python3 support toevent_analyzing_sample.pyperf script python: Add Python3 support tointel-pt-events.pyYang Wei (1):
perf clang: Remove needless extra semicolonkernel/events/core.c | 4 +- tools/lib/traceevent/event-parse.c | 2 +- tools/perf/Documentation/perf-diff.txt | 56 ++++ tools/perf/arch/arm64/annotate/instructions.c | 2 +- tools/perf/arch/s390/annotate/instructions.c | 2 +- tools/perf/builtin-c2c.c | 8 +- tools/perf/builtin-diff.c | 168 +++++++++- tools/perf/builtin-report.c | 38 +-- tools/perf/builtin-script.c | 39 +-- tools/perf/include/bpf/bpf.h | 8 +- tools/perf/scripts/python/check-perf-trace.py | 76 ++--- tools/perf/scripts/python/compaction-times.py | 8 +- .../perf/scripts/python/event_analyzing_sample.py | 48 +-- tools/perf/scripts/python/export-to-postgresql.py | 16 +- tools/perf/scripts/python/export-to-sqlite.py | 12 +- tools/perf/scripts/python/exported-sql-viewer.py | 354 ++++++++++++++++----- .../perf/scripts/python/failed-syscalls-by-pid.py | 38 +-- tools/perf/scripts/python/futex-contention.py | 10 +- tools/perf/scripts/python/intel-pt-events.py | 60 ++-- tools/perf/scripts/python/mem-phys-addr.py | 7 +- tools/perf/scripts/python/net_dropmonitor.py | 2 +- tools/perf/scripts/python/netdev-times.py | 12 +- tools/perf/scripts/python/sched-migration.py | 6 +- tools/perf/scripts/python/sctop.py | 13 +- tools/perf/scripts/python/stackcollapse.py | 2 +- tools/perf/scripts/python/syscall-counts-by-pid.py | 47 ++- tools/perf/scripts/python/syscall-counts.py | 31 +- tools/perf/trace/beauty/msg_flags.c | 2 +- tools/perf/util/annotate.c | 74 +++-- tools/perf/util/annotate.h | 7 +- tools/perf/util/auxtrace.c | 3 +- tools/perf/util/c++/clang.cpp | 2 +- tools/perf/util/data.c | 4 +- tools/perf/util/db-export.c | 15 +- tools/perf/util/db-export.h | 3 +- tools/perf/util/evlist.c | 25 +- tools/perf/util/evsel.c | 8 - tools/perf/util/hist.c | 51 +-- tools/perf/util/intel-bts.c | 20 +- tools/perf/util/intel-pt.c | 2 + tools/perf/util/pmu.c | 14 + tools/perf/util/pmu.h | 1 + tools/perf/util/probe-event.c | 9 +- .../util/scripting-engines/trace-event-python.c | 8 +-
Quoted 8 lines
tools/perf/util/session.c | 4 +- tools/perf/util/thread-stack.c | 16 +- tools/perf/util/thread-stack.h | 6 +- tools/perf/util/thread.c | 23 ++ tools/perf/util/thread.h | 3 + tools/perf/util/time-utils.c | 51 ++- tools/perf/util/time-utils.h | 6 + 51 files changed, 978 insertions(+), 448 deletions(-)
Pulled, thanks a lot Arnaldo!
Ingo