perf/core improvements and fixes
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 9128d3ed9de3882c83b927eb553d5d44c84505f5:
perf/x86/msr: Clean up the code (2018-01-06 12:18:40 +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-4.16-20180110
for you to fetch changes up to 5d64db2966e38bfd99114ecf0b54f97d33023dcd:
tools headers: Synchronize kernel <-> tooling headers (2018-01-10 12:46:54 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
- The 'perf test bpf' entry hooked a eBPF proggie to the SyS_epoll_wait() kernel function and expected it to be hit when calling the epoll_wait() libc wrapper, which changed recently, in systems such as Fedora 27, with the glibc wrapper calling instead the epoll_pwait() syscall, so switch to epoll_pwait() for both the kernel and libc function, getting it to work both in old and new systems (Arnaldo Carvalho de Melo)
- Beautify 'gettid' syscall result in 'perf trace', and in doing so noticed that we need to handle namespaces in 'perf trace', will be dealt with in follow up patches where we'll try to figure out if the recent support for namespace in tools/perf/ can be used for this purpose as well. (Arnaldo Carvalho de Melo)
- Introduce 'perf report --mmaps' and 'perf report --tasks' to show info present in 'perf.data' (Jiri Olsa, Arnaldo Carvalho de Melo)
- Synchronize kernel <-> tooling headers wrt meltdown/spectre changes (Arnaldo Carvalho de Melo)
- Fix a wrong offset issue when using /proc/kcore (Jin Yao)
- Fix bug that prevented annotating symbols in perf.data files generated with 'perf record --branch-any' (Jin Yao)
- Add infrastructure to record first and last sample time to the perf.data file header, so that when processing all samples in a 'perf record' session, such as when doing build-id processing, or when specifically requesting that that info be recorded, use that in 'perf report --time', that also got support for percent slices in addition to absolute ones.
I.e. now it is possible to ask for the samples in the 10%-20% time slice of a perf.data file (Jin Yao)
- Enable building with libbabeltrace by default (Jiri Olsa)
- Display perf_event_attr::namespaces when duping the attributes in verbose mode (Jiri Olsa)
- Allocate context task_ctx_data for child event (Jiri Olsa)
- Update comments for PERF_RECORD_ITRACE_START and PERF_RECORD_MISC_* (Jiri Olsa)
- Add support for showing PERF_RECORD_LOST events in 'perf script' (Jiri Olsa)
- Add 'perf report --stats' option to display quick statistics about metadata events (PERF_RECORD_*) i.e. what we get at the end of 'perf report -D' (Jiri Olsa)
- Fix compile error with libunwind x86 (Wang Nan)
----------------------------------------------------------------
Arnaldo Carvalho de Melo (6):
perf test bpf: Improve message about expected samples perf test bpf: Use designated struct field initializers perf test bpf: Hook on epoll_pwait()
perf trace: Beautify 'gettid' syscall result perf report: Introduce --mmaps
tools headers: Synchronize kernel <-> tooling headers
Jin Yao (8):
perf report: Fix a wrong offset issue when using /proc/kcore perf report: Fix a no annotate browser displayed issue perf header: Add infrastructure to record first and last sample time perf record: Record the first and last sample time in the header perf tools: Create function to parse time percent
perf tools: Create function to perform multiple time range checking perf report: Support time percent and multiple time ranges perf script: Support time percent and multiple time ranges
Jiri Olsa (12):
perf tools: Enable LIBBABELTRACE by default
perf tools: Display perf_event_attr::namespaces debug info
perf: Allocate context task_ctx_data for child event
perf: Add sample_id to PERF_RECORD_ITRACE_START event comment
perf: Make perf_callchain function static
perf: Return empty callchain instead of NULL
perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13 perf script: Add support to display sample misc field
perf script: Add support to display lost events
perf tools: Make the tool's warning messages optional
perf report: Add --stats option to display quick data statistics perf report: Add --tasks option to display monitored tasks
Wang Nan (1):
perf tools: Fix compile error with libunwind x86
include/uapi/linux/perf_event.h | 10 +- kernel/events/callchain.c | 15 -- kernel/events/core.c | 54 +++-- kernel/events/internal.h | 4 - tools/arch/x86/include/asm/cpufeatures.h | 4 +- tools/arch/x86/include/asm/disabled-features.h | 8 +- tools/include/uapi/linux/perf_event.h | 10 +- tools/perf/Documentation/perf-record.txt | 3 + tools/perf/Documentation/perf-report.txt | 37 ++- tools/perf/Documentation/perf-script.txt | 39 +++- tools/perf/Documentation/perf.data-file-format.txt | 4 + tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 2 +- tools/perf/arch/x86/util/unwind-libunwind.c | 2 +- tools/perf/builtin-record.c | 18 +- tools/perf/builtin-report.c | 249 ++++++++++++++++++++- tools/perf/builtin-script.c | 136 +++++++++-- tools/perf/builtin-trace.c | 1 + tools/perf/tests/bpf-script-example.c | 4 +- tools/perf/tests/bpf.c | 65 +++--- tools/perf/util/annotate.c | 3 +- tools/perf/util/event.c | 8 + tools/perf/util/event.h | 1 + tools/perf/util/evlist.h | 2 + tools/perf/util/evsel.c | 2 + tools/perf/util/header.c | 60 +++++ tools/perf/util/header.h | 1 + tools/perf/util/machine.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/session.c | 6 +- tools/perf/util/sort.c | 16 +- tools/perf/util/srcline.c | 9 +- tools/perf/util/srcline.h | 5 +- tools/perf/util/time-utils.c | 233 ++++++++++++++++++- tools/perf/util/time-utils.h | 6 + tools/perf/util/tool.h | 1 + 36 files changed, 884 insertions(+), 140 deletions(-)
Test results:
The first ones are container (docker) based builds of tools/perf with and without libelf support. Where clang is available, it is also used to build perf with/without libelf.
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.
# dm 1 36.42 alpine:3.4 : Ok gcc (Alpine 5.3.0) 5.3.0 2 43.36 alpine:3.5 : Ok gcc (Alpine 6.2.1) 6.2.1 20160822 3 42.02 alpine:3.6 : Ok gcc (Alpine 6.3.0) 6.3.0 4 39.44 alpine:edge : Ok gcc (Alpine 6.4.0) 6.4.0 5 34.12 amazonlinux:1 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) 6 43.12 amazonlinux:2 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 7 25.83 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 8 27.52 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 9 21.87 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 10 31.57 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) 11 37.87 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 12 35.19 debian:7 : Ok gcc (Debian 4.7.2-5) 4.7.2 13 36.66 debian:8 : Ok gcc (Debian 4.9.2-10) 4.9.2 14 60.91 debian:9 : Ok gcc (Debian 6.3.0-18) 6.3.0 20170516 15 63.71 debian:experimental : Ok gcc (Debian 7.2.0-18) 7.2.0 16 41.01 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 17 37.53 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 18 35.28 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 7.2.0-11) 7.2.0 19 38.06 debian:experimental-x-mipsel : Ok mipsel-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 20 37.48 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7) 21 40.09 fedora:21 : Ok gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) 22 38.66 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 23 38.56 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) 24 40.34 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) 25 33.60 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 26 76.30 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1) 27 83.91 fedora:26 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 28 76.94 fedora:27 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) 29 84.12 fedora:rawhide : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-4) 30 39.65 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 6.4.0 p1.1) 6.4.0 31 40.31 mageia:5 : Ok gcc (GCC) 4.9.2 32 40.96 mageia:6 : Ok gcc (Mageia 5.4.0-5.mga6) 5.4.0 33 40.56 opensuse:42.1 : Ok gcc (SUSE Linux) 4.8.5 34 44.99 opensuse:42.2 : Ok gcc (SUSE Linux) 4.8.5 35 39.41 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5 36 82.57 opensuse:tumbleweed : Ok gcc (SUSE Linux) 7.2.1 20171020 [gcc-7-branch revision 253932] 37 31.39 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) 38 37.82 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 39 29.52 ubuntu:12.04.5 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 40 35.32 ubuntu:14.04.4 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 41 31.84 ubuntu:14.04.4-x-linaro-arm64 : Ok aarch64-linux-gnu-gcc (Linaro GCC 5.5-2017.10) 5.5.0 42 59.60 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609 43 32.43 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 44 30.82 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 45 30.35 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 46 32.15 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609 47 31.77 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 48 31.49 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 49 62.81 ubuntu:16.10 : Ok gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005 50 64.87 ubuntu:17.04 : Ok gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406 51 63.93 ubuntu:17.10 : Ok gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0 52 64.43 ubuntu:18.04 : Ok gcc (Ubuntu 7.2.0-18ubuntu2) 7.2.0 #
# uname -a Linux seventh 4.15.0-rc7+ #2 SMP Wed Jan 10 11:53:43 -03 2018 x86_64 x86_64 x86_64 GNU/Linux # 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: Number of exit events of a simple workload : Ok 22: Software clock events period values : Ok 23: Object code reading : Ok 24: Sample parsing : Ok 25: Use a dummy software event to keep tracking : Ok 26: Parse with no sample_id_all bit set : Ok 27: Filter hist entries : Ok 28: Lookup mmap thread : Ok 29: Share thread mg : Ok 30: Sort output of hist entries : Ok 31: Cumulate child hist entries : Ok 32: Track with sched_switch : Ok 33: Filter fds with revents mask in a fdarray : Ok 34: Add fd to a fdarray, making it autogrow : Ok 35: kmod_path__parse : Ok 36: Thread map : Ok 37: LLVM search and compile : 37.1: Basic BPF llvm compile : Ok 37.2: kbuild searching : Ok 37.3: Compile source for BPF prologue generation : Ok 37.4: Compile source for BPF relocation : Ok 38: Session topology : Ok 39: BPF filter : 39.1: Basic BPF filtering : Ok 39.2: BPF pinning : Ok 39.3: BPF prologue generation : Ok 39.4: BPF relocation checker : Ok 40: Synthesize thread map : Ok 41: Remove thread map : Ok 42: Synthesize cpu map : Ok 43: Synthesize stat config : Ok 44: Synthesize stat : Ok 45: Synthesize stat round : Ok 46: Synthesize attr update : Ok 47: Event times : Ok 48: Read backward ring buffer : Ok 49: Print cpu map : Ok 50: Probe SDT events : Ok 51: is_printable_array : Ok 52: Print bitmap : Ok 53: perf hooks : Ok 54: builtin clang support : Skip (not compiled in) 55: unit_number__scnprintf : Ok 56: x86 rdpmc : Ok 57: Convert perf time to TSC : Ok 58: DWARF unwind : Ok 59: x86 instruction decoder - new instructions : Ok 60: Use vfs_getname probe to get syscall args filenames : Ok 61: Check open filename arg using perf trace + vfs_getname: Ok 62: probe libc's inet_pton & backtrace it with ping : Ok 63: Add vfs_getname probe to get syscall args filenames : Ok #
$ make -C tools/perf build-test
make: Entering directory '/home/acme/git/perf/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_perf_o_O: make perf.o
make_static_O: make LDFLAGS=-static
make_doc_O: make doc
make_no_libperl_O: make NO_LIBPERL=1
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
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_tags_O: make tags
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_install_prefix_O: make install prefix=/tmp/krava
make_clean_all_O: make clean all
make_no_libelf_O: make NO_LIBELF=1
make_no_libunwind_O: make NO_LIBUNWIND=1
make_with_babeltrace_O: make LIBBABELTRACE=1
make_no_gtk2_O: make NO_GTK2=1
make_no_demangle_O: make NO_DEMANGLE=1
make_no_libpython_O: make NO_LIBPYTHON=1
make_no_libbpf_O: make NO_LIBBPF=1
make_util_map_o_O: make util/map.o
make_debug_O: make DEBUG=1
make_no_libbionic_O: make NO_LIBBIONIC=1
make_no_backtrace_O: make NO_BACKTRACE=1
make_help_O: make help
make_no_newt_O: make NO_NEWT=1
make_no_auxtrace_O: make NO_AUXTRACE=1
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_install_O: make install
make_no_libaudit_O: make NO_LIBAUDIT=1
make_pure_O: make
make_no_libnuma_O: make NO_LIBNUMA=1
make_no_slang_O: make NO_SLANG=1
make_install_bin_O: make install-bin
make_with_clangllvm_O: make LIBCLANGLLVM=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$Arnaldo Carvalho de Melo
maintainerPATCH 1/27 perf test bpf: Improve message about expected samples
From: Arnaldo Carvalho de Melo <[email protected]>
When failing on one of the BPF tests we were just stating:
BPF filter result incorrect
Add some more info to help figuring out the problem:
BPF filter result incorrect, expected 56, got 0 samples
This came out while investigating this failure, first seen after updating the kernel to the 4.15.0-rc6 tag:
[root@jouet ~]# perf test bpf
39: BPF filter : 39.1: Basic BPF filtering : FAILED! 39.2: BPF pinning : Skip
39.3: BPF prologue generation: Skip 39.4: BPF relocation checker : Skip [root@jouet ~]#
--- tools/perf/tests/bpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/bpf.c +1 -1
@@ -190,7 +190,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void), }if (count != expect) { -pr_debug ("BPF filter result incorrect\n" ); +pr_debug ("BPF filter result incorrect, expected %d, got %d samples\n" , expect, count); goto out_delete_evlist; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 2/27 perf test bpf: Use designated struct field initializers
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To follow standard practice in the kernel sources, documenting the initialization better and helping quickly finding the value for some field in a struct with many entries.
--- tools/perf/tests/bpf.c | 59 +++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 32 deletions(-)
tools/perf/tests/bpf.c +27 -32
@@ -63,46 +63,41 @@ static struct {bool pin; } bpf_testcase_table[] = { { - LLVM_TESTCASE_BASE, - "Basic BPF filtering", - "[basic_bpf_test]", - "fix 'perf test LLVM' first", - "load bpf object failed", - &epoll_wait_loop, - (NR_ITERS + 1) / 2, - false, + .prog_id = LLVM_TESTCASE_BASE, + .desc = "Basic BPF filtering", + .name = "[basic_bpf_test]", + .msg_compile_fail = "fix 'perf test LLVM' first", + .msg_load_fail = "load bpf object failed", + .target_func = &epoll_wait_loop, + .expect_result = (NR_ITERS + 1) / 2, }, { - LLVM_TESTCASE_BASE, - "BPF pinning", - "[bpf_pinning]", - "fix kbuild first", - "check your vmlinux setting?", - &epoll_wait_loop, - (NR_ITERS + 1) / 2, - true, + .prog_id = LLVM_TESTCASE_BASE, + .desc = "BPF pinning", + .name = "[bpf_pinning]", + .msg_compile_fail = "fix kbuild first", + .msg_load_fail = "check your vmlinux setting?", + .target_func = &epoll_wait_loop, + .expect_result = (NR_ITERS + 1) / 2, + .pin = true, }, #ifdef HAVE_BPF_PROLOGUE { - LLVM_TESTCASE_BPF_PROLOGUE, - "BPF prologue generation", - "[bpf_prologue_test]", - "fix kbuild first", - "check your vmlinux setting?", - &llseek_loop, - (NR_ITERS + 1) / 4, - false, + .prog_id = LLVM_TESTCASE_BPF_PROLOGUE, + .desc = "BPF prologue generation", + .name = "[bpf_prologue_test]", + .msg_compile_fail = "fix kbuild first", + .msg_load_fail = "check your vmlinux setting?", + .target_func = &llseek_loop, + .expect_result = (NR_ITERS + 1) / 4, }, #endif { - LLVM_TESTCASE_BPF_RELOCATION, - "BPF relocation checker", - "[bpf_relocation_test]", - "fix 'perf test LLVM' first", - "libbpf error when dealing with relocation", - NULL, - 0, - false, + .prog_id = LLVM_TESTCASE_BPF_RELOCATION, + .desc = "BPF relocation checker", + .name = "[bpf_relocation_test]", + .msg_compile_fail = "fix 'perf test LLVM' first", + .msg_load_fail = "libbpf error when dealing with relocation", }, };
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 3/27 perf test bpf: Hook on epoll_pwait()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The 'perf test bpf' was hooking a eBPF program on the SyS_epoll_wait() kernel function, that was what the epoll_wait() glibc function ended up calling, but since at least glibc 2.26, the one that comes with, for instance, Fedora 27, glibc ends up calling SyS_epoll_pwait() when epoll_wait() is used, causing this 'perf test' entry to fail.
So switch to using epoll_pwait() and hook the eBPF program to the SyS_epoll_pwait() kernel function to make it work on a wider range of glibc and kernel versions.
--- tools/perf/tests/bpf-script-example.c | 4 ++-- tools/perf/tests/bpf.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
tools/perf/tests/bpf-script-example.c +2 -2
@@ -31,8 +31,8 @@ struct bpf_map_def SEC("maps") flip_table = { .max_entries = 1, }; -SEC("func=SyS_epoll_wait") -int bpf_func__SyS_epoll_wait (void *ctx) +SEC("func=SyS_epoll_pwait") +int bpf_func__SyS_epoll_pwait (void *ctx) {int ind =0 ;int *flag =bpf_map_lookup_elem (&flip_table, &ind);
tools/perf/tests/bpf.c +4 -4
@@ -19,13 +19,13 @@#ifdef HAVE_LIBBPF_SUPPORT -static int epoll_wait_loop (void ) +static int epoll_pwait_loop (void ) {int i;/* Should fail NR_ITERS times */ for (i =0 ; i <NR_ITERS ; i++) -epoll_wait (-(i +1 ),NULL ,0 ,0 ); +epoll_pwait (-(i +1 ),NULL ,0 ,0 ,NULL );return 0 ; }
@@ -68,7 +68,7 @@ static struct { .name = "[basic_bpf_test]", .msg_compile_fail = "fix 'perf test LLVM' first", .msg_load_fail = "load bpf object failed", - .target_func = &epoll_wait_loop, + .target_func = &epoll_pwait_loop, .expect_result = (NR_ITERS + 1) / 2, }, {
@@ -77,7 +77,7 @@ static struct { .name = "[bpf_pinning]", .msg_compile_fail = "fix kbuild first", .msg_load_fail = "check your vmlinux setting?", - .target_func = &epoll_wait_loop, + .target_func = &epoll_pwait_loop, .expect_result = (NR_ITERS + 1) / 2, .pin = true, },
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 4/27 perf tools: Fix compile error with libunwind x86
In reply to Arnaldo Carvalho de MeloFrom: Wang Nan <[email protected]>
Fix a compile error:
...
CC util/libunwind/x86_32.o
In file included from util/libunwind/x86_32.c:33:0:
util/libunwind/../../arch/x86/util/unwind-libunwind.c: In function 'libunwind__x86_reg_id':
util/libunwind/../../arch/x86/util/unwind-libunwind.c:110:11: error: 'EINVAL' undeclared (first use in this function)
return -EINVAL;
^ util/libunwind/../../arch/x86/util/unwind-libunwind.c:110:11: note: each undeclared identifier is reported only once for each function it appears in
mv: cannot stat 'util/libunwind/.x86_32.o.tmp': No such file or directory
make[4]: *** [util/libunwind/x86_32.o] Error 1
make[3]: *** [util] Error 2
make[2]: *** [libperf-in.o] Error 2
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
It happens when libunwind-x86 feature is detected.
--- tools/perf/arch/x86/util/unwind-libunwind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/util/unwind-libunwind.c +1 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 -#ifndef REMOTE_UNWIND_LIBUNWIND #include <errno.h> +#ifndef REMOTE_UNWIND_LIBUNWIND #include <libunwind.h> #include "perf_regs.h" #include "../../util/unwind.h"
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 5/27 perf report: Fix a wrong offset issue when using /proc/kcore
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
When a valid vmlinux is not found, 'perf report' falls back to look at /proc/kcore. In this case, it will report the impossible large offset.
For example:
# perf record -b -e cycles:k find /etc/ > /dev/null # perf report --stdio --branch-history
22.77% _vm_normal_page+18446603336221188162
|
---page_remove_rmap +18446603336221188324
page_remove_rmap +18446603336221188487 (cycles:5)
unlock_page_memcg +18446603336221188096
page_remove_rmap +18446603336221188327 (cycles:1)The issue is the value which is passed to parameter 'addr' in __get_srcline() is the objdump address. It's not correct if we calculate the offset by using 'addr - sym->start'.
This patch creates a new parameter 'ip' in __get_srcline(). It is not converted to objdump address.
With this patch, the perf report output is:
22.77% _vm_normal_page+66
|
---page_remove_rmap +228
page_remove_rmap +391 (cycles:5)
unlock_page_memcg +0
page_remove_rmap +231 (cycles:1)
page_remove_rmap +236Committer testing:
Make sure you get any valid vmlinux out of the way, using '-v' on the 'perf report' case and deleting it from places where perf searches them, like your kernel build dir and the build-id cache, in ~/.debug/.
--- tools/perf/util/annotate.c | 3 ++- tools/perf/util/machine.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/sort.c | 16 ++++++++++------ tools/perf/util/srcline.c | 9 +++++---- tools/perf/util/srcline.h | 5 +++-- 6 files changed, 22 insertions(+), 15 deletions(-)
tools/perf/util/annotate.c +2 -1
@@ -1960,7 +1960,8 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,if (percent_max <=0.5 )continue ; - al->path =get_srcline (map->dso, start + al->offset,NULL , false, true); + al->path =get_srcline (map->dso, start + al->offset,NULL , + false, true, start + al->offset);insert_source_line (&tmp_root, al); }
tools/perf/util/machine.c +1 -1
@@ -1726,7 +1726,7 @@ static char *callchain_srcline(struct map *map, struct symbol *sym, u64 ip)bool show_addr = callchain_param.key ==CCKEY_ADDRESS ; srcline =get_srcline (map->dso,map__rip_2objdump (map, ip), - sym, show_sym, show_addr); + sym, show_sym, show_addr, ip);srcline__tree_insert (&map->dso->srclines, ip, srcline); }
tools/perf/util/map.c +1 -1
@@ -419,7 +419,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,if (map && map->dso) { srcline =get_srcline (map->dso,map__rip_2objdump (map, addr),NULL , - true, true); + true, true, addr);if (srcline !=SRCLINE_UNKNOWN ) ret =fprintf (fp,"%s%s" , prefix, srcline);free_srcline (srcline);
tools/perf/util/sort.c +10 -6
@@ -336,7 +336,7 @@ char *hist_entry__get_srcline(struct hist_entry *he)return SRCLINE_UNKNOWN ;return get_srcline (map->dso,map__rip_2objdump (map, he->ip), - he->ms.sym, true, true); + he->ms.sym, true, true, he->ip); } static int64_t
@@ -380,7 +380,8 @@ sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)map__rip_2objdump (map, left->branch_info->from.al_addr), left->branch_info->from.sym, - true, true); + true, true, + left->branch_info->from.al_addr); }if (!right->branch_info->srcline_from) {struct map *map = right->branch_info->from.map;
@@ -391,7 +392,8 @@ sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)map__rip_2objdump (map, right->branch_info->from.al_addr), right->branch_info->from.sym, - true, true); + true, true, + right->branch_info->from.al_addr); }return strcmp (right->branch_info->srcline_from, left->branch_info->srcline_from); }
@@ -423,7 +425,8 @@ sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)map__rip_2objdump (map, left->branch_info->to.al_addr), left->branch_info->from.sym, - true, true); + true, true, + left->branch_info->to.al_addr); }if (!right->branch_info->srcline_to) {struct map *map = right->branch_info->to.map;
@@ -434,7 +437,8 @@ sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)map__rip_2objdump (map, right->branch_info->to.al_addr), right->branch_info->to.sym, - true, true); + true, true, + right->branch_info->to.al_addr); }return strcmp (right->branch_info->srcline_to, left->branch_info->srcline_to); }
@@ -465,7 +469,7 @@ static char *hist_entry__get_srcfile(struct hist_entry *e)return no_srcfile; sf =__get_srcline (map->dso,map__rip_2objdump (map, e->ip), - e->ms.sym, false, true, true); + e->ms.sym, false, true, true, e->ip);if (!strcmp (sf,SRCLINE_UNKNOWN ))return no_srcfile; p =strchr (sf,':' );
tools/perf/util/srcline.c +5 -4
@@ -496,7 +496,8 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr,#define A2L_FAIL_LIMIT 123char *__get_srcline (struct dso *dso,u64 addr,struct symbol *sym, -bool show_sym,bool show_addr,bool unwind_inlines) +bool show_sym,bool show_addr,bool unwind_inlines, +u64 ip) {char *file =NULL ;unsigned line =0 ;
@@ -536,7 +537,7 @@ char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,if (sym) {if (asprintf (&srcline,"%s+%" PRIu64, show_sym ? sym->name :"" , - addr - sym->start) <0 ) + ip - sym->start) <0 )return SRCLINE_UNKNOWN ; }else if (asprintf (&srcline,"%s[%" PRIx64"]" , dso->short_name, addr) <0 )return SRCLINE_UNKNOWN ;
@@ -550,9 +551,9 @@ void free_srcline(char *srcline) }char *get_srcline (struct dso *dso,u64 addr,struct symbol *sym, -bool show_sym,bool show_addr) +bool show_sym,bool show_addr,u64 ip) { -return __get_srcline (dso, addr, sym, show_sym, show_addr, false); +return __get_srcline (dso, addr, sym, show_sym, show_addr, false, ip); }struct srcline_node {
tools/perf/util/srcline.h +3 -2
@@ -11,9 +11,10 @@ struct symbol;extern bool srcline_full_filename;char *get_srcline (struct dso *dso,u64 addr,struct symbol *sym, -bool show_sym,bool show_addr); +bool show_sym,bool show_addr,u64 ip);char *__get_srcline (struct dso *dso,u64 addr,struct symbol *sym, -bool show_sym,bool show_addr,bool unwind_inlines); +bool show_sym,bool show_addr,bool unwind_inlines, +u64 ip);void free_srcline (char *srcline);/* insert the srcline into the DSO, which will take ownership */
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 6/27 perf report: Fix a no annotate browser displayed issue
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
When enabling '-b' option in perf record, for example,
perf record -b ...
perf report
and then browsing the annotate browser from perf report (press 'A'), it would fail (annotate browser can't be displayed).
It's because the '.add_entry_cb' op of struct report is overwritten by hist_iter__branch_callback() in builtin-report.c. But this function doesn't do something like mapping symbols and sources. So next, do_annotate() will return directly.
notes = symbol__annotation(act->ms.sym);
if (!notes->src)
return 0;This patch adds the lost code to hist_iter__branch_callback (refer to hist_iter__report_callback).
v2:
Fix a crash bug when perform 'perf report --stdio'.
The reason is that we init the symbol annotation only in browser mode, it doesn't allocate/init resources for stdio mode.
So now in hist_iter__branch_callback(), it will return directly if it's not in browser mode.
--- tools/perf/builtin-report.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +17 -1
@@ -162,12 +162,28 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,struct hist_entry *he = iter->he;struct report *rep = arg;struct branch_info *bi; +struct perf_sample *sample = iter->sample; +struct perf_evsel *evsel = iter->evsel; +int err; + +if (!ui__has_annotation ()) +return 0 ; + +hist__account_cycles (sample->branch_stack, al, sample, + rep->nonany_branch_mode); bi = he->branch_info; + err =addr_map_symbol__inc_samples (&bi->from, sample, evsel->idx); +if (err) + goto out; + + err =addr_map_symbol__inc_samples (&bi->to, sample, evsel->idx); +branch_type_count (&rep->brtype_stat, &bi->flags, bi->from.addr, bi->to.addr); -return 0 ; +out: +return err; } static int process_sample_event(struct perf_tool *tool,
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 7/27 perf header: Add infrastructure to record first and last sample time
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
perf report/script/... have a --time option to limit the time range of output. That's very useful to slice large traces, e.g. when processing the output of perf script for some analysis.
But right now --time only supports absolute time. Also there is no fast way to get the start/end times of a given trace except for looking at it. This makes it hard to e.g. only decode the first half of the trace, which is useful for parallelization of scripts
Another problem is that perf records are variable size and there is no synchronization mechanism. So the only way to find the last sample reliably would be to walk all samples. But we want to avoid that in perf report/... because it is already quite expensive. That is why storing the first sample time and last sample time in perf record is better.
This patch creates a new header feature type HEADER_SAMPLE_TIME and related ops. Save the first sample time and the last sample time to the feature section in perf file header. That will be done when, for instance, processing build-ids, where we already have to process all samples to create the build-id table, take advantage of that to further amortize that processing by storing HEADER_SAMPLE_TIME to make 'perf report/script' faster when using --time.
Committer testing:
After this patch is applied the header is written with zeroes, we need the next patch, for "perf record" to actually write the timestamps:
# perf report -D | grep PERF_RECORD_SAMPLE\( 22501155244406 0x44f0 [0x28]: PERF_RECORD_SAMPLE(IP, 0x4001): 25016/25016: 0xffffffffa21be8c5 period: 1 addr: 0 <SNIP> 22501155793625 0x4a30 [0x28]: PERF_RECORD_SAMPLE(IP, 0x4001): 25016/25016: 0xffffffffa21ffd50 period: 2828043 addr: 0 # perf report --header | grep "time of " # time of first sample : 0.000000 # time of last sample : 0.000000 #
Changelog:
v7: 1. Rebase to latest perf/core branch.
2. Add following clarification in patch description according to Arnaldo's suggestion.
"That will be done when, for instance, processing build-ids,
where we already have to process all samples to create the build-id table, take advantage of that to further amortize that processing by storing HEADER_SAMPLE_TIME to make 'perf report/script' faster when using --time."
v4: Use perf script time style for timestamp printing. Also add with
the printing of sample duration.
v3: Remove the definitions of first_sample_time/last_sample_time from
perf_session. Just define them in perf_evlist
--- tools/perf/Documentation/perf.data-file-format.txt | 4 ++ tools/perf/util/evlist.h | 2 + tools/perf/util/header.c | 60 ++++++++++++++++++++++ tools/perf/util/header.h | 1 + 4 files changed, 67 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +4 -0
@@ -261,6 +261,10 @@ struct { struct perf_header_string map; }[number_of_cache_levels]; + HEADER_SAMPLE_TIME = 21, + +Two uint64_t for the time of first sample and the time of last sample. + other bits are reserved and should ignored for now HEADER_FEAT_BITS = 256,
tools/perf/util/evlist.h +2 -0
@@ -50,6 +50,8 @@ struct perf_evlist {struct perf_evsel *selected;struct events_stats stats;struct perf_env *env; +u64 first_sample_time; +u64 last_sample_time; };struct perf_evsel_str_handler {
tools/perf/util/header.c +60 -0
96 lines not on this page · raw message
tools/perf/util/header.h +1 -0
@@ -35,6 +35,7 @@ enum {HEADER_AUXTRACE ,HEADER_STAT ,HEADER_CACHE , +HEADER_SAMPLE_TIME ,HEADER_LAST_FEATURE , HEADER_FEAT_BITS = 256, };
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 8/27 perf record: Record the first and last sample time in the header
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
In the default 'perf record' configuration, all samples are processed, to create the HEADER_BUILD_ID table. So it's very easy to get the first/last samples and save the time to perf file header via the function write_sample_time().
Later, at post processing time, perf report/script will fetch the time from perf file header.
Committer testing:
# perf record -a sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.099 MB perf.data (1101 samples) ] [root@jouet home]# perf report --header | grep "time of " # time of first sample : 22947.909226 # time of last sample : 22948.910704 # # perf report -D | grep PERF_RECORD_SAMPLE\( 0 22947909226101 0x20bb68 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa21b1af3 period: 1 addr: 0 0 22947909229928 0x20bb98 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa200d204 period: 1 addr: 0 <SNIP> 3 22948910397351 0x219360 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 28251/28251: 0xffffffffa22071d8 period: 169518 addr: 0 0 22948910652380 0x20f120 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa2856816 period: 198807 addr: 0 2 22948910704034 0x2172d0 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa2856816 period: 88111 addr: 0 #
Changelog:
v7: Just update the patch description according to Arnaldo's suggestion.
v6: Currently '--buildid-all' is not enabled at default. So the walking
on all samples is the default operation. There is no big overhead to calculate the timestamp boundary in process_sample_event handler once we already go through all samples. So the timestamp boundary calculation is enabled by default when '--buildid-all' is not enabled.
While if '--buildid-all' is enabled, we creates a new option "--timestamp-boundary" for user to decide if it enables the timestamp boundary calculation.
v5: There is an issue that the sample walking can only work when
'--buildid-all' is not enabled. So we need to let the walking be able to work even if '--buildid-all' is enabled and let the processing skips the dso hit marking for this case.
At first, I want to provide a new option "--record-time-boundaries". While after consideration, I think a new option is not very necessary.
v3: Remove the definitions of first_sample_time and last_sample_time
from struct record and directly save them in perf_evlist.
--- tools/perf/Documentation/perf-record.txt | 3 +++ tools/perf/builtin-record.c | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-record.txt +3 -0
@@ -430,6 +430,9 @@ Configure all used events to run in user space. --timestamp-filename Append timestamp to output file name. +--timestamp-boundary:: +Record timestamp boundary (time of first/last samples). + --switch-output[=mode]:: Generate multiple perf.data files, timestamp prefixed, switching to a new one based on 'mode' value:
tools/perf/builtin-record.c +15 -3
@@ -78,6 +78,7 @@ struct record {bool no_buildid_cache_set;bool buildid_all;bool timestamp_filename; +bool timestamp_boundary;struct switch_output switch_output;unsigned long long samples; };
@@ -409,8 +410,15 @@ static int process_sample_event(struct perf_tool *tool, { struct record *rec = container_of(tool, struct record, tool); - rec->samples++; +if (rec->evlist->first_sample_time ==0 ) + rec->evlist->first_sample_time = sample->time; + + rec->evlist->last_sample_time = sample->time; +if (rec->buildid_all) +return 0 ; + + rec->samples++;return build_id__mark_dso_hit (tool, event, sample, evsel, machine); }
@@ -435,9 +443,11 @@ static int process_buildids(struct record *rec)/* * If --buildid-all is given, it marks all DSO regardless of hits, -* so no need to process samples. +* so no need to process samples. But if timestamp_boundary is enabled, +* it still needs to walk on all samples to get the timestamps of +* first/last samples. */ -if (rec->buildid_all) +if (rec->buildid_all && !rec->timestamp_boundary) rec->tool.sample =NULL ;return perf_session__process_events (session);
@@ -1621,6 +1631,8 @@ static struct option __record_options[] = { "Record build-id of all DSOs regardless of hits"),OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), +OPT_BOOLEAN (0 ,"timestamp-boundary" , &record.timestamp_boundary, +"Record timestamp boundary (time of first/last samples)" ), OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str, &record.switch_output.set, "signal,size,time", "Switch output when receive SIGUSR2 or cross size,time threshold",
Signature · 1 line
2.14.3
Re: [PATCH 08/27] perf record: Record the first and last sample time in the header
Quoted 12 lines · Arnaldo Carvalho de Melo
From: Jin Yao <[email protected]>
In the default 'perf record' configuration, all samples are processed, to create the
HEADER_BUILD_IDtable. So it's very easy to get the first/last samples and save the time to perf file header via the functionwrite_sample_time().Later, at post processing time, perf report/script will fetch the time from perf file header.
Committer testing:
Quoted 15 lines
# perf record -a sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.099 MB perf.data (1101 samples) ] [root@jouet home]# perf report --header | grep "time of " # time of first sample : 22947.909226 # time of last sample : 22948.910704 # # perf report -D | grep PERF_RECORD_SAMPLE\( 0 22947909226101 0x20bb68 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa21b1af3 period: 1 addr: 0 0 22947909229928 0x20bb98 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa200d204 period: 1 addr: 0 <SNIP> 3 22948910397351 0x219360 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 28251/28251: 0xffffffffa22071d8 period: 169518 addr: 0 0 22948910652380 0x20f120 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa2856816 period: 198807 addr: 0 2 22948910704034 0x2172d0 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa2856816 period: 88111 addr: 0 #
This would be really useful to incorporate within "trace_begin" for perf script language support. How difficult would that be?
Within perf scripts, it could be used to more efficiently compute deltas from the start of the trace within the functions. For example, every time a function is invoked, like raw_syscalls__sys_enter, the only context one has is the current timestamp. To determine the delta since the start of the trace, one has to know if this is the first event. So, *every* event function needs something like:
def event_family__event(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, ..., perf_sample_dict):
global start_timestamp
current_timestamp = nsecs(common_secs, common_nsecs)
if (start_timestamp == 0):
start_timestamp = current_timestamp
If start_timestamp could be set in trace_begin, the conditional assignment of start_timestamp could be eliminated in *every* function.
(More generally, perhaps "trace_begin" could have access to the full set of information in the perf.data header? Like, how many events are in the trace, so "% complete" tickers could be displayed during processing.)
Regards,
PC
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 08/27] perf record: Record the first and last sample time in the header
Em Thu, Jan 11, 2018 at 07:29:46AM -0600, Paul Clarke escreveu:
Quoted 45 lines · Arnaldo Carvalho de Melo
Quoted 12 lines
From: Jin Yao <[email protected]>
In the default 'perf record' configuration, all samples are processed, to create the
HEADER_BUILD_IDtable. So it's very easy to get the first/last samples and save the time to perf file header via the functionwrite_sample_time().Later, at post processing time, perf report/script will fetch the time from perf file header.
Committer testing:
Quoted 15 lines
# perf record -a sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.099 MB perf.data (1101 samples) ] [root@jouet home]# perf report --header | grep "time of " # time of first sample : 22947.909226 # time of last sample : 22948.910704 # # perf report -D | grep PERF_RECORD_SAMPLE\( 0 22947909226101 0x20bb68 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa21b1af3 period: 1 addr: 0 0 22947909229928 0x20bb98 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa200d204 period: 1 addr: 0 <SNIP> 3 22948910397351 0x219360 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 28251/28251: 0xffffffffa22071d8 period: 169518 addr: 0 0 22948910652380 0x20f120 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa2856816 period: 198807 addr: 0 2 22948910704034 0x2172d0 [0x30]: PERF_RECORD_SAMPLE(IP, 0x4001): 0/0: 0xffffffffa2856816 period: 88111 addr: 0 #This would be really useful to incorporate within "
trace_begin" for perf script language support. How difficult would that be?Within perf scripts, it could be used to more efficiently compute deltas from the start of the trace within the functions. For example, every time a function is invoked, like
raw_syscalls__sys_enter, the only context one has is the current timestamp. To determine the delta since the start of the trace, one has to know if this is the first event. So, *every* event function needs something like:def event_family__event(event_name, context,
common_cpu,common_secs,common_nsecs,common_pid,common_comm,common_callchain, ...,perf_sample_dict):
globalstart_timestamp
current_timestamp=nsecs(common_secs, common_nsecs)
if (start_timestamp== 0):
start_timestamp=current_timestamp
Quoted 7 lines
If
start_timestampcould be set intrace_begin, the conditional assignment ofstart_timestampcould be eliminated in *every* function.(More generally, perhaps "
trace_begin" could have access to the full set of information in the perf.data header? Like, how many events are in the trace, so "% complete" tickers could be displayed during processing.)
Yeah, I think this is something worth exported to python/perl scripts in some sane way, via classes or a simple dict.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerPATCH 9/27 perf tools: Create function to parse time percent
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Current perf report/script/... have a --time option to limit the time range of output. But right now it only supports absolute time, add support for time percentage.
For example:
1. Select the second 10% time slice
perf report --time 10%/2
2. Select from 0% to 10% time slice
perf report --time 0%-10%
It also support the multiple time ranges.
3. Select the first and second 10% time slices
perf report --time 10%/1,10%/2
4. Select from 0% to 10% and 30% to 40% slices
perf report --time 0%-10%,30%-40%
Changelog:
v4: An issue is found. Following passes.
perf script --time 10%/10x12321xsdfdasfdsafdsafdsa
Now it uses strtol to replace atoi.
Committer notes:
This just puts in place the infrastructure, so the examples in this cset comment will only work later, after more patches in this series are applied.
--- tools/perf/util/time-utils.c | 205 ++++++++++++++++++++++++++++++++++++++++--- tools/perf/util/time-utils.h | 3 + 2 files changed, 196 insertions(+), 12 deletions(-)
tools/perf/util/time-utils.c +193 -12
@@ -6,6 +6,7 @@#include <time.h> #include <errno.h> #include <inttypes.h> +#include <math.h> #include "perf.h" #include "debug.h"
@@ -60,11 +61,10 @@ static int parse_timestr_sec_nsec(struct perf_time_interval *ptime,return 0 ; } -int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr) +static int split_start_end (char **start,char **end,const char *ostr,char ch) {char *start_str, *end_str;char *d, *str; -int rc =0 ;if (ostr ==NULL || *ostr =='\0' )return 0 ;
@@ -74,25 +74,35 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)if (str ==NULL )return -ENOMEM ; - ptime->start =0 ; - ptime->end =0 ; - -/* str has the format: <start>,<stop> -* variations: <start>, -* ,<stop> -* , -*/ start_str = str; - d =strchr (start_str,',' ); + d =strchr (start_str, ch);if (d) { *d ='\0' ; ++d; } end_str = d; + *start = start_str; + *end = end_str; + +return 0 ; +} + +int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr) +{ +char *start_str =NULL , *end_str; +int rc; + + rc =split_start_end (&start_str, &end_str, ostr,',' ); +if (rc || !start_str) +return rc; + + ptime->start =0 ; + ptime->end =0 ; + rc =parse_timestr_sec_nsec (ptime, start_str, end_str); -free (str); +free (start_str);/* make sure end time is after start time if it was given */ if (rc ==0 && ptime->end && ptime->end < ptime->start)
@@ -104,6 +114,177 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)return rc; } +static int parse_percent (double *pcnt,char *str) +{ +char *c; + + c =strchr (str,'%' ); +if (c) + *c ='\0' ; +else +return -1 ; + + *pcnt =atof (str) /100.0 ; + +return 0 ; +} + +static int percent_slash_split (char *str,struct perf_time_interval *ptime, +u64 start,u64 end) +{ +char *p, *end_str; +double pcnt, start_pcnt, end_pcnt; +u64 total = end - start; +int i; + +/* +* Example: +* 10%/2: select the second 10% slice and the third 10% slice +*/ + +/* We can modify this string since the original one is copied */ + p =strchr (str,'/' ); +if (!p) +return -1 ; + + *p ='\0' ; +if (parse_percent (&pcnt, str) <0 ) +return -1 ; + + p++; + i = (int )strtol (p, &end_str,10 ); +if (*end_str) +return -1 ; + +if (pcnt <=0.0 ) +return -1 ; + + start_pcnt = pcnt * (i -1 ); + end_pcnt = pcnt * i; + +if (start_pcnt <0.0 || start_pcnt >1.0 || + end_pcnt <0.0 || end_pcnt >1.0 ) { +return -1 ; + } + + ptime->start = start +round (start_pcnt * total); + ptime->end = start +round (end_pcnt * total); + +return 0 ; +} + +static int percent_dash_split (char *str,struct perf_time_interval *ptime, +u64 start,u64 end) +{ +char *start_str =NULL , *end_str; +double start_pcnt, end_pcnt; +u64 total = end - start; +int ret; + +/* +* Example: 0%-10% +*/ + + ret =split_start_end (&start_str, &end_str, str,'-' ); +if (ret || !start_str) +return ret; + +if ((parse_percent (&start_pcnt, start_str) !=0 ) || + (parse_percent (&end_pcnt, end_str) !=0 )) { +free (start_str); +return -1 ; + } + +free (start_str); + +if (start_pcnt <0.0 || start_pcnt >1.0 || + end_pcnt <0.0 || end_pcnt >1.0 || + start_pcnt > end_pcnt) { +return -1 ; + } + + ptime->start = start +round (start_pcnt * total); + ptime->end = start +round (end_pcnt * total); + +return 0 ; +} + +typedef int (*time_pecent_split )(char *,struct perf_time_interval *, +u64 start,u64 end); + +static int percent_comma_split (struct perf_time_interval *ptime_buf,int num, +const char *ostr,u64 start,u64 end, +time_pecent_split func) +{ +char *str, *p1, *p2; +int len, ret, i =0 ; + + str =strdup (ostr); +if (str ==NULL ) +return -ENOMEM ; + + len =strlen (str); + p1 = str; + +while (p1 < str + len) { +if (i >= num) { +free (str); +return -1 ; + } + + p2 =strchr (p1,',' ); +if (p2) + *p2 ='\0' ; + + ret = (func)(p1, &ptime_buf[i], start, end); +if (ret <0 ) { +free (str); +return -1 ; + } + +pr_debug ("start time %d: %" PRIu64", " , i, ptime_buf[i].start); +pr_debug ("end time %d: %" PRIu64"\n" , i, ptime_buf[i].end); + + i++; + +if (p2) + p1 = p2 +1 ; +else +break ; + } + +free (str); +return i; +} + +int perf_time__percent_parse_str (struct perf_time_interval *ptime_buf,int num, +const char *ostr,u64 start,u64 end) +{ +char *c; + +/* +* ostr example: +* 10%/2,10%/3: select the second 10% slice and the third 10% slice +* 0%-10%,30%-40%: multiple time range +*/ + +memset (ptime_buf,0 ,sizeof (*ptime_buf) * num); + + c =strchr (ostr,'/' ); +if (c) { +return percent_comma_split (ptime_buf, num, ostr, start, + end, percent_slash_split); + } + + c =strchr (ostr,'-' ); +if (c) { +return percent_comma_split (ptime_buf, num, ostr, start, + end, percent_dash_split); + } + +return -1 ; +} +bool perf_time__skip_sample (struct perf_time_interval *ptime,u64 timestamp) {/* if time is not set don't drop sample */
tools/perf/util/time-utils.h +3 -0
@@ -13,6 +13,9 @@ int parse_nsec_time(const char *str, u64 *ptime);int perf_time__parse_str (struct perf_time_interval *ptime,const char *ostr); +int perf_time__percent_parse_str (struct perf_time_interval *ptime_buf,int num, +const char *ostr,u64 start,u64 end); +bool perf_time__skip_sample (struct perf_time_interval *ptime,u64 timestamp);int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 10/27 perf tools: Create function to perform multiple time range checking
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Previous patch supports the multiple time range.
For example, select the first and second 10% time slices. perf report --time 10%/1,10%/2
We need a function to check if a timestamp is in the ranges of [0, 10%) and [10%, 20%].
Note that it includes the last element in [10%, 20%] but it doesn't include the last element in [0, 10%). It's to avoid the overlap.
This patch implments a new function perf_time__ranges_skip_sample for this checking.
Change log:
v4: Let perf_time__ranges_skip_sample be compatible with
perf_time__skip_sample when only one time range.
--- tools/perf/util/time-utils.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/time-utils.h | 3 +++ 2 files changed, 31 insertions(+)
tools/perf/util/time-utils.c +28 -0
@@ -300,6 +300,34 @@ bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)return false; } +bool perf_time__ranges_skip_sample (struct perf_time_interval *ptime_buf, +int num,u64 timestamp) +{ +struct perf_time_interval *ptime; +int i; + +if ((timestamp ==0 ) || (num ==0 )) +return false; + +if (num ==1 ) +return perf_time__skip_sample (&ptime_buf[0 ], timestamp); + +/* +* start/end of multiple time ranges must be valid. +*/ +for (i =0 ; i < num; i++) { + ptime = &ptime_buf[i]; + +if (timestamp >= ptime->start && + ((timestamp < ptime->end && i < num -1 ) || + (timestamp <= ptime->end && i == num -1 ))) { +break ; + } + } + +return (i == num) ? true : false; +} +int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz) {u64 sec = timestamp /NSEC_PER_SEC ;
tools/perf/util/time-utils.h +3 -0
@@ -18,6 +18,9 @@ int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,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); +int timestamp__scnprintf_usec (u64 timestamp,char *buf,size_t sz);int fetch_current_timestamp (char *buf,size_t sz);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 11/27 perf report: Support time percent and multiple time ranges
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
perf report has a --time option to limit the time range of output. It only supports absolute time.
Now this option is extended to support multiple time ranges and support the percent of time.
For example:
1. Select the first and second 10% time slices:
perf report --time 10%/1,10%/2
2. Select from 0% to 10% and 30% to 40% slices:
perf report --time 0%-10%,30%-40%
Changelog:
v6: Fix the merge issue with latest perf/core branch.
No functional changes.
v5: Add checking of first/last sample time to detect if it's recorded
in perf.data. If it's not recorded, returns error message to user.
v4: Remove perf_time__skip_sample, only uses perf_time__ranges_skip_sample
v3: Since the definitions of first_sample_time/last_sample_time
are moved from perf_session to perf_evlist so change the related code.
--- tools/perf/Documentation/perf-report.txt | 20 ++++++++++++++++++++ tools/perf/builtin-report.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-report.txt +20 -0
@@ -402,6 +402,26 @@ OPTIONS stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. + Also support time percent with multiple time range. Time string is + 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 10. + + For example: + Select the second 10% time slice: + + perf report --time 10%/2 + + Select from 0% to 10% time slice: + + perf report --time 0%-10% + + Select the first and second 10% time slices: + + perf report --time 10%/1,10%/2 + + Select from 0% to 10% and 30% to 40% slices: + + perf report --time 0%-10%,30%-40% + --itrace:: Options for decoding instruction tracing data. The options are:
tools/perf/builtin-report.c +26 -5
@@ -52,6 +52,8 @@#include <sys/stat.h> #include <unistd.h> +#define PTIME_RANGE_MAX 10 +struct report {struct perf_tool tool;struct perf_session *session;
@@ -69,7 +71,8 @@ struct report {const char *cpu_list;const char *symbol_filter_str;const char *time_str; -struct perf_time_interval ptime; +struct perf_time_interval ptime_range[PTIME_RANGE_MAX ]; +int range_num;float min_percent;u64 nr_entries;u64 queue_size;
@@ -202,8 +205,10 @@ static int process_sample_event(struct perf_tool *tool, };int ret =0 ; -if (perf_time__skip_sample (&rep->ptime, sample->time)) +if (perf_time__ranges_skip_sample (rep->ptime_range, rep->range_num, + sample->time)) {return 0 ; + }if (machine__resolve (machine, &al, sample) <0 ) { pr_debug("problem processing %d event, skipping it.\n",
@@ -1093,9 +1098,25 @@ int cmd_report(int argc, const char **argv)if (symbol__init (&session->header.env) <0 ) goto error; -if (perf_time__parse_str (&report.ptime, report.time_str) !=0 ) { -pr_err ("Invalid time string\n" ); -return -EINVAL ; +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 ("No first/last sample time in perf data\n" ); +return -EINVAL ; + } + + report.range_num =perf_time__percent_parse_str ( + report.ptime_range,PTIME_RANGE_MAX , + report.time_str, + session->evlist->first_sample_time, + session->evlist->last_sample_time); + +if (report.range_num <0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + }else { + report.range_num =1 ; }sort__setup_elide (stdout);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 12/27 perf script: Support time percent and multiple time ranges
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
perf script has a --time option to limit the time range of output. It only supports absolute time.
Now this option is extended to support multiple time ranges and support the percent of time.
For example:
1. Select the first and second 10% time slices:
perf script --time 10%/1,10%/2
2. Select from 0% to 10% and 30% to 40% slices:
perf script --time 0%-10%,30%-40%
Changelog:
v6: Fix the merge issue with latest perf/core branch.
No functional changes.
v5: Add checking of first/last sample time to detect if it's recorded
in perf.data. If it's not recorded, returns error message to user.
v4: Remove perf_time__skip_sample, only uses perf_time__ranges_skip_sample
v3: Since the definitions of first_sample_time/last_sample_time
are moved from perf_session to perf_evlist so change the related code.
--- tools/perf/Documentation/perf-script.txt | 16 +++++++++++++++ tools/perf/builtin-script.c | 34 ++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-script.txt +16 -0
@@ -329,6 +329,22 @@ include::itrace.txt[] stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. + Also support time percent with multipe time range. Time string is + 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 10. + + For example: + Select the second 10% time slice + perf script --time 10%/2 + + Select from 0% to 10% time slice + perf script --time 0%-10% + + Select the first and second 10% time slices + perf script --time 10%/1,10%/2 + + Select from 0% to 10% and 30% to 40% slices + perf script --time 0%-10%,30%-40% + --max-blocks:: Set the maximum number of program blocks to print with brstackasm for each sample.
tools/perf/builtin-script.c +28 -6
@@ -1436,6 +1436,8 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,return 0 ; } +#define PTIME_RANGE_MAX 10 +struct perf_script {struct perf_tool tool;struct perf_session *session;
@@ -1449,7 +1451,8 @@ struct perf_script {struct thread_map *threads;int name_width;const char *time_str; -struct perf_time_interval ptime; +struct perf_time_interval ptime_range[PTIME_RANGE_MAX ]; +int range_num; };static int perf_evlist__max_name_len (struct perf_evlist *evlist)
@@ -1734,8 +1737,10 @@ static int process_sample_event(struct perf_tool *tool, struct perf_script *scr = container_of(tool, struct perf_script, tool);struct addr_location al; -if (perf_time__skip_sample (&scr->ptime, sample->time)) +if (perf_time__ranges_skip_sample (scr->ptime_range, scr->range_num, + sample->time)) {return 0 ; + }if (debug_mode) {if (sample->time < last_timestamp) {
@@ -3360,10 +3365,27 @@ int cmd_script(int argc, const char **argv) goto out_delete;/* needs to be parsed after looking up reference time */ -if (perf_time__parse_str (&script.ptime, script.time_str) !=0 ) { -pr_err ("Invalid time string\n" ); - err = -EINVAL ; - goto out_delete; +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 ("No first/last sample time in perf data\n" ); + err = -EINVAL ; + goto out_delete; + } + + script.range_num =perf_time__percent_parse_str ( + script.ptime_range,PTIME_RANGE_MAX , + 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 ; + goto out_delete; + } + }else { + script.range_num =1 ; } err =__cmd_script (&script);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 13/27 perf tools: Enable LIBBABELTRACE by default
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
There's no reason anymore to treat babel trace in a special way, because
a) we no longer display its state b) the needed babeltrace library is now out and well adopted among distros.
--- tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/Makefile.config +1 -1
@@ -780,7 +780,7 @@ else NO_PERF_READ_VDSOX32 := 1 endif -ifdef LIBBABELTRACE +ifndef NO_LIBBABELTRACE $(call feature_check,libbabeltrace) ifeq ($(feature-libbabeltrace), 1) CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
tools/perf/Makefile.perf +1 -1
@@ -77,7 +77,7 @@ include ../scripts/utilities.mak # # Define NO_ZLIB if you do not want to support compressed kernel modules # -# Define LIBBABELTRACE if you DO want libbabeltrace support +# Define NO_LIBBABELTRACE if you do not want libbabeltrace support # for CTF data format. # # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 14/27 perf tools: Display perf_event_attr::namespaces debug info
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Display namespaces bit in -vv debug display:
$ perf record -vv --namespaces ...
...
perf_event_attr:
size 112
...
namespaces 1--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
@@ -1577,6 +1577,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,PRINT_ATTRf (use_clockid, p_unsigned);PRINT_ATTRf (context_switch, p_unsigned);PRINT_ATTRf (write_backward, p_unsigned); +PRINT_ATTRf (namespaces, p_unsigned);PRINT_ATTRn ("{ wakeup_events, wakeup_watermark }" , wakeup_events, p_unsigned);PRINT_ATTRf (bp_type, p_unsigned);
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 15/27 perf: Allocate context task_ctx_data for child event
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Currently we use perf_event_context::task_ctx_data to save and restore the LBR status when the task is scheduled out and in.
We don't allocate it for child contexts, which results in shorter task's LBR stack, because we don't save the history from previous run and start over every time we schedule the task in.
I made a test to generate samples with LBR call stack and got higher numbers on bigger chain depths:
before: after:
LBR call chain: nr: 1 60561 498127
LBR call chain: nr: 2 0 0
LBR call chain: nr: 3 107030 2172
LBR call chain: nr: 4 466685 62758
LBR call chain: nr: 5 2307319 878046
LBR call chain: nr: 6 48713 495218
LBR call chain: nr: 7 1040 4551
LBR call chain: nr: 8 481 172 LBR call chain: nr: 9 878 120 LBR call chain: nr: 10 2377 6698 LBR call chain: nr: 11 28830 151487 LBR call chain: nr: 12 29347 339867 LBR call chain: nr: 13 4 22 LBR call chain: nr: 14 3 53
--- kernel/events/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
kernel/events/core.c +14 -0
@@ -10703,6 +10703,19 @@ inherit_event(struct perf_event *parent_event,if (IS_ERR (child_event))return child_event; + +if ((child_event->attach_state &PERF_ATTACH_TASK_DATA ) && + !child_ctx->task_ctx_data) { +struct pmu *pmu = child_event->pmu; + + child_ctx->task_ctx_data =kzalloc (pmu->task_ctx_size, +GFP_KERNEL ); +if (!child_ctx->task_ctx_data) { +free_event (child_event); +return NULL ; + } + } +/* * is_orphaned_event() and list_add_tail(&parent_event->child_list) * must be under the same lock in order to serialize against
@@ -10713,6 +10726,7 @@ inherit_event(struct perf_event *parent_event,if (is_orphaned_event (parent_event) || !atomic_long_inc_not_zero (&parent_event->refcount)) {mutex_unlock (&parent_event->child_mutex); +/* task_ctx_data is freed with child_ctx */ free_event (child_event);return NULL ; }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 16/27 perf: Add sample_id to PERF_RECORD_ITRACE_START event comment
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding missing sample_id line into PERF_RECORD_ITRACE_START event comment.
--- include/uapi/linux/perf_event.h | 1 + tools/include/uapi/linux/perf_event.h | 1 + 2 files changed, 2 insertions(+)
include/uapi/linux/perf_event.h +1 -0
@@ -864,6 +864,7 @@ enum perf_event_type {* struct perf_event_header header; * u32 pid; * u32 tid; +* struct sample_id sample_id; * }; */ PERF_RECORD_ITRACE_START = 12,
tools/include/uapi/linux/perf_event.h +1 -0
@@ -864,6 +864,7 @@ enum perf_event_type {* struct perf_event_header header; * u32 pid; * u32 tid; +* struct sample_id sample_id; * }; */ PERF_RECORD_ITRACE_START = 12,
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 17/27 perf: Make perf_callchain function static
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
And move it to core.c, because there's no caller of this function other than the one in core.c
--- kernel/events/callchain.c | 15 --------------- kernel/events/core.c | 16 ++++++++++++++++ kernel/events/internal.h | 4 ---- 3 files changed, 16 insertions(+), 19 deletions(-)
kernel/events/callchain.c +0 -15
@@ -178,21 +178,6 @@ put_callchain_entry(int rctx)put_recursion_context (this_cpu_ptr (callchain_recursion), rctx); } -struct perf_callchain_entry * -perf_callchain (struct perf_event *event,struct pt_regs *regs) -{ -bool kernel = !event->attr.exclude_callchain_kernel; -bool user = !event->attr.exclude_callchain_user; -/* Disallow cross-task user callchains. */ -bool crosstask = event->ctx->task && event->ctx->task != current; -const u32 max_stack = event->attr.sample_max_stack; - -if (!kernel && !user) -return NULL ; - -return get_perf_callchain (regs,0 , kernel, user, max_stack, crosstask, true); -} -struct perf_callchain_entry *get_perf_callchain (struct pt_regs *regs,u32 init_nr,bool kernel,bool user,u32 max_stack,bool crosstask,bool add_mark)
kernel/events/core.c +16 -0
@@ -5980,6 +5980,22 @@ static u64 perf_virt_to_phys(u64 virt)return phys_addr; } +static struct perf_callchain_entry * +perf_callchain (struct perf_event *event,struct pt_regs *regs) +{ +bool kernel = !event->attr.exclude_callchain_kernel; +bool user = !event->attr.exclude_callchain_user; +/* Disallow cross-task user callchains. */ +bool crosstask = event->ctx->task && event->ctx->task != current; +const u32 max_stack = event->attr.sample_max_stack; + +if (!kernel && !user) +return NULL ; + +return get_perf_callchain (regs,0 , kernel, user, + max_stack, crosstask, true); +} + void perf_prepare_sample(struct perf_event_header *header, struct perf_sample_data *data, struct perf_event *event,
kernel/events/internal.h +0 -4
@@ -201,10 +201,6 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n) DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user) -/* Callchain handling */ -extern struct perf_callchain_entry * -perf_callchain (struct perf_event *event,struct pt_regs *regs); -static inline int get_recursion_context (int *recursion) {int rctx;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 18/27 perf: Return empty callchain instead of NULL
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
It simplifies the code a bit, because we dump the callchain
even if it's empty. With 'empty' callchain we can remove all the NULL-checking code paths.
Original-patch-from: Peter Zijlstra <[email protected]>
--- kernel/events/core.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
kernel/events/core.c +12 -18
@@ -5815,19 +5815,11 @@ void perf_output_sample(struct perf_output_handle *handle,perf_output_read (handle, event);if (sample_type &PERF_SAMPLE_CALLCHAIN ) { -if (data->callchain) { -int size =1 ; - -if (data->callchain) - size += data->callchain->nr; - - size *=sizeof (u64); +int size =1 ; -__output_copy (handle, data->callchain, size); - }else { -u64 nr =0 ; -perf_output_put (handle, nr); - } + size += data->callchain->nr; + size *=sizeof (u64); +__output_copy (handle, data->callchain, size); }if (sample_type &PERF_SAMPLE_RAW ) {
@@ -5980,6 +5972,8 @@ static u64 perf_virt_to_phys(u64 virt)return phys_addr; } +static struct perf_callchain_entry __empty_callchain = { .nr =0 , }; +static struct perf_callchain_entry *perf_callchain (struct perf_event *event,struct pt_regs *regs) {
@@ -5988,12 +5982,14 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs)/* Disallow cross-task user callchains. */ bool crosstask = event->ctx->task && event->ctx->task != current;const u32 max_stack = event->attr.sample_max_stack; +struct perf_callchain_entry *callchain;if (!kernel && !user) -return NULL ; +return &__empty_callchain; -return get_perf_callchain (regs,0 , kernel, user, - max_stack, crosstask, true); + callchain =get_perf_callchain (regs,0 , kernel, user, + max_stack, crosstask, true); +return callchain ?: &__empty_callchain; } void perf_prepare_sample(struct perf_event_header *header,
@@ -6018,9 +6014,7 @@ void perf_prepare_sample(struct perf_event_header *header,int size =1 ; data->callchain =perf_callchain (event, regs); - -if (data->callchain) - size += data->callchain->nr; + size += data->callchain->nr; header->size += size *sizeof (u64); }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 19/27 perf: Update PERF_RECORD_MISC_* comment for perf_event_header::misc bit 13
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
The perf_event_header::misc bit 13 is shared on different events and next patch is adding yet another bit 13 user. Updating the comment to make it more structured and clear which events use bit 13.
--- include/uapi/linux/perf_event.h | 9 ++++++--- tools/include/uapi/linux/perf_event.h | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-)
include/uapi/linux/perf_event.h +6 -3
@@ -612,9 +612,12 @@ struct perf_event_mmap_page {*/ #define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT (1 << 12)/* -* PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on -* different events so can reuse the same bit position. -* Ditto PERF_RECORD_MISC_SWITCH_OUT. +* Following PERF_RECORD_MISC_* are used on different +* events, so can reuse the same bit position: +* +* PERF_RECORD_MISC_MMAP_DATA - PERF_RECORD_MMAP* events +* PERF_RECORD_MISC_COMM_EXEC - PERF_RECORD_COMM event +* PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events */ #define PERF_RECORD_MISC_MMAP_DATA (1 << 13)#define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
tools/include/uapi/linux/perf_event.h +6 -3
@@ -612,9 +612,12 @@ struct perf_event_mmap_page {*/ #define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT (1 << 12)/* -* PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on -* different events so can reuse the same bit position. -* Ditto PERF_RECORD_MISC_SWITCH_OUT. +* Following PERF_RECORD_MISC_* are used on different +* events, so can reuse the same bit position: +* +* PERF_RECORD_MISC_MMAP_DATA - PERF_RECORD_MMAP* events +* PERF_RECORD_MISC_COMM_EXEC - PERF_RECORD_COMM event +* PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events */ #define PERF_RECORD_MISC_MMAP_DATA (1 << 13)#define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 20/27 perf script: Add support to display sample misc field
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding support to display sample misc field in form of letter for each bit:
# perf script -F +misc ... sched-messaging 1414 K 28690.636582: 4590 cycles ... sched-messaging 1407 U 28690.636600: 325620 cycles ... sched-messaging 1414 K 28690.636608: 19473 cycles ... misc field __________/
The misc bits are assigned to following letters:
PERF_RECORD_MISC_KERNEL K PERF_RECORD_MISC_USER U PERF_RECORD_MISC_HYPERVISOR H PERF_RECORD_MISC_GUEST_KERNEL G PERF_RECORD_MISC_GUEST_USER g PERF_RECORD_MISC_MMAP_DATA* M PERF_RECORD_MISC_COMM_EXEC E PERF_RECORD_MISC_SWITCH_OUT S
--- tools/perf/Documentation/perf-script.txt | 20 ++++++++- tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++----- tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 1 + 4 files changed, 84 insertions(+), 12 deletions(-)
tools/perf/Documentation/perf-script.txt +19 -1
@@ -117,7 +117,7 @@ OPTIONS Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, - brstackoff, callindent, insn, insnlen, synth, phys_addr, metric. + brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -225,6 +225,24 @@ OPTIONS that the metric computed is averaged over the whole sampling period, not just for the sample point. + For sample events it's possible to display misc field with -F +misc option, + following letters are displayed for each bit: + + PERF_RECORD_MISC_KERNEL K + PERF_RECORD_MISC_USER U + PERF_RECORD_MISC_HYPERVISOR H + PERF_RECORD_MISC_GUEST_KERNEL G + PERF_RECORD_MISC_GUEST_USER g + PERF_RECORD_MISC_MMAP_DATA* M + PERF_RECORD_MISC_COMM_EXEC E + PERF_RECORD_MISC_SWITCH_OUT S + + $ perf script -F +misc ... + sched-messaging 1414 K 28690.636582: 4590 cycles ... + sched-messaging 1407 U 28690.636600: 325620 cycles ... + sched-messaging 1414 K 28690.636608: 19473 cycles ... + misc field ___________/ + -k:: --vmlinux=<file>:: vmlinux pathname
tools/perf/builtin-script.c +63 -11
158 lines not on this page · raw message
tools/perf/util/event.h +1 -0
@@ -205,6 +205,7 @@ struct perf_sample {u32 flags;u16 insn_len;u8 cpumode; +u16 misc;char insn[MAX_INSN ];void *raw_data;struct ip_callchain *callchain;
tools/perf/util/evsel.c +1 -0
@@ -2042,6 +2042,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, data->stream_id = data->id = data->time =-1ULL ; data->period = evsel->attr.sample_period; data->cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ; + data->misc = event->header.misc; data->id =-1ULL ; data->data_src =PERF_MEM_DATA_SRC_NONE ;
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 21/27 perf script: Add support to display lost events
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding option to display lost events:
$ perf script --show-lost-events ... mplayer 13810 [002] 468011.402396: 100 cycles:ppp: ff.. mplayer 13810 [002] 468011.402396: PERF_RECORD_LOST lost 3880 mplayer 13810 [002] 468011.402397: 100 cycles:ppp: ff..
--- tools/perf/Documentation/perf-script.txt | 3 +++ tools/perf/builtin-script.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/event.c | 8 ++++++++ 3 files changed, 39 insertions(+)
tools/perf/Documentation/perf-script.txt +3 -0
@@ -300,6 +300,9 @@ OPTIONS Display context switch events i.e. events of type PERF_RECORD_SWITCH or PERF_RECORD_SWITCH_CPU_WIDE. +--show-lost-events + Display lost events i.e. events of type PERF_RECORD_LOST. + --demangle:: Demangle symbol names to human readable form. It's enabled by default, disable with --no-demangle.
tools/perf/builtin-script.c +28 -0
@@ -1489,6 +1489,7 @@ struct perf_script {bool show_mmap_events;bool show_switch_events;bool show_namespace_events; +bool show_lost_events;bool allocated;bool per_event_dump;struct cpu_map *cpus;
@@ -2080,6 +2081,29 @@ static int process_switch_event(struct perf_tool *tool,return 0 ; } +static int +process_lost_event (struct perf_tool *tool, +union perf_event *event, +struct perf_sample *sample, +struct machine *machine) +{ + struct perf_script *script = container_of(tool, struct perf_script, tool); +struct perf_session *session = script->session; +struct perf_evsel *evsel =perf_evlist__id2evsel (session->evlist, sample->id); +struct thread *thread; + + thread =machine__findnew_thread (machine, sample->pid, + sample->tid); +if (thread ==NULL ) +return -1 ; + +perf_sample__fprintf_start (sample, thread, evsel, +PERF_RECORD_LOST , stdout); +perf_event__fprintf (event, stdout); +thread__put (thread); +return 0 ; +} +static void sig_handler (int sig__maybe_unused ) { session_done =1 ;
@@ -2174,6 +2198,8 @@ static int __cmd_script(struct perf_script *script) script->tool.context_switch = process_switch_event;if (script->show_namespace_events) script->tool.namespaces = process_namespaces_event; +if (script->show_lost_events) + script->tool.lost = process_lost_event;if (perf_script__setup_per_event_dump (script)) {pr_err ("Couldn't create the per event dump files\n" );
@@ -3110,6 +3136,8 @@ int cmd_script(int argc, const char **argv) "Show context switch events (if recorded)"),OPT_BOOLEAN ('\0' ,"show-namespace-events" , &script.show_namespace_events,"Show namespace events (if recorded)" ), +OPT_BOOLEAN ('\0' ,"show-lost-events" , &script.show_lost_events, +"Show lost events (if recorded)" ),OPT_BOOLEAN ('\0' ,"per-event-dump" , &script.per_event_dump,"Dump trace output to files named by the monitored events" ), OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
tools/perf/util/event.c +8 -0
@@ -1435,6 +1435,11 @@ size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp) event->context_switch.next_prev_tid); } +static size_t perf_event__fprintf_lost (union perf_event *event,FILE *fp) +{ +return fprintf (fp," lost %" PRIu64"\n" , event->lost.lost); +} +size_t perf_event__fprintf (union perf_event *event,FILE *fp) { size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -1467,6 +1472,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)case PERF_RECORD_SWITCH_CPU_WIDE : ret +=perf_event__fprintf_switch (event, fp);break ; +case PERF_RECORD_LOST : + ret +=perf_event__fprintf_lost (event, fp); +break ;default : ret +=fprintf (fp,"\n" ); }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 22/27 perf tools: Make the tool's warning messages optional
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
I want to display the pure events status coming in the next patch and the tool's warnings are superfluous in the output. Making it optional, enabled by default.
--- tools/perf/util/session.c | 6 ++++-- tools/perf/util/tool.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/session.c +4 -2
@@ -1773,7 +1773,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session) err =perf_session__flush_thread_stacks (session); out_err:free (buf); -perf_session__warn_about_errors (session); +if (!tool->no_warn) +perf_session__warn_about_errors (session);ordered_events__free (&session->ordered_events);auxtrace__free_events (session);return err;
@@ -1929,7 +1930,8 @@ static int __perf_session__process_events(struct perf_session *session, err =perf_session__flush_thread_stacks (session); out_err:ui_progress__finish (); -perf_session__warn_about_errors (session); +if (!tool->no_warn) +perf_session__warn_about_errors (session);/* * We may switching perf.data output, make ordered_events * reusable.
tools/perf/util/tool.h +1 -0
@@ -76,6 +76,7 @@ struct perf_tool {bool ordered_events;bool ordering_requires_timestamps;bool namespace_events; +bool no_warn;enum show_feature_header show_feat_hdr; };
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 23/27 perf report: Add --stats option to display quick data statistics
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add --stats option to display quick data statistics of event numbers, without any further processing, like the one at the end of the perf report -D command.
$ perf report --stat
Aggregated stats:
TOTAL events: 4566
MMAP events: 113
LOST events: 19
COMM events: 3
FORK events: 400
SAMPLE events: 3315
MMAP2 events: 32
FINISHED_ROUND events: 681
THREAD_MAP events: 1
CPU_MAP events: 1
TIME_CONV events: 1
I found this useful when hunting lost events for another change.
--- tools/perf/Documentation/perf-report.txt | 4 ++++ tools/perf/builtin-report.c | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +4 -0
@@ -457,6 +457,10 @@ include::itrace.txt[] will be printed. Each entry is function name or file/line. Enabled by default, disable with --no-inline. +--stats:: + Display overall events statistics without any further processing. + (like the one at the end of the perf report -D command) + include::callchain-overhead-calculation.txt[] SEE ALSO
tools/perf/builtin-report.c +25 -1
@@ -62,6 +62,7 @@ struct report {bool show_threads;bool inverted_callchain;bool mem_mode; +bool stats_mode;bool header;bool header_only;bool nonany_branch_mode;
@@ -588,6 +589,20 @@ static void report__output_resort(struct report *rep)ui_progress__finish (); } +static void stats_setup (struct report *rep) +{ +memset (&rep->tool,0 ,sizeof (rep->tool)); + rep->tool.no_warn = true; +} + +static int stats_print (struct report *rep) +{ +struct perf_session *session = rep->session; + +perf_session__fprintf_nr_events (session, stdout); +return 0 ; +} +static int __cmd_report (struct report *rep) {int ret;
@@ -619,12 +634,18 @@ static int __cmd_report(struct report *rep)return ret; } +if (rep->stats_mode) +stats_setup (rep); + ret =perf_session__process_events (session);if (ret) {ui__error ("failed to process sample\n" );return ret; } +if (rep->stats_mode) +return stats_print (rep); +report__warn_kptr_restrict (rep);evlist__for_each_entry (session->evlist, pos)
@@ -781,6 +802,7 @@ int cmd_report(int argc, const char **argv)OPT_BOOLEAN ('q' ,"quiet" , &quiet,"Do not show any message" ),OPT_BOOLEAN ('D' ,"dump-raw-trace" , &dump_trace,"dump raw trace in ASCII" ), +OPT_BOOLEAN (0 ,"stats" , &report.stats_mode,"Display event stats" ),OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
@@ -1042,6 +1064,8 @@ int cmd_report(int argc, const char **argv) report.tool.show_feat_hdr =SHOW_FEAT_HEADER ;if (report.show_full_info) report.tool.show_feat_hdr =SHOW_FEAT_HEADER_FULL_INFO ; +if (report.stats_mode) + use_browser =0 ;if (strcmp (input_name,"-" ) !=0 )setup_browser (true);
@@ -1064,7 +1088,7 @@ int cmd_report(int argc, const char **argv) ret =0 ; goto error; } - }else if (use_browser ==0 && !quiet) { + }else if (use_browser ==0 && !quiet && !report.stats_mode) {fputs ("# To display the perf.data header info, please use --header/--header-only options.\n#\n" , stdout); }
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 24/27 perf trace: Beautify 'gettid' syscall result
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Before:
# trace -a -e gettid sleep 0.01
<SNIP>
4.863 ( 0.005 ms): Chrome_ChildIO/26241 gettid() = 26241
4.931 ( 0.004 ms): Chrome_IOThrea/26154 gettid() = 26154
4.942 ( 0.001 ms): Chrome_IOThrea/26154 gettid() = 26154
4.946 ( 0.001 ms): Chrome_IOThrea/26154 gettid() = 26154
4.970 ( 0.002 ms): Chrome_IOThrea/26154 gettid() = 26154
#After:
# trace -a -e gettid sleep 0.01
0.000 ( 0.009 ms): Chrome_IOThrea/26154 gettid() = 26154 (Chrome_IOThread)
<SNIP>
3.416 ( 0.002 ms): Chrome_ChildIO/26241 gettid() = 26241 (Chrome_ChildIOT)
3.424 ( 0.001 ms): Chrome_ChildIO/26241 gettid() = 26241 (Chrome_ChildIOT)
3.343 ( 0.002 ms): chrome/26116 gettid() = 26116 (chrome)
3.386 ( 0.002 ms): Chrome_IOThrea/26154 gettid() = 26154 (Chrome_IOThread)
4.003 ( 0.003 ms): Chrome_ChildIO/26241 gettid() = 26241 (Chrome_ChildIOT)
4.031 ( 0.002 ms): Chrome_IOThrea/26154 gettid() = 26154 (Chrome_IOThread)
#--- tools/perf/builtin-trace.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/builtin-trace.c +1 -0
@@ -622,6 +622,7 @@ static struct syscall_fmt { .arg = { [2] = { .scnprintf = SCA_GETRANDOM_FLAGS, /* flags */ }, }, }, { .name = "getrlimit", .arg = { [0] = STRARRAY(resource, rlimit_resources), }, }, + { .name = "gettid", .errpid = true, }, { .name = "ioctl", .arg = {#if defined(__i386__) || defined(__x86_64__)
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 25/27 perf report: Add --tasks option to display monitored tasks
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add --tasks option to display monitored tasks stored in perf.data. Displaying pid/tid/ppid plus the command string aligned to distinguish parent and child tasks.
$ perf record -a
...
$ perf report --tasks
# pid tid ppid comm
0 0 -1 |swapper
2 2 0 | kthreadd
14080 14080 2 | kworker/u17:1
4 4 2 | kworker/0:0H
6 6 2 | mm_percpu_wq
...
1 1 0 | systemd
23242 23242 1 | firefox
23242 23298 23242 | Cache2 I/O
23242 23304 23242 | GMPThread
...
1195 1195 1 | login
1611 1611 1195 | bash
1639 1639 1611 | startx
1663 1663 1639 | xinit
1673 1673 1663 | xmonad-x86_64-l
23939 23939 1673 | xterm
23941 23941 23939 | bash
23963 23963 23941 | mutt
24954 24954 23963 | offlineimap--- tools/perf/Documentation/perf-report.txt | 4 + tools/perf/builtin-report.c | 136 ++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-report.txt +4 -0
@@ -461,6 +461,10 @@ include::itrace.txt[] Display overall events statistics without any further processing. (like the one at the end of the perf report -D command) +--tasks:: + Display monitored tasks stored in perf data. Displaying pid/tid/ppid + plus the command string aligned to distinguish parent and child tasks. + include::callchain-overhead-calculation.txt[] SEE ALSO
tools/perf/builtin-report.c +134 -2
185 lines not on this page · raw message
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 26/27 perf report: Introduce --mmaps
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Similar to --tasks, producing the same output plus /proc/<PID>/maps similar lines for each mmap record present in a perf.data file.
Please note that not all mmaps are stored, for instance, some of the non-executable mmaps are only stored when 'perf record --data' is used, when the user wants to resolve data accesses in addition to asking for executable mmaps to get the DSO with symtabs.
E.g.:
# perf record sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.018 MB perf.data (7 samples) ]
[root@jouet ~]# perf report --mmaps
# pid tid ppid comm
0 0 -1 |swapper
4137 4137 -1 |sleep
5628a35a1000-5628a37aa000 r-xp 00000000 3147148 /usr/bin/sleep
7fb65ad51000-7fb65b134000 r-xp 00000000 3149795 /usr/lib64/libc-2.26.so
7fb65b134000-7fb65b35e000 r-xp 00000000 3149715 /usr/lib64/ld-2.26.so
7ffd94b9f000-7ffd94ba1000 r-xp 00000000 0 [vdso]
#
# perf record sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (8 samples) ]
# perf report --mmaps
# pid tid ppid comm
0 0 -1 |swapper
4161 4161 -1 |sleep
55afae69a000-55afae8a3000 r-xp 00000000 3147148 /usr/bin/sleep
7f569f00d000-7f569f3f0000 r-xp 00000000 3149795 /usr/lib64/libc-2.26.so
7f569f3f0000-7f569f61a000 r-xp 00000000 3149715 /usr/lib64/ld-2.26.so
7fff6fffe000-7fff70000000 r-xp 00000000 0 [vdso]
#
# perf record time sleep 1
0.00user 0.00system 0:01.00elapsed 0%CPU (0avgtext+0avgdata 2156maxresident)k
0inputs+0outputs (0major+73minor)pagefaults 0swaps
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (14 samples) ]
# perf report --mmaps
# pid tid ppid comm
0 0 -1 |swapper
4281 4281 -1 |time
560560dca000-560560fcf000 r-xp 00000000 3190458 /usr/bin/time
7fc175196000-7fc175579000 r-xp 00000000 3149795 /usr/lib64/libc-2.26.so
7fc175579000-7fc1757a3000 r-xp 00000000 3149715 /usr/lib64/ld-2.26.so
7ffc924f6000-7ffc924f8000 r-xp 00000000 0 [vdso]
4282 4282 4281 | sleep
560560dca000-560560fcf000 r-xp 00000000 3190458 /usr/bin/time
564b4de3c000-564b4e045000 r-xp 00000000 3147148 /usr/bin/sleep
7f6a5a716000-7f6a5aaf9000 r-xp 00000000 3149795 /usr/lib64/libc-2.26.so
7f6a5aaf9000-7f6a5ad23000 r-xp 00000000 3149715 /usr/lib64/ld-2.26.so
7fc175196000-7fc175579000 r-xp 00000000 3149795 /usr/lib64/libc-2.26.so
7fc175579000-7fc1757a3000 r-xp 00000000 3149715 /usr/lib64/ld-2.26.so
7ffc924f6000-7ffc924f8000 r-xp 00000000 0 [vdso]
7ffcec7e6000-7ffcec7e8000 r-xp 00000000 0 [vdso]
#--- tools/perf/Documentation/perf-report.txt | 9 +++++- tools/perf/builtin-report.c | 50 +++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-report.txt +8 -1
@@ -457,6 +457,13 @@ include::itrace.txt[] will be printed. Each entry is function name or file/line. Enabled by default, disable with --no-inline. +--mmaps:: + Show --tasks output plus mmap information in a format similar to + /proc/<PID>/maps. + + Please note that not all mmaps are stored, options affecting which ones + are include 'perf record --data', for instance. + --stats:: Display overall events statistics without any further processing. (like the one at the end of the perf report -D command)
@@ -469,4 +476,4 @@ include::callchain-overhead-calculation.txt[] SEE ALSO -------- -linkperf:perf-stat[1], linkperf:perf-annotate[1] +linkperf:perf-stat[1], linkperf:perf-annotate[1], linkperf:perf-record[1]
tools/perf/builtin-report.c +46 -4
97 lines not on this page · raw message
Signature · 1 line
2.14.3
Arnaldo Carvalho de Melo
maintainerPATCH 27/27 tools headers: Synchronize kernel <-> tooling headers
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Two kernel headers got modified recently due to meltdown/spectre, in:
a89f040fa34e ("x86/cpufeatures: Add X86_BUG_CPU_INSECURE")
which are used by tooling as well:
arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/disabled-features.h
None of those changes have an effect on tooling, so do a plain copy.
--- tools/arch/x86/include/asm/cpufeatures.h | 4 +++- tools/arch/x86/include/asm/disabled-features.h | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-)
tools/arch/x86/include/asm/cpufeatures.h +3 -1
@@ -197,11 +197,12 @@#define X86_FEATURE_CAT_L3 ( 7*32+ 4)/* Cache Allocation Technology L3 */ #define X86_FEATURE_CAT_L2 ( 7*32+ 5)/* Cache Allocation Technology L2 */ #define X86_FEATURE_CDP_L3 ( 7*32+ 6)/* Code and Data Prioritization L3 */ +#define X86_FEATURE_INVPCID_SINGLE ( 7*32+ 7)/* Effectively INVPCID && CR4.PCIDE=1 */ #define X86_FEATURE_HW_PSTATE ( 7*32+ 8)/* AMD HW-PState */ #define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9)/* AMD ProcFeedbackInterface */ #define X86_FEATURE_SME ( 7*32+10)/* AMD Secure Memory Encryption */ - +#define X86_FEATURE_PTI ( 7*32+11)/* Kernel Page Table Isolation enabled */ #define X86_FEATURE_INTEL_PPIN ( 7*32+14)/* Intel Processor Inventory Number */ #define X86_FEATURE_INTEL_PT ( 7*32+15)/* Intel Processor Trace */ #define X86_FEATURE_AVX512_4VNNIW ( 7*32+16)/* AVX-512 Neural Network Instructions */
@@ -340,5 +341,6 @@#define X86_BUG_SWAPGS_FENCE X86_BUG(11)/* SWAPGS without input dep on GS */ #define X86_BUG_MONITOR X86_BUG(12)/* IPI required to wake up remote CPU */ #define X86_BUG_AMD_E400 X86_BUG(13)/* CPU is among the affected by Erratum 400 */ +#define X86_BUG_CPU_MELTDOWN X86_BUG(14)/* CPU is affected by meltdown attack and needs kernel page table isolation */ #endif /* _ASM_X86_CPUFEATURES_H */
tools/arch/x86/include/asm/disabled-features.h +7 -1
@@ -50,6 +50,12 @@# define DISABLE_LA57 (1<<(X86_FEATURE_LA57 & 31))#endif +#ifdef CONFIG_PAGE_TABLE_ISOLATION +# define DISABLE_PTI 0 +#else +# define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31)) +#endif +/* * Make sure to add features to the correct mask */
@@ -60,7 +66,7 @@#define DISABLED_MASK4 (DISABLE_PCID)#define DISABLED_MASK5 0#define DISABLED_MASK6 0 -#define DISABLED_MASK7 0 +#define DISABLED_MASK7 (DISABLE_PTI)#define DISABLED_MASK8 0#define DISABLED_MASK9 (DISABLE_MPX)#define DISABLED_MASK10 0
Signature · 1 line
2.14.3
Quoted 141 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
9128d3ed9de3882c83b927eb553d5d44c84505f5:perf/x86/msr: Clean up the code (2018-01-06 12:18:40 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-4.16-20180110for you to fetch changes up to
5d64db2966e38bfd99114ecf0b54f97d33023dcd:tools headers: Synchronize kernel <-> tooling headers (2018-01-10 12:46:54 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:- The 'perf test bpf' entry hooked a eBPF proggie to the
SyS_epoll_wait()kernel function and expected it to be hit when calling theepoll_wait()libc wrapper, which changed recently, in systems such as Fedora 27, with the glibc wrapper calling instead theepoll_pwait()syscall, so switch toepoll_pwait()for both the kernel and libc function, getting it to work both in old and new systems (Arnaldo Carvalho de Melo)- Beautify 'gettid' syscall result in 'perf trace', and in doing so noticed that we need to handle namespaces in 'perf trace', will be dealt with in follow up patches where we'll try to figure out if the recent support for namespace in
tools/perf/can be used for this purpose as well. (Arnaldo Carvalho de Melo)- Introduce 'perf report --mmaps' and 'perf report --tasks' to show info present in 'perf.data' (Jiri Olsa, Arnaldo Carvalho de Melo)
- Synchronize kernel <-> tooling headers wrt meltdown/spectre changes (Arnaldo Carvalho de Melo)
- Fix a wrong offset issue when using
/proc/kcore(Jin Yao)- Fix bug that prevented annotating symbols in perf.data files generated with 'perf record --branch-any' (Jin Yao)
- Add infrastructure to record first and last sample time to the perf.data file header, so that when processing all samples in a 'perf record' session, such as when doing build-id processing, or when specifically requesting that that info be recorded, use that in 'perf report --time', that also got support for percent slices in addition to absolute ones.
I.e. now it is possible to ask for the samples in the 10%-20% time slice of a perf.data file (Jin Yao)
- Enable building with libbabeltrace by default (Jiri Olsa)
- Display
perf_event_attr::namespaceswhen duping the attributes in verbose mode (Jiri Olsa)- Allocate context
task_ctx_datafor child event (Jiri Olsa)- Update comments for
PERF_RECORD_ITRACE_STARTand PERF_RECORD_MISC_* (Jiri Olsa)- Add support for showing
PERF_RECORD_LOSTevents in 'perf script' (Jiri Olsa)- Add 'perf report --stats' option to display quick statistics about metadata events (PERF_RECORD_*) i.e. what we get at the end of 'perf report -D' (Jiri Olsa)
- Fix compile error with libunwind x86 (Wang Nan)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Arnaldo Carvalho de Melo (6):
perf test bpf: Improve message about expected samples perf test bpf: Use designated struct field initializers perf test bpf: Hook onepoll_pwait()
perf trace: Beautify 'gettid' syscall result perf report: Introduce --mmaps
tools headers: Synchronize kernel <-> tooling headersJin Yao (8):
perf report: Fix a wrong offset issue when using/proc/kcoreperf report: Fix a no annotate browser displayed issue perf header: Add infrastructure to record first and last sample time perf record: Record the first and last sample time in the header perf tools: Create function to parse time percent
perf tools: Create function to perform multiple time range checking perf report: Support time percent and multiple time ranges perf script: Support time percent and multiple time rangesJiri Olsa (12):
perf tools: Enable LIBBABELTRACE by default
perf tools: Displayperf_event_attr::namespacesdebug info
perf: Allocate contexttask_ctx_datafor child event
perf: Addsample_idtoPERF_RECORD_ITRACE_STARTevent comment
perf: Makeperf_callchainfunction static
perf: Return empty callchain instead of NULL
perf: Update PERF_RECORD_MISC_* comment forperf_event_header::miscbit 13 perf script: Add support to display sample misc field
perf script: Add support to display lost events
perf tools: Make the tool's warning messages optional
perf report: Add --stats option to display quick data statistics perf report: Add --tasks option to display monitored tasksWang Nan (1):
perf tools: Fix compile error with libunwind x86include/uapi/linux/perf_event.h | 10 +- kernel/events/callchain.c | 15 -- kernel/events/core.c | 54 +++-- kernel/events/internal.h | 4 - tools/arch/x86/include/asm/cpufeatures.h | 4 +- tools/arch/x86/include/asm/disabled-features.h | 8 +- tools/include/uapi/linux/perf_event.h | 10 +- tools/perf/Documentation/perf-record.txt | 3 + tools/perf/Documentation/perf-report.txt | 37 ++- tools/perf/Documentation/perf-script.txt | 39 +++- tools/perf/Documentation/perf.data-file-format.txt | 4 + tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 2 +- tools/perf/arch/x86/util/unwind-libunwind.c | 2 +- tools/perf/builtin-record.c | 18 +- tools/perf/builtin-report.c | 249 ++++++++++++++++++++- tools/perf/builtin-script.c | 136 +++++++++-- tools/perf/builtin-trace.c | 1 + tools/perf/tests/bpf-script-example.c | 4 +- tools/perf/tests/bpf.c | 65 +++--- tools/perf/util/annotate.c | 3 +- tools/perf/util/event.c | 8 + tools/perf/util/event.h | 1 + tools/perf/util/evlist.h | 2 + tools/perf/util/evsel.c | 2 + tools/perf/util/header.c | 60 +++++ tools/perf/util/header.h | 1 + tools/perf/util/machine.c | 2 +- tools/perf/util/map.c | 2 +-
Quoted 8 lines
tools/perf/util/session.c | 6 +- tools/perf/util/sort.c | 16 +- tools/perf/util/srcline.c | 9 +- tools/perf/util/srcline.h | 5 +- tools/perf/util/time-utils.c | 233 ++++++++++++++++++- tools/perf/util/time-utils.h | 6 + tools/perf/util/tool.h | 1 + 36 files changed, 884 insertions(+), 140 deletions(-)
Pulled, thanks a lot Arnaldo!
Ingo