perf/core improvements and fixes
Arnaldo Carvalho de Melo
maintainerHi Ingo/Thomas,
Please consider pulling,
Best regards,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit d46eec8e975a8180e178e01ba505801c44bc9a6c:
Merge remote-tracking branch 'acme/perf/urgent' into perf/core (2020-03-04 10:29:19 -0300)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-5.7-20200310
for you to fetch changes up to f787feff69c466dfc6f261c9632627e383b49187:
perf block-info: Support color ops to print block percents in color (2020-03-09 21:43:25 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
perf stat:
Jin Yao:
- Show percore counts in per CPU output.
perf report:
Jin Yao:
- Allow selecting which block info columns to report and its order.
- Support color ops to print block percents in color.
- Fix wrong block address comparison in block_info__cmp().
perf annotate:
Ravi Bangoria:
- Get rid of annotation->nr_jumps, unused.
expr:
Jiri Olsa:
- Move expr lexer to flex.
llvm:
Arnaldo Carvalho de Melo:
- Add debug hint message about missing kernel-devel package.
core:
Kan Liang:
- Initial patches to support the recently added PERF_SAMPLE_BRANCH_HW_INDEX kernel feature.
- Add check for unexpected use of reserved membrs in event attr, so that in the future older perf tools will complain instead of silently try to process unknown features.
libapi:
Namhyung Kim:
- Adopt cgroupsfs_find_mountpoint() from tools/perf/util/.
libperf:
Michael Petlan:
- Add counting example.
libtraceevent:
Steven Rostedt (VMware):
- Remove extra '\n' in print_event_time().
----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
perf llvm: Add debug hint message about missing kernel-devel package tools headers UAPI: Update tools's copy of linux/perf_event.h
Jin Yao (5):
perf stat: Show percore counts in per CPU output
perf block-info: Fix wrong block address comparison in block_info__cmp() perf diff: Use __block_info__cmp() to replace block_pair_cmp() perf block-info: Allow selecting which columns to report and its order perf block-info: Support color ops to print block percents in color
Jiri Olsa (5):
perf expr: Add expr.c object
perf expr: Move expr lexer to flex
perf expr: Increase EXPR_MAX_OTHER to support metrics with more than 15 variables perf expr: Straighten expr__parse()/expr__find_other() interface perf expr: Make expr__parse() return -1 on error
Kan Liang (3):
perf tools: Add hw_idx in struct branch_stack
perf evsel: Support PERF_SAMPLE_BRANCH_HW_INDEX
perf header: Add check for unexpected use of reserved membrs in event attr
Michael Petlan (1):
libperf: Add counting example
Namhyung Kim (1):
tools lib api fs: Move cgroupsfs_find_mountpoint()
Ravi Bangoria (1):
perf annotate: Get rid of annotation->nr_jumps
Steven Rostedt (VMware) (1):
tools lib traceevent: Remove extra '\n' in print_event_time()
tools/include/uapi/linux/perf_event.h | 8 +- tools/lib/api/fs/Build | 1 + tools/lib/api/fs/cgroup.c | 67 ++++++++ tools/lib/api/fs/fs.h | 2 + tools/lib/perf/Documentation/examples/counting.c | 83 +++++++++ tools/lib/traceevent/event-parse.c | 2 +- tools/perf/Documentation/perf-stat.txt | 9 + tools/perf/builtin-diff.c | 21 +-- tools/perf/builtin-report.c | 21 ++- tools/perf/builtin-script.c | 70 ++++---- tools/perf/builtin-stat.c | 4 + tools/perf/tests/expr.c | 10 +- tools/perf/tests/sample-parsing.c | 7 +- tools/perf/util/Build | 11 +- tools/perf/util/annotate.c | 2 - tools/perf/util/annotate.h | 1 - tools/perf/util/block-info.c | 106 +++++++----- tools/perf/util/block-info.h | 9 +- tools/perf/util/branch.h | 22 +++ tools/perf/util/cgroup.c | 63 +------ tools/perf/util/cs-etm.c | 2 + tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 20 ++- tools/perf/util/evsel.h | 6 + tools/perf/util/expr.c | 112 +++++++++++++ tools/perf/util/expr.h | 8 +- tools/perf/util/expr.l | 114 +++++++++++++ tools/perf/util/expr.y | 185 ++++----------------- tools/perf/util/header.c | 37 +++++ tools/perf/util/hist.c | 3 +- tools/perf/util/intel-pt.c | 2 + tools/perf/util/llvm-utils.c | 2 + tools/perf/util/machine.c | 35 ++-- tools/perf/util/perf_event_attr_fprintf.c | 1 + .../util/scripting-engines/trace-event-python.c | 30 ++-- tools/perf/util/session.c | 8 +- tools/perf/util/stat-display.c | 33 +++- tools/perf/util/stat-shadow.c | 4 +- tools/perf/util/stat.h | 1 + tools/perf/util/synthetic-events.c | 6 +- 40 files changed, 750 insertions(+), 379 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.c create mode 100644 tools/lib/perf/Documentation/examples/counting.c create mode 100644 tools/perf/util/expr.c create mode 100644 tools/perf/util/expr.l
Test results:
The first ones are container based builds of tools/perf with and without libelf support. Where clang is available, it is also used to build perf with/without libelf, and building with LIBCLANGLLVM=1 (built-in clang) with gcc and clang when clang and its devel libraries are installed.
The objtool and samples/bpf/ builds are disabled now that I'm switching from using the sources in a local volume to fetching them from a http server to build it inside the container, to make it easier to build in a container cluster. Those will come back later.
Several are cross builds, the ones with -x-ARCH and the android one, and those may not have all the features built, due to lack of multi-arch devel packages, available and being used so far on just a few, like debian:experimental-x-{arm64,mipsel}.
The 'perf test' one will perform a variety of tests exercising tools/perf/util/, tools/lib/{bpf,traceevent,etc}, as well as run perf commands with a variety of command line event specifications to then intercept the sys_perf_event syscall to check that the perf_event_attr fields are set up as expected, among a variety of other unit tests.
Then there is the 'make -C tools/perf build-test' ones, that build tools/perf/ with a variety of feature sets, exercising the build with an incomplete set of features as well as with a complete one. It is planned to have it run on each of the containers mentioned above, using some container orchestration infrastructure. Get in contact if interested in helping having this in place.
Clearlinux is failing when due to:
.gnu.debuglto_.debug_macro' referenced in section .gnu.debuglto_.debug_macro' of /tmp/build/perf/util/scripting-engines/perf-in.o: defined in discarded section `.gnu.debuglto_.debug_macro[wm4.stdcpredef.h.19.8dc41bed5d9037ff9622e015fb5f0ce3]' of /tmp/build/perf/util/scripting-engines/perf-in.o
Ubuntu 19.10 is failing when linking against libllvm, which isn't the default, needs to be investigated, haven't tested with CC=gcc, but should be the same problem:
+ make ARCH= CROSS_COMPILE= EXTRA_CFLAGS= LIBCLANGLLVM=1 -C /git/linux/tools/perf O=/tmp/build/perf CC=clang
.../usr/bin/ld: /usr/lib/llvm-9/lib/libclangAnalysis.a(ExprMutationAnalyzer.cpp.o): in function `clang::ast_matchers::internal::matcher_ignoringImpCasts0Matcher::matches(clang::Expr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const':
(.text._ZNK5clang12ast_matchers8internal32matcher_ignoringImpCasts0Matcher7matchesERKNS_4ExprEPNS1_14ASTMatchFinderEPNS1_21BoundNodesTreeBuilderE[_ZNK5clang12ast_matchers8internal32matcher_ignoringImpCasts0Matcher7matchesERKNS_4ExprEPNS1_14ASTMatchFinderEPNS1_21BoundNodesTreeBuilderE]+0x43): undefined reference to `clang::ast_matchers::internal::DynTypedMatcher::matches(clang::ast_type_traits::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const' /usr/bin/ld: /usr/lib/llvm-9/lib/libclangAnalysis.a(ExprMutationAnalyzer.cpp.o): in function `clang::ast_matchers::internal::matcher_hasLoopVariable0Matcher::matches(clang::CXXForRangeStmt const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const':
(.text._ZNK5clang12ast_matchers8internal31matcher_hasLoopVariable0Matcher7matchesERKNS_15CXXForRangeStmtEPNS1_14ASTMatchFinderEPNS1_21BoundNodesTreeBuilderE[_ZNK5clang12ast_matchers8internal31matcher_hasLoopVariable0Matcher7matchesERKNS_15CXXForRangeStmtEPNS1_14ASTMatchFinderEPNS1_21BoundNodesTreeBuilderE]+0x48): undefined reference to `clang::ast_matchers::internal::DynTypedMatcher::matches(clang::ast_type_traits::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const'
...
It builds ok with the default set of options.
# export PERF_TARBALL=http://192.168.124.1/perf/perf-5.6.0-rc4.tar.xz # dm 1 alpine:3.4 : Ok gcc (Alpine 5.3.0) 5.3.0, clang version 3.8.0 (tags/RELEASE_380/final) 2 alpine:3.5 : Ok gcc (Alpine 6.2.1) 6.2.1 20160822, clang version 3.8.1 (tags/RELEASE_381/final) 3 alpine:3.6 : Ok gcc (Alpine 6.3.0) 6.3.0, clang version 4.0.0 (tags/RELEASE_400/final) 4 alpine:3.7 : Ok gcc (Alpine 6.4.0) 6.4.0, Alpine clang version 5.0.0 (tags/RELEASE_500/final) (based on LLVM 5.0.0) 5 alpine:3.8 : Ok gcc (Alpine 6.4.0) 6.4.0, Alpine clang version 5.0.1 (tags/RELEASE_501/final) (based on LLVM 5.0.1) 6 alpine:3.9 : Ok gcc (Alpine 8.3.0) 8.3.0, Alpine clang version 5.0.1 (tags/RELEASE_502/final) (based on LLVM 5.0.1) 7 alpine:3.10 : Ok gcc (Alpine 8.3.0) 8.3.0, Alpine clang version 8.0.0 (tags/RELEASE_800/final) (based on LLVM 8.0.0) 8 alpine:3.11 : Ok gcc (Alpine 9.2.0) 9.2.0, Alpine clang version 9.0.0 (https://git.alpinelinux.org/aports f7f0d2c2b8bcd6a5843401a9a702029556492689) (based on LLVM 9.0.0) 9 alpine:edge : Ok gcc (Alpine 9.2.0) 9.2.0, Alpine clang version 9.0.1 (git://git.alpinelinux.org/aports 7c78441134e54efbb34618f457d88c783c913361) (based on LLVM 9.0.1) 10 alt:p8 : Ok x86_64-alt-linux-gcc (GCC) 5.3.1 20151207 (ALT p8 5.3.1-alt3.M80P.1), clang version 3.8.0 (tags/RELEASE_380/final) 11 alt:p9 : Ok x86_64-alt-linux-gcc (GCC) 8.3.1 20190507 (ALT p9 8.3.1-alt5), clang version 7.0.1 12 alt:sisyphus : Ok x86_64-alt-linux-gcc (GCC) 9.2.1 20190827 (ALT Sisyphus 9.2.1-alt2), clang version 7.0.1 13 amazonlinux:1 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2), clang version 3.6.2 (tags/RELEASE_362/final) 14 amazonlinux:2 : Ok gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6), clang version 7.0.1 (Amazon Linux 2 7.0.1-1.amzn2.0.2) 15 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 16 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 17 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 18 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23) 19 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39) 20 centos:8 : Ok gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4), clang version 8.0.1 (Red Hat 8.0.1-1.module_el8.1.0+215+a01033fb) 21 clearlinux:latest : Ok gcc (Clear Linux OS for Intel Architecture) 9.2.1 20200214 gcc_9_2_0_release-615-g7866f9ebf1, clang version 9.0.1 22 debian:8 : Ok gcc (Debian 4.9.2-10+deb8u2) 4.9.2, Debian clang version 3.5.0-10 (tags/RELEASE_350/final) (based on LLVM 3.5.0) 23 debian:9 : Ok gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, clang version 3.8.1-24 (tags/RELEASE_381/final) 24 debian:10 : Ok gcc (Debian 8.3.0-6) 8.3.0, clang version 7.0.1-8 (tags/RELEASE_701/final) 25 debian:experimental : Ok gcc (Debian 9.2.1-28) 9.2.1 20200203, clang version 8.0.1-7 (tags/RELEASE_801/final) 26 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 8.3.0-19) 8.3.0 27 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 8.3.0-19) 8.3.0 28 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 9.2.1-24) 9.2.1 20200117 29 debian:experimental-x-mipsel : Ok mipsel-linux-gnu-gcc (Debian 9.2.1-8) 9.2.1 20190909 30 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7) 31 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6), clang version 3.5.0 (tags/RELEASE_350/final) 32 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6), clang version 3.7.0 (tags/RELEASE_370/final) 33 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1), clang version 3.8.1 (tags/RELEASE_381/final) 34 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 35 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1), clang version 3.9.1 (tags/RELEASE_391/final) 36 fedora:26 : Ok gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2), clang version 4.0.1 (tags/RELEASE_401/final) 37 fedora:27 : Ok gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6), clang version 5.0.2 (tags/RELEASE_502/final) 38 fedora:28 : Ok gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2), clang version 6.0.1 (tags/RELEASE_601/final) 39 fedora:29 : Ok gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2), clang version 7.0.1 (Fedora 7.0.1-6.fc29) 40 fedora:30 : Ok gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1), clang version 8.0.0 (Fedora 8.0.0-3.fc30) 41 fedora:30-x-ARC-glibc : Ok arc-linux-gcc (ARC HS GNU/Linux glibc toolchain 2019.03-rc1) 8.3.1 20190225 42 fedora:30-x-ARC-uClibc : Ok arc-linux-gcc (ARCv2 ISA Linux uClibc toolchain 2019.03-rc1) 8.3.1 20190225 43 fedora:31 : Ok gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1), clang version 9.0.1 (Fedora 9.0.1-2.fc31) 44 fedora:32 : Ok gcc (GCC) 10.0.1 20200216 (Red Hat 10.0.1-0.8), clang version 10.0.0 (Fedora 10.0.0-0.1.rc2.fc32) 45 fedora:rawhide : Ok gcc (GCC) 10.0.1 20200216 (Red Hat 10.0.1-0.8), clang version 10.0.0 (Fedora 10.0.0-0.3.rc2.fc33) 46 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 9.2.0-r2 p3) 9.2.0 47 mageia:5 : Ok gcc (GCC) 4.9.2, clang version 3.5.2 (tags/RELEASE_352/final) 48 mageia:6 : Ok gcc (Mageia 5.5.0-1.mga6) 5.5.0, clang version 3.9.1 (tags/RELEASE_391/final) 49 mageia:7 : Ok gcc (Mageia 8.3.1-0.20190524.1.mga7) 8.3.1 20190524, clang version 8.0.0 (Mageia 8.0.0-1.mga7) 50 manjaro:latest : Ok gcc (GCC) 9.2.0, clang version 9.0.0 (tags/RELEASE_900/final) 51 openmandriva:cooker : Ok gcc (GCC) 10.0.0 20200216 (OpenMandriva), clang version 10.0.0 52 opensuse:15.0 : Ok gcc (SUSE Linux) 7.4.1 20190424 [gcc-7-branch revision 270538], clang version 5.0.1 (tags/RELEASE_501/final 312548) 53 opensuse:15.1 : Ok gcc (SUSE Linux) 7.5.0, clang version 7.0.1 (tags/RELEASE_701/final 349238) 54 opensuse:15.2 : Ok gcc (SUSE Linux) 7.5.0, clang version 7.0.1 (tags/RELEASE_701/final 349238) 55 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5, clang version 3.8.0 (tags/RELEASE_380/final 262553) 56 opensuse:tumbleweed : Ok gcc (SUSE Linux) 9.2.1 20200128 [revision 83f65674e78d97d27537361de1a9d74067ff228d], clang version 9.0.1 57 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23.0.1) 58 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39.0.3) 59 oraclelinux:8 : Ok gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4.5.0.5), clang version 8.0.1 (Red Hat 8.0.1-1.0.1.module+el8.1.0+5428+345cee14) 60 ubuntu:12.04 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0) 61 ubuntu:14.04 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4 62 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609, clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) 63 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 64 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 65 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 66 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 67 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 68 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 69 ubuntu:18.04 : Ok gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) 70 ubuntu:18.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0 71 ubuntu:18.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0 72 ubuntu:18.04-x-m68k : Ok m68k-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 73 ubuntu:18.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 74 ubuntu:18.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 75 ubuntu:18.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 76 ubuntu:18.04-x-riscv64 : Ok riscv64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 77 ubuntu:18.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 78 ubuntu:18.04-x-sh4 : Ok sh4-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 79 ubuntu:18.04-x-sparc64 : Ok sparc64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 80 ubuntu:18.10 : Ok gcc (Ubuntu 8.3.0-6ubuntu1~18.10.1) 8.3.0, clang version 7.0.0-3 (tags/RELEASE_700/final) 81 ubuntu:19.04 : Ok gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0, clang version 8.0.0-3 (tags/RELEASE_800/final) 82 ubuntu:19.04-x-alpha : Ok alpha-linux-gnu-gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0 83 ubuntu:19.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 8.3.0-6ubuntu1) 8.3.0 84 ubuntu:19.04-x-hppa : Ok hppa-linux-gnu-gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0 85 ubuntu:19.10 : FAIL gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008, clang version 9.0.0-2 (tags/RELEASE_900/final) #
# uname -a
Linux five 5.5.5-200.fc31.x86_64 #1 SMP Wed Feb 19 23:28:07 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
# git log --oneline -1
f787feff69c4 perf block-info: Support color ops to print block percents in color
# perf version --build-options
perf version 5.6.rc4.gf787feff69c4
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
glibc: [ on ] # HAVE_GLIBC_SUPPORT
gtk2: [ on ] # HAVE_GTK2_SUPPORT
syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
libbfd: [ on ] # HAVE_LIBBFD_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
aio: [ on ] # HAVE_AIO_SUPPORT
zstd: [ on ] # HAVE_ZSTD_SUPPORT
# perf test
1: vmlinux symtab matches kallsyms : Ok
2: Detect openat syscall event : Ok
3: Detect openat syscall event on all cpus : Ok
4: Read samples using the mmap interface : Ok
5: Test data source output : Ok
6: Parse event definition strings : Ok
7: Simple expression parser : Ok
8: PERF_RECORD_* events & perf_sample fields : Ok
9: Parse perf pmu format : Ok
10: DSO data read : Ok
11: DSO data cache : Ok
12: DSO data reopen : Ok
13: Roundtrip evsel->name : Ok
14: Parse sched tracepoints fields : Ok
15: syscalls:sys_enter_openat event fields : Ok
16: Setup struct perf_event_attr : Ok
17: Match and link multiple hists : Ok
18: 'import perf' in python : Ok
19: Breakpoint overflow signal handler : Ok
20: Breakpoint overflow sampling : Ok
21: Breakpoint accounting : Ok
22: Watchpoint :
22.1: Read Only Watchpoint : Skip
22.2: Write Only Watchpoint : Ok
22.3: Read / Write Watchpoint : Ok
22.4: Modify Watchpoint : Ok
23: Number of exit events of a simple workload : Ok
24: Software clock events period values : Ok
25: Object code reading : Ok
26: Sample parsing : Ok
27: Use a dummy software event to keep tracking : Ok
28: Parse with no sample_id_all bit set : Ok
29: Filter hist entries : Ok
30: Lookup mmap thread : Ok
31: Share thread maps : Ok
32: Sort output of hist entries : Ok
33: Cumulate child hist entries : Ok
34: Track with sched_switch : Ok
35: Filter fds with revents mask in a fdarray : Ok
36: Add fd to a fdarray, making it autogrow : Ok
37: kmod_path__parse : Ok
38: Thread map : Ok
39: LLVM search and compile :
39.1: Basic BPF llvm compile : Ok
39.2: kbuild searching : Ok
39.3: Compile source for BPF prologue generation : Ok
39.4: Compile source for BPF relocation : Ok
40: Session topology : Ok
41: BPF filter :
41.1: Basic BPF filtering : Ok
41.2: BPF pinning : Ok
41.3: BPF prologue generation : Ok
41.4: BPF relocation checker : Ok
42: Synthesize thread map : Ok
43: Remove thread map : Ok
44: Synthesize cpu map : Ok
45: Synthesize stat config : Ok
46: Synthesize stat : Ok
47: Synthesize stat round : Ok
48: Synthesize attr update : Ok
49: Event times : Ok
50: Read backward ring buffer : Ok
51: Print cpu map : Ok
52: Merge cpu map : Ok
53: Probe SDT events : Ok
54: is_printable_array : Ok
55: Print bitmap : Ok
56: perf hooks : Ok
57: builtin clang support : Skip (not compiled in)
58: unit_number__scnprintf : Ok
59: mem2node : Ok
60: time utils : Ok
61: Test jit_write_elf : Ok
62: maps__merge_in : Ok
63: x86 rdpmc : Ok
64: Convert perf time to TSC : Ok
65: DWARF unwind : Ok
66: x86 instruction decoder - new instructions : Ok
67: Intel PT packet decoder : Ok
68: x86 bp modify : Ok
69: probe libc's inet_pton & backtrace it with ping : Ok
70: Use vfs_getname probe to get syscall args filenames : Ok
71: Check open filename arg using perf trace + vfs_getname: Ok
72: Zstd perf.data compression/decompression : Ok
73: Add vfs_getname probe to get syscall args filenames : Ok $ git log --oneline -1
f787feff69c4 (HEAD -> perf/core, quaco/perf/core) perf block-info: Support color ops to print block percents in color
$ make -C tools/perf build-test
make: Entering directory '/home/acme/git/perf/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_no_libbionic_O: make NO_LIBBIONIC=1
make_install_prefix_O: make install prefix=/tmp/krava
make_no_libnuma_O: make NO_LIBNUMA=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 NO_LIBZSTD=1 NO_LIBCAP=1
make_install_bin_O: make install-bin
make_with_clangllvm_O: make LIBCLANGLLVM=1
make_no_backtrace_O: make NO_BACKTRACE=1
make_doc_O: make doc
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_no_libelf_O: make NO_LIBELF=1
make_perf_o_O: make perf.o
make_no_auxtrace_O: make NO_AUXTRACE=1
make_no_gtk2_O: make NO_GTK2=1
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_tags_O: make tags
make_no_libunwind_O: make NO_LIBUNWIND=1
make_no_slang_O: make NO_SLANG=1
make_no_libaudit_O: make NO_LIBAUDIT=1
make_pure_O: make
make_clean_all_O: make clean all
make_no_libbpf_O: make NO_LIBBPF=1
make_static_O: make LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1
make_no_libperl_O: make NO_LIBPERL=1
make_util_map_o_O: make util/map.o
make_with_babeltrace_O: make LIBBABELTRACE=1
make_help_O: make help
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_no_libpython_O: make NO_LIBPYTHON=1
make_no_newt_O: make NO_NEWT=1
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_install_O: make install
make_no_demangle_O: make NO_DEMANGLE=1
make_debug_O: make DEBUG=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$Arnaldo Carvalho de Melo
maintainerPATCH 1/19 tools lib api fs: Move cgroupsfs_find_mountpoint()
From: Namhyung Kim <[email protected]>
Move it from tools/perf/util/cgroup.c as it can be used by other places. Note that cgroup filesystem is different from others since it's usually mounted separately (in v1) for each subsystem.
I just copied the code with a little modification to pass a name of subsystem.
--- tools/lib/api/fs/Build | 1 + tools/lib/api/fs/cgroup.c | 67 +++++++++++++++++++++++++++++++++++++++ tools/lib/api/fs/fs.h | 2 ++ tools/perf/util/cgroup.c | 63 ++---------------------------------- 4 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 tools/lib/api/fs/cgroup.c
tools/lib/api/fs/Build +1 -0
@@ -1,2 +1,3 @@ libapi-y += fs.o libapi-y += tracing_path.o +libapi-y += cgroup.o
tools/lib/api/fs/cgroup.c new file +67 -0
67 lines not on this page · raw message
tools/lib/api/fs/fs.h +2 -0
@@ -28,6 +28,8 @@ FS(bpf_fs)#undef FS +int cgroupfs_find_mountpoint (char *buf,size_t maxlen,const char *subsys); +int filename__read_int (const char *filename,int *value);int filename__read_ull (const char *filename,unsigned long long *value);int filename__read_xll (const char *filename,unsigned long long *value);
tools/perf/util/cgroup.c +2 -61
84 lines not on this page · raw message
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 2/19 perf stat: Show percore counts in per CPU output
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
We have supported the event modifier "percore" which sums up the event counts for all hardware threads in a core and show the counts per core.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A -- sleep 1
Performance counter stats for 'system wide':
S0-D0-C0 395,072 cpu/event=cpu-cycles,percore/ S0-D0-C1 851,248 cpu/event=cpu-cycles,percore/ S0-D0-C2 954,226 cpu/event=cpu-cycles,percore/ S0-D0-C3 1,233,659 cpu/event=cpu-cycles,percore/
This patch provides a new option "--percore-show-thread". It is used with event modifier "percore" together to sum up the event counts for all hardware threads in a core but show the counts per hardware thread.
This is essentially a replacement for the any bit (which is gone in Icelake). Per core counts are useful for some formulas, e.g. CoreIPC. The original percore version was inconvenient to post process. This variant matches the output of the any bit.
With this patch, for example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -- sleep 1
Performance counter stats for 'system wide':
CPU0 2,453,061 cpu/event=cpu-cycles,percore/ CPU1 1,823,921 cpu/event=cpu-cycles,percore/ CPU2 1,383,166 cpu/event=cpu-cycles,percore/ CPU3 1,102,652 cpu/event=cpu-cycles,percore/ CPU4 2,453,061 cpu/event=cpu-cycles,percore/ CPU5 1,823,921 cpu/event=cpu-cycles,percore/ CPU6 1,383,166 cpu/event=cpu-cycles,percore/ CPU7 1,102,652 cpu/event=cpu-cycles,percore/
We can see counts are duplicated in CPU pairs (CPU0/CPU4, CPU1/CPU5, CPU2/CPU6, CPU3/CPU7).
The interval mode also works. For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -I 1000
# time CPU counts unit events
1.000425421 CPU0 925,032 cpu/event=cpu-cycles,percore/
1.000425421 CPU1 430,202 cpu/event=cpu-cycles,percore/
1.000425421 CPU2 436,843 cpu/event=cpu-cycles,percore/
1.000425421 CPU3 1,192,504 cpu/event=cpu-cycles,percore/
1.000425421 CPU4 925,032 cpu/event=cpu-cycles,percore/
1.000425421 CPU5 430,202 cpu/event=cpu-cycles,percore/
1.000425421 CPU6 436,843 cpu/event=cpu-cycles,percore/
1.000425421 CPU7 1,192,504 cpu/event=cpu-cycles,percore/If we offline CPU5, the result is:
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -- sleep 1
Performance counter stats for 'system wide':
CPU0 2,752,148 cpu/event=cpu-cycles,percore/ CPU1 1,009,312 cpu/event=cpu-cycles,percore/ CPU2 2,784,072 cpu/event=cpu-cycles,percore/ CPU3 2,427,922 cpu/event=cpu-cycles,percore/ CPU4 2,752,148 cpu/event=cpu-cycles,percore/ CPU6 2,784,072 cpu/event=cpu-cycles,percore/ CPU7 2,427,922 cpu/event=cpu-cycles,percore/
1.001416041 seconds time elapsed
v4:
---
Ravi Bangoria reports an issue in v3. Once we offline a CPU, the output is not correct. The issue is we should use the cpu idx in print_percore_thread rather than using the cpu value.
v3:
---
1. Fix the interval mode output error
2. Use cpu value (not cpu index) in config->aggr_get_id().
3. Refine the code according to Jiri's comments.
v2:
---
Add the explanation in change log. This is essentially a replacement for the any bit. No code change.
--- tools/perf/Documentation/perf-stat.txt | 9 +++++++ tools/perf/builtin-stat.c | 4 ++++ tools/perf/util/stat-display.c | 33 ++++++++++++++++++++++---- tools/perf/util/stat.h | 1 + 4 files changed, 42 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-stat.txt +9 -0
@@ -334,6 +334,15 @@ Configure all used events to run in kernel space. --all-user:: Configure all used events to run in user space. +--percore-show-thread:: +The event modifier "percore" has supported to sum up the event counts +for all hardware threads in a core and show the counts per core. + +This option with event modifier "percore" enabled also sums up the event +counts for all hardware threads in a core but show the sum counts per +hardware thread. This is essentially a replacement for the any bit and +convenient for post processing. + EXAMPLES --------
tools/perf/builtin-stat.c +4 -0
@@ -929,6 +929,10 @@ static struct option stat_options[] = {OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user,"Configure all used events to run in user space." ,PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN (0 ,"percore-show-thread" , &stat_config.percore_show_thread, +"Use with 'percore' event qualifier to show the event " +"counts of one hardware thread by sum up total hardware " +"threads of same physical core" ), OPT_END() };
tools/perf/util/stat-display.c +28 -5
@@ -110,7 +110,7 @@ static void aggr_printout(struct perf_stat_config *config, config->csv_sep);break ;case AGGR_NONE : -if (evsel->percore) { +if (evsel->percore && !config->percore_show_thread) { fprintf(config->output, "S%d-D%d-C%*d%s", cpu_map__id_to_socket(id), cpu_map__id_to_die(id),
@@ -628,7 +628,7 @@ static void aggr_cb(struct perf_stat_config *config,static void print_counter_aggrdata (struct perf_stat_config *config,struct evsel *counter,int s,char *prefix,bool metric_only, -bool *first) +bool *first,int cpu) {struct aggr_data ad;FILE *output = config->output;
@@ -654,7 +654,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config,fprintf (output,"%s" , prefix); uval = val * counter->scale; -printout (config, id, nr, counter, uval, prefix, +printout (config, cpu !=-1 ? cpu : id, nr, counter, uval, prefix, run, ena,1.0 , &rt_stat);if (!metric_only)fputc ('\n' , output);
@@ -687,7 +687,7 @@ static void print_aggr(struct perf_stat_config *config,evlist__for_each_entry (evlist, counter) {print_counter_aggrdata (config, counter, s, prefix, metric_only, - &first); + &first,-1 ); }if (metric_only)fputc ('\n' , output);
@@ -1146,6 +1146,26 @@ static void print_footer(struct perf_stat_config *config) "the same PMU. Try reorganizing the group.\n"); } +static void print_percore_thread (struct perf_stat_config *config, +struct evsel *counter,char *prefix) +{ +int s, s2, id; +bool first = true; + +for (int i =0 ; i <perf_evsel__nr_cpus (counter); i++) { + s2 = config->aggr_get_id (config,evsel__cpus (counter), i); +for (s =0 ; s < config->aggr_map->nr; s++) { + id = config->aggr_map->map[s]; +if (s2 == id) +break ; + } + +print_counter_aggrdata (config, counter, s, + prefix, false, + &first, i); + } +} +static void print_percore (struct perf_stat_config *config,struct evsel *counter,char *prefix) {
@@ -1157,13 +1177,16 @@ static void print_percore(struct perf_stat_config *config,if (!(config->aggr_map || config->aggr_get_id))return ; +if (config->percore_show_thread) +return print_percore_thread (config, counter, prefix); +for (s =0 ; s < config->aggr_map->nr; s++) {if (prefix && metric_only)fprintf (output,"%s" , prefix);print_counter_aggrdata (config, counter, s, prefix, metric_only, - &first); + &first,-1 ); }if (metric_only)
tools/perf/util/stat.h +1 -0
@@ -109,6 +109,7 @@ struct perf_stat_config {bool walltime_run_table;bool all_kernel;bool all_user; +bool percore_show_thread;FILE *output;unsigned int interval;unsigned int timeout;
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 3/19 perf llvm: Add debug hint message about missing kernel-devel package
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To help in debugging, add this extra message:
detect_kbuild_dir: Couldn't find "/lib/modules/5.4.20-200.fc31.x86_64/build/include/generated/autoconf.h", missing kernel-devel package?.
--- tools/perf/util/llvm-utils.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/llvm-utils.c +2 -0
@@ -265,6 +265,8 @@ static int detect_kbuild_dir(char **kbuild_dir)return -ENOMEM ;return 0 ; } +pr_debug ("%s: Couldn't find \"%s\", missing kernel-devel package?.\n" , + __func__, autoconf_path);free (autoconf_path);return -ENOENT ; }
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 4/19 perf annotate: Get rid of annotation->nr_jumps
In reply to Arnaldo Carvalho de MeloFrom: Ravi Bangoria <[email protected]>
The 'nr_jumps' field in 'struct annotation' is not used since it's inception in commit 2402e4a936a0 ("perf annotate browser: Show 'jumpy' functions"). Get rid of it.
--- tools/perf/util/annotate.c | 2 -- tools/perf/util/annotate.h | 1 - 2 files changed, 3 deletions(-)
tools/perf/util/annotate.c +0 -2
@@ -2611,8 +2611,6 @@ void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym)if (++al->jump_sources > notes->max_jump_sources) notes->max_jump_sources = al->jump_sources; - - ++notes->nr_jumps; } }
tools/perf/util/annotate.h +0 -1
@@ -279,7 +279,6 @@ struct annotation {struct annotation_options *options;struct annotation_line **offsets;int nr_events; -int nr_jumps;int max_jump_sources;int nr_entries;int nr_asm_entries;
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 5/19 libperf: Add counting example
In reply to Arnaldo Carvalho de MeloFrom: Michael Petlan <[email protected]>
Current libperf man pages mention file counting.c "coming with libperf package", however, the file is missing. Add the file then.
LPU-Reference: [email protected]
--- .../perf/Documentation/examples/counting.c | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tools/lib/perf/Documentation/examples/counting.c
tools/lib/perf/Documentation/examples/counting.c new file +83 -0
@@ -0,0 +1,83 @@ +#include <linux/perf_event.h> +#include <perf/evlist.h> +#include <perf/evsel.h> +#include <perf/cpumap.h> +#include <perf/threadmap.h> +#include <perf/mmap.h> +#include <perf/core.h> +#include <perf/event.h> +#include <stdio.h> +#include <unistd.h> + +static int libperf_print (enum libperf_print_level level, +const char *fmt,va_list ap) +{ +return vfprintf (stderr, fmt, ap); +} + +int main (int argc,char **argv) +{ +int count =100000 , err =0 ; +struct perf_evlist *evlist; +struct perf_evsel *evsel; +struct perf_thread_map *threads; +struct perf_counts_values counts; + +struct perf_event_attr attr1 = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_CPU_CLOCK , + .read_format =PERF_FORMAT_TOTAL_TIME_ENABLED |PERF_FORMAT_TOTAL_TIME_RUNNING , + .disabled =1 , + }; +struct perf_event_attr attr2 = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_TASK_CLOCK , + .read_format =PERF_FORMAT_TOTAL_TIME_ENABLED |PERF_FORMAT_TOTAL_TIME_RUNNING , + .disabled =1 , + }; + +libperf_init (libperf_print); + threads =perf_thread_map__new_dummy (); +if (!threads) { +fprintf (stderr,"failed to create threads\n" ); +return -1 ; + } +perf_thread_map__set_pid (threads,0 ,0 ); + evlist =perf_evlist__new (); +if (!evlist) { +fprintf (stderr,"failed to create evlist\n" ); + goto out_threads; + } + evsel =perf_evsel__new (&attr1); +if (!evsel) { +fprintf (stderr,"failed to create evsel1\n" ); + goto out_evlist; + } +perf_evlist__add (evlist, evsel); + evsel =perf_evsel__new (&attr2); +if (!evsel) { +fprintf (stderr,"failed to create evsel2\n" ); + goto out_evlist; + } +perf_evlist__add (evlist, evsel); +perf_evlist__set_maps (evlist,NULL , threads); + err =perf_evlist__open (evlist); +if (err) { +fprintf (stderr,"failed to open evsel\n" ); + goto out_evlist; + } +perf_evlist__enable (evlist); +while (count--); +perf_evlist__disable (evlist); +perf_evlist__for_each_evsel (evlist, evsel) { +perf_evsel__read (evsel,0 ,0 , &counts); +fprintf (stdout,"count %llu, enabled %llu, run %llu\n" , + counts.val, counts.ena, counts.run); + } +perf_evlist__close (evlist); +out_evlist: +perf_evlist__delete (evlist); +out_threads: +perf_thread_map__put (threads); +return err; +}
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 6/19 tools lib traceevent: Remove extra '\n' in print_event_time()
In reply to Arnaldo Carvalho de MeloFrom: "Steven Rostedt (VMware)" <[email protected]>
If the precision of print_event_time() is zero or greater than the timestamp, it uses a different format. But that format had an extra new line at the end, and caused the output to not look right:
cpus=2
sleep-3946 [001]111264306005
: function: inotify_inode_queue_event
sleep-3946 [001]111264307158
: function: __fsnotify_parent
sleep-3946 [001]111264307637
: function: inotify_dentry_parent_queue_event
sleep-3946 [001]111264307989
: function: fsnotify
sleep-3946 [001]111264308401: function: audit_syscall_exit
--- tools/lib/traceevent/event-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +1 -1
@@ -5541,7 +5541,7 @@ static void print_event_time(struct tep_handle *tep, struct trace_seq *s,if (p10 >1 && p10 < time)trace_seq_printf (s,"%5llu.%0*llu" , time / p10, prec, time % p10);else -trace_seq_printf (s,"%12llu\n" , time); +trace_seq_printf (s,"%12llu" , time); }struct print_event_type {
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 7/19 tools headers UAPI: Update tools's copy of linux/perf_event.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To get the changes in:
bbfd5e4fab63 ("perf/core: Add new branch sample type for HW index of raw branch records")
This silences this perf tools build warning:
Warning: Kernel ABI header at 'tools/include/uapi/linux/perf_event.h' differs from latest version at 'include/uapi/linux/perf_event.h' diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h
This update is a prerequisite to adding support for the HW index of raw branch records.
--- tools/include/uapi/linux/perf_event.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/include/uapi/linux/perf_event.h +7 -1
@@ -181,6 +181,8 @@ enum perf_branch_sample_type_shift {PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT =16 ,/* save branch type */ +PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT =17 ,/* save low level index of raw branch records */ + PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ };
@@ -208,6 +210,8 @@ enum perf_branch_sample_type {PERF_SAMPLE_BRANCH_TYPE_SAVE =1U <<PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT , +PERF_SAMPLE_BRANCH_HW_INDEX =1U <<PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT , + PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, };
@@ -853,7 +857,9 @@ enum perf_event_type {* char data[size];}&& PERF_SAMPLE_RAW * * { u64 nr; -* { u64 from, to, flags } lbr[nr];} && PERF_SAMPLE_BRANCH_STACK +* { u64 hw_idx; } && PERF_SAMPLE_BRANCH_HW_INDEX +* { u64 from, to, flags } lbr[nr]; +* } && PERF_SAMPLE_BRANCH_STACK * * { u64 abi; # enum perf_sample_regs_abi * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 8/19 perf tools: Add hw_idx in struct branch_stack
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The low level index of raw branch records for the most recent branch can be recorded in a sample with PERF_SAMPLE_BRANCH_HW_INDEX branch_sample_type. Extend struct branch_stack to support it.
However, if the PERF_SAMPLE_BRANCH_HW_INDEX is not applied, only nr and entries[] will be output by kernel. The pointer of entries[] could be wrong, since the output format is different with new struct branch_stack. Add a variable no_hw_idx in struct perf_sample to indicate whether the hw_idx is output. Add get_branch_entry() to return corresponding pointer of entries[0].
To make dummy branch sample consistent as new branch sample, add hw_idx in struct dummy_branch_stack for cs-etm and intel-pt.
Apply the new struct branch_stack for synthetic events as well.
Extend test case sample-parsing to support new struct branch_stack.
Committer notes:
Renamed get_branch_entries() to perf_sample__branch_entries() to have proper namespacing and pave the way for this to be moved to libperf, eventually.
Add 'static' to that inline as it is in a header.
Add 'hw_idx' to 'struct dummy_branch_stack' in cs-etm.c to fix the build on arm64.
--- tools/perf/builtin-script.c | 70 ++++++++++--------- tools/perf/tests/sample-parsing.c | 7 +- tools/perf/util/branch.h | 22 ++++++ tools/perf/util/cs-etm.c | 2 + tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 5 ++ tools/perf/util/evsel.h | 5 ++ tools/perf/util/hist.c | 3 +- tools/perf/util/intel-pt.c | 2 + tools/perf/util/machine.c | 35 +++++----- .../scripting-engines/trace-event-python.c | 30 ++++---- tools/perf/util/session.c | 8 ++- tools/perf/util/synthetic-events.c | 6 +- 13 files changed, 125 insertions(+), 71 deletions(-)
tools/perf/builtin-script.c +37 -33
@@ -735,6 +735,7 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample, struct perf_event_attr *attr, FILE *fp) { struct branch_stack *br = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);struct addr_location alf, alt;u64 i, from, to;int printed =0 ;
@@ -743,8 +744,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,return 0 ;for (i =0 ; i < br->nr; i++) { - from = br->entries[i].from; - to = br->entries[i].to; + from = entries[i].from; + to = entries[i].to;if (PRINT_FIELD (DSO )) {memset (&alf,0 ,sizeof (alf));
@@ -768,10 +769,10 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample, } printed +=fprintf (fp,"/%c/%c/%c/%d " , -mispred_str ( br->entries + i), - br->entries[i].flags.in_tx?'X' :'-' , - br->entries[i].flags.abort?'A' :'-' , - br->entries[i].flags.cycles); +mispred_str (entries + i), + entries[i].flags.in_tx ?'X' :'-' , + entries[i].flags.abort ?'A' :'-' , + entries[i].flags.cycles); }return printed;
@@ -782,6 +783,7 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample, struct perf_event_attr *attr, FILE *fp) { struct branch_stack *br = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);struct addr_location alf, alt;u64 i, from, to;int printed =0 ;
@@ -793,8 +795,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,memset (&alf,0 ,sizeof (alf));memset (&alt,0 ,sizeof (alt)); - from = br->entries[i].from; - to = br->entries[i].to; + from = entries[i].from; + to = entries[i].to;thread__find_symbol_fb (thread, sample->cpumode, from, &alf);thread__find_symbol_fb (thread, sample->cpumode, to, &alt);
@@ -813,10 +815,10 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample, printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"/%c/%c/%c/%d " , -mispred_str ( br->entries + i), - br->entries[i].flags.in_tx?'X' :'-' , - br->entries[i].flags.abort?'A' :'-' , - br->entries[i].flags.cycles); +mispred_str (entries + i), + entries[i].flags.in_tx ?'X' :'-' , + entries[i].flags.abort ?'A' :'-' , + entries[i].flags.cycles); }return printed;
@@ -827,6 +829,7 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample, struct perf_event_attr *attr, FILE *fp) { struct branch_stack *br = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);struct addr_location alf, alt;u64 i, from, to;int printed =0 ;
@@ -838,8 +841,8 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,memset (&alf,0 ,sizeof (alf));memset (&alt,0 ,sizeof (alt)); - from = br->entries[i].from; - to = br->entries[i].to; + from = entries[i].from; + to = entries[i].to;if (thread__find_map_fb (thread, sample->cpumode, from, &alf) && !alf.map->dso->adjust_symbols)
@@ -862,10 +865,10 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample, printed +=fprintf (fp,")" ); } printed +=fprintf (fp,"/%c/%c/%c/%d " , -mispred_str (br->entries + i), - br->entries[i].flags.in_tx ?'X' :'-' , - br->entries[i].flags.abort ?'A' :'-' , - br->entries[i].flags.cycles); +mispred_str (entries + i), + entries[i].flags.in_tx ?'X' :'-' , + entries[i].flags.abort ?'A' :'-' , + entries[i].flags.cycles); }return printed;
@@ -1053,6 +1056,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, struct machine *machine, FILE *fp) { struct branch_stack *br = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);u64 start, end;int i, insn, len, nr, ilen, printed =0 ;struct perf_insn x;
@@ -1073,31 +1077,31 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed +=fprintf (fp,"%c" ,'\n' );/* Handle first from jump, of which we don't know the entry. */ - len =grab_bb (buffer, br->entries[nr-1 ].from, - br->entries[nr-1 ].from, + len =grab_bb (buffer, entries[nr-1 ].from, + entries[nr-1 ].from, machine, thread, &x.is64bit, &x.cpumode, false);if (len >0 ) { - printed +=ip__fprintf_sym (br->entries[nr -1 ].from, thread, + printed +=ip__fprintf_sym (entries[nr -1 ].from, thread, x.cpumode, x.cpu, &lastsym, attr, fp); - printed +=ip__fprintf_jump (br->entries[nr -1 ].from, &br->entries[nr -1 ], + printed +=ip__fprintf_jump (entries[nr -1 ].from, &entries[nr -1 ], &x, buffer, len,0 , fp, &total_cycles);if (PRINT_FIELD (SRCCODE )) - printed +=print_srccode (thread, x.cpumode, br->entries[nr -1 ].from); + printed +=print_srccode (thread, x.cpumode, entries[nr -1 ].from); }/* Print all blocks */ for (i = nr -2 ; i >=0 ; i--) { -if (br->entries[i].from || br->entries[i].to) +if (entries[i].from || entries[i].to)pr_debug ("%d: %" PRIx64"-%" PRIx64"\n" , i, - br->entries[i].from, - br->entries[i].to); - start = br->entries[i +1 ].to; - end = br->entries[i].from; + entries[i].from, + entries[i].to); + start = entries[i +1 ].to; + end = entries[i].from; len =grab_bb (buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, false);/* Patch up missing kernel transfers due to ring filters */ if (len == -ENXIO && i >0 ) { - end = br->entries[--i].from; + end = entries[--i].from;pr_debug ("\tpatching up to %" PRIx64"-%" PRIx64"\n" , start, end); len =grab_bb (buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, false); }
@@ -1110,7 +1114,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, printed +=ip__fprintf_sym (ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);if (ip == end) { - printed +=ip__fprintf_jump (ip, &br->entries[i], &x, buffer + off, len - off, ++insn, fp, + printed +=ip__fprintf_jump (ip, &entries[i], &x, buffer + off, len - off, ++insn, fp, &total_cycles);if (PRINT_FIELD (SRCCODE )) printed +=print_srccode (thread, x.cpumode, ip);
@@ -1134,9 +1138,9 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,* Hit the branch? In this case we are already done, and the target * has not been executed yet. */ -if (br->entries[0 ].from == sample->ip) +if (entries[0 ].from == sample->ip) goto out; -if (br->entries[0 ].flags.abort) +if (entries[0 ].flags.abort) goto out;/*
@@ -1147,7 +1151,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,* between final branch and sample. When this happens just * continue walking after the last TO until we hit a branch. */ - start = br->entries[0 ].to; + start = entries[0 ].to; end = sample->ip;if (end < start) {/* Missing jump. Scan 128 bytes for the next branch */
tools/perf/tests/sample-parsing.c +6 -1
@@ -99,6 +99,7 @@ static bool samples_same(const struct perf_sample *s1,if (type &PERF_SAMPLE_BRANCH_STACK ) {COMP (branch_stack->nr); +COMP (branch_stack->hw_idx);for (i =0 ; i < s1->branch_stack->nr; i++)MCOMP (branch_stack->entries[i]); }
@@ -186,7 +187,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)u64 data[64 ]; } branch_stack = {/* 1 branch_entry */ - .data = {1, 211, 212, 213}, + .data = {1, -1ULL, 211, 212, 213}, };u64 regs[64 ];const u64 raw_data[] = {0x123456780a0b0c0dULL ,0x1102030405060708ULL };
@@ -208,6 +209,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) .transaction = 112, .raw_data = (void *)raw_data, .callchain = &callchain.callchain, + .no_hw_idx = false, .branch_stack = &branch_stack.branch_stack, .user_regs = { .abi = PERF_SAMPLE_REGS_ABI_64,
@@ -244,6 +246,9 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)if (sample_type &PERF_SAMPLE_REGS_INTR ) evsel.core.attr.sample_regs_intr = sample_regs; +if (sample_type &PERF_SAMPLE_BRANCH_STACK ) + evsel.core.attr.branch_sample_type |=PERF_SAMPLE_BRANCH_HW_INDEX ; +for (i =0 ; i <sizeof (regs); i++) *(i + (u8 *)regs) = i &0xfe ;
tools/perf/util/branch.h +22 -0
@@ -12,6 +12,7 @@#include <linux/stddef.h> #include <linux/perf_event.h> #include <linux/types.h> +#include "event.h" struct branch_flags {u64 mispred:1 ;
@@ -39,9 +40,30 @@ struct branch_entry {struct branch_stack {u64 nr; +u64 hw_idx;struct branch_entry entries[0 ]; }; +/* +* The hw_idx is only available when PERF_SAMPLE_BRANCH_HW_INDEX is applied. +* Otherwise, the output format of a sample with branch stack is +* struct branch_stack { +* u64 nr; +* struct branch_entry entries[0]; +* } +* Check whether the hw_idx is available, +* and return the corresponding pointer of entries[0]. +*/ +static inline struct branch_entry *perf_sample__branch_entries (struct perf_sample *sample) +{ +u64 *entry = (u64 *)sample->branch_stack; + + entry++; +if (sample->no_hw_idx) +return (struct branch_entry *)entry; +return (struct branch_entry *)(++entry); +} +struct branch_type_stat {bool branch_to;u64 counts[PERF_BR_MAX ];
tools/perf/util/cs-etm.c +2 -0
@@ -1172,6 +1172,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,union perf_event *event = tidq->event_buf;struct dummy_branch_stack {u64 nr; +u64 hw_idx;struct branch_entry entries; } dummy_bs;u64 ip;
@@ -1202,6 +1203,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,if (etm->synth_opts.last_branch) { dummy_bs = (struct dummy_branch_stack ){ .nr =1 , + .hw_idx =-1ULL , .entries = { .from = sample.ip, .to = sample.addr,
tools/perf/util/event.h +1 -0
@@ -139,6 +139,7 @@ struct perf_sample {u16 insn_len;u8 cpumode;u16 misc; +bool no_hw_idx;/* No hw_idx collected in branch_stack */ char insn[MAX_INSN ];void *raw_data;struct ip_callchain *callchain;
tools/perf/util/evsel.c +5 -0
@@ -2169,7 +2169,12 @@ int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event,if (data->branch_stack->nr > max_branch_nr)return -EFAULT ; + sz = data->branch_stack->nr *sizeof (struct branch_entry ); +if (perf_evsel__has_branch_hw_idx (evsel)) + sz +=sizeof (u64); +else + data->no_hw_idx = true;OVERFLOW_CHECK (array, sz, max_size); array = (void *)array + sz; }
tools/perf/util/evsel.h +5 -0
@@ -389,6 +389,11 @@ static inline bool perf_evsel__has_branch_callstack(const struct evsel *evsel)return evsel->core.attr.branch_sample_type &PERF_SAMPLE_BRANCH_CALL_STACK ; } +static inline bool perf_evsel__has_branch_hw_idx (const struct evsel *evsel) +{ +return evsel->core.attr.branch_sample_type &PERF_SAMPLE_BRANCH_HW_INDEX ; +} +static inline bool evsel__has_callchain (const struct evsel *evsel) {return (evsel->core.attr.sample_type &PERF_SAMPLE_CALLCHAIN ) !=0 ;
tools/perf/util/hist.c +2 -1
@@ -2584,9 +2584,10 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, u64 *total_cycles) {struct branch_info *bi; +struct branch_entry *entries =perf_sample__branch_entries (sample);/* If we have branch cycles always annotate them. */ -if (bs && bs->nr && bs->entries[0 ].flags.cycles) { +if (bs && bs->nr && entries[0 ].flags.cycles) {int i; bi =sample__resolve_bstack (sample, al);
tools/perf/util/intel-pt.c +2 -0
@@ -1295,6 +1295,7 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)struct perf_sample sample = { .ip =0 , };struct dummy_branch_stack {u64 nr; +u64 hw_idx;struct branch_entry entries; } dummy_bs;
@@ -1316,6 +1317,7 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)if (pt->synth_opts.last_branch && sort__mode ==SORT_MODE__BRANCH ) { dummy_bs = (struct dummy_branch_stack ){ .nr =1 , + .hw_idx =-1ULL , .entries = { .from = sample.ip, .to = sample.addr,
tools/perf/util/machine.c +18 -17
@@ -2081,15 +2081,16 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample, {unsigned int i;const struct branch_stack *bs = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);struct branch_info *bi =calloc (bs->nr,sizeof (struct branch_info ));if (!bi)return NULL ;for (i =0 ; i < bs->nr; i++) { -ip__resolve_ams (al->thread, &bi[i].to, bs->entries[i].to); -ip__resolve_ams (al->thread, &bi[i].from, bs->entries[i].from); - bi[i].flags = bs->entries[i].flags; +ip__resolve_ams (al->thread, &bi[i].to, entries[i].to); +ip__resolve_ams (al->thread, &bi[i].from, entries[i].from); + bi[i].flags = entries[i].flags; }return bi; }
@@ -2185,6 +2186,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread,/* LBR only affects the user callchain */ if (i != chain_nr) {struct branch_stack *lbr_stack = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);int lbr_nr = lbr_stack->nr, j, k;bool branch;struct branch_flags *flags;
@@ -2210,31 +2212,29 @@ static int resolve_lbr_callchain_sample(struct thread *thread, ip = chain->ips[j]; else if (j > i + 1) { k = j - i -2 ; - ip = lbr_stack->entries[k].from; + ip = entries[k].from; branch = true; - flags = &lbr_stack->entries[k].flags; + flags = &entries[k].flags; } else { - ip = lbr_stack->entries[0 ].to; + ip = entries[0 ].to; branch = true; - flags = &lbr_stack->entries[0 ].flags; - branch_from = - lbr_stack->entries[0 ].from; + flags = &entries[0 ].flags; + branch_from = entries[0 ].from; } }else {if (j < lbr_nr) { k = lbr_nr - j -1 ; - ip = lbr_stack->entries[k].from; + ip = entries[k].from; branch = true; - flags = &lbr_stack->entries[k].flags; + flags = &entries[k].flags; }else if (j > lbr_nr) ip = chain->ips[i +1 - (j - lbr_nr)];else { - ip = lbr_stack->entries[0 ].to; + ip = entries[0 ].to; branch = true; - flags = &lbr_stack->entries[0 ].flags; - branch_from = - lbr_stack->entries[0 ].from; + flags = &entries[0 ].flags; + branch_from = entries[0 ].from; } }
@@ -2281,6 +2281,7 @@ static int thread__resolve_callchain_sample(struct thread *thread, int max_stack) {struct branch_stack *branch = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);struct ip_callchain *chain = sample->callchain;int chain_nr =0 ;u8 cpumode =PERF_RECORD_MISC_USER ;
@@ -2328,7 +2329,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,for (i =0 ; i < nr; i++) {if (callchain_param.order ==ORDER_CALLEE ) { - be[i] = branch->entries[i]; + be[i] = entries[i];if (chain ==NULL )continue ;
@@ -2347,7 +2348,7 @@ static int thread__resolve_callchain_sample(struct thread *thread, be[i].from >= chain->ips[first_call] - 8) first_call++; }else - be[i] = branch->entries[branch->nr - i -1 ]; + be[i] = entries[branch->nr - i -1 ]; }memset (iter,0 ,sizeof (struct iterations ) * nr);
tools/perf/util/scripting-engines/trace-event-python.c +16 -14
@@ -464,6 +464,7 @@ static PyObject *python_process_brstack(struct perf_sample *sample, struct thread *thread) {struct branch_stack *br = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);PyObject *pylist;u64 i;
@@ -484,28 +485,28 @@ static PyObject *python_process_brstack(struct perf_sample *sample,Py_FatalError ("couldn't create Python dictionary" );pydict_set_item_string_decref (pyelem,"from" , -PyLong_FromUnsignedLongLong (br->entries[i].from)); +PyLong_FromUnsignedLongLong (entries[i].from));pydict_set_item_string_decref (pyelem,"to" , -PyLong_FromUnsignedLongLong (br->entries[i].to)); +PyLong_FromUnsignedLongLong (entries[i].to));pydict_set_item_string_decref (pyelem,"mispred" , -PyBool_FromLong (br->entries[i].flags.mispred)); +PyBool_FromLong (entries[i].flags.mispred));pydict_set_item_string_decref (pyelem,"predicted" , -PyBool_FromLong (br->entries[i].flags.predicted)); +PyBool_FromLong (entries[i].flags.predicted));pydict_set_item_string_decref (pyelem,"in_tx" , -PyBool_FromLong (br->entries[i].flags.in_tx)); +PyBool_FromLong (entries[i].flags.in_tx));pydict_set_item_string_decref (pyelem,"abort" , -PyBool_FromLong (br->entries[i].flags.abort)); +PyBool_FromLong (entries[i].flags.abort));pydict_set_item_string_decref (pyelem,"cycles" , -PyLong_FromUnsignedLongLong (br->entries[i].flags.cycles)); +PyLong_FromUnsignedLongLong (entries[i].flags.cycles));thread__find_map_fb (thread, sample->cpumode, - br->entries[i].from, &al); + entries[i].from, &al); dsoname =get_dsoname (al.map);pydict_set_item_string_decref (pyelem,"from_dsoname" ,_PyUnicode_FromString (dsoname));thread__find_map_fb (thread, sample->cpumode, - br->entries[i].to, &al); + entries[i].to, &al); dsoname =get_dsoname (al.map);pydict_set_item_string_decref (pyelem,"to_dsoname" ,_PyUnicode_FromString (dsoname));
@@ -561,6 +562,7 @@ static PyObject *python_process_brstacksym(struct perf_sample *sample, struct thread *thread) {struct branch_stack *br = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);PyObject *pylist;u64 i;char bf[512 ];
@@ -581,22 +583,22 @@ static PyObject *python_process_brstacksym(struct perf_sample *sample,Py_FatalError ("couldn't create Python dictionary" );thread__find_symbol_fb (thread, sample->cpumode, - br->entries[i].from, &al); + entries[i].from, &al);get_symoff (al.sym, &al, true, bf,sizeof (bf));pydict_set_item_string_decref (pyelem,"from" ,_PyUnicode_FromString (bf));thread__find_symbol_fb (thread, sample->cpumode, - br->entries[i].to, &al); + entries[i].to, &al);get_symoff (al.sym, &al, true, bf,sizeof (bf));pydict_set_item_string_decref (pyelem,"to" ,_PyUnicode_FromString (bf)); -get_br_mspred (&br->entries[i].flags, bf,sizeof (bf)); +get_br_mspred (&entries[i].flags, bf,sizeof (bf));pydict_set_item_string_decref (pyelem,"pred" ,_PyUnicode_FromString (bf)); -if (br->entries[i].flags.in_tx) { +if (entries[i].flags.in_tx) {pydict_set_item_string_decref (pyelem,"in_tx" ,_PyUnicode_FromString ("X" )); }else {
@@ -604,7 +606,7 @@ static PyObject *python_process_brstacksym(struct perf_sample *sample, _PyUnicode_FromString("-")); } -if (br->entries[i].flags.abort) { +if (entries[i].flags.abort) {pydict_set_item_string_decref (pyelem,"abort" ,_PyUnicode_FromString ("A" )); }else {
tools/perf/util/session.c +5 -3
@@ -1007,6 +1007,7 @@ static void callchain__lbr_callstack_printf(struct perf_sample *sample) {struct ip_callchain *callchain = sample->callchain;struct branch_stack *lbr_stack = sample->branch_stack; +struct branch_entry *entries =perf_sample__branch_entries (sample);u64 kernel_callchain_nr = callchain->nr;unsigned int i;
@@ -1043,10 +1044,10 @@ static void callchain__lbr_callstack_printf(struct perf_sample *sample) i, callchain->ips[i]);printf ("..... %2d: %016" PRIx64"\n" , - (int )(kernel_callchain_nr), lbr_stack->entries[0 ].to); + (int )(kernel_callchain_nr), entries[0 ].to);for (i =0 ; i < lbr_stack->nr; i++)printf ("..... %2d: %016" PRIx64"\n" , - (int )(i + kernel_callchain_nr +1 ), lbr_stack->entries[i].from); + (int )(i + kernel_callchain_nr +1 ), entries[i].from); } }
@@ -1068,6 +1069,7 @@ static void callchain__printf(struct evsel *evsel,static void branch_stack__printf (struct perf_sample *sample,bool callstack) { +struct branch_entry *entries =perf_sample__branch_entries (sample);uint64_t i; printf("%s: nr:%" PRIu64 "\n",
@@ -1075,7 +1077,7 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack) sample->branch_stack->nr);for (i =0 ; i < sample->branch_stack->nr; i++) { -struct branch_entry *e = &sample->branch_stack->entries[i]; +struct branch_entry *e = &entries[i];if (!callstack) { printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %s%s%s%s %x\n",
tools/perf/util/synthetic-events.c +4 -2
@@ -1183,7 +1183,8 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,if (type &PERF_SAMPLE_BRANCH_STACK ) { sz = sample->branch_stack->nr *sizeof (struct branch_entry ); - sz +=sizeof (u64); +/* nr, hw_idx */ + sz +=2 *sizeof (u64); result += sz; }
@@ -1344,7 +1345,8 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_foif (type &PERF_SAMPLE_BRANCH_STACK ) { sz = sample->branch_stack->nr *sizeof (struct branch_entry ); - sz +=sizeof (u64); +/* nr, hw_idx */ + sz +=2 *sizeof (u64);memcpy (array, sample->branch_stack, sz); array = (void *)array + sz; }
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 9/19 perf evsel: Support PERF_SAMPLE_BRANCH_HW_INDEX
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
A new branch sample type PERF_SAMPLE_BRANCH_HW_INDEX has been introduced in latest kernel.
Enable HW_INDEX by default in LBR call stack mode.
If kernel doesn't support the sample type, switching it off.
Add HW_INDEX in attr_fprintf as well. User can check whether the branch sample type is set via debug information or header.
Committer testing:
First collect some samples with LBR callchains, system wide, for a few seconds:
# perf record --call-graph lbr -a sleep 5 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.625 MB perf.data (224 samples) ] #
Now lets use 'perf evlist -v' to look at the branch_sample_type:
# perf evlist -v
cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: USER|CALL_STACK|NO_FLAGS|NO_CYCLES|HW_INDEX
#So the machine has the kernel feature, and it was correctly added to perf_event_attr.branch_sample_type, for the default 'cycles' event.
If we do it in another machine, where the kernel lacks the HW_INDEX feature, we get:
# perf record --call-graph lbr -a sleep 2s
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.690 MB perf.data (499 samples) ]
# perf evlist -v
cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: USER|CALL_STACK|NO_FLAGS|NO_CYCLES
#No HW_INDEX in attr.branch_sample_type.
--- tools/perf/util/evsel.c | 15 ++++++++++++--- tools/perf/util/evsel.h | 1 + tools/perf/util/perf_event_attr_fprintf.c | 1 + 3 files changed, 14 insertions(+), 3 deletions(-)
tools/perf/util/evsel.c +12 -3
@@ -712,7 +712,8 @@ static void __perf_evsel__config_callchain(struct evsel *evsel, attr->branch_sample_type =PERF_SAMPLE_BRANCH_USER |PERF_SAMPLE_BRANCH_CALL_STACK |PERF_SAMPLE_BRANCH_NO_CYCLES | -PERF_SAMPLE_BRANCH_NO_FLAGS ; +PERF_SAMPLE_BRANCH_NO_FLAGS | +PERF_SAMPLE_BRANCH_HW_INDEX ; } }else pr_warning("Cannot use LBR callstack with branch stack. "
@@ -763,7 +764,8 @@ perf_evsel__reset_callgraph(struct evsel *evsel,if (param->record_mode ==CALLCHAIN_LBR ) {perf_evsel__reset_sample_bit (evsel,BRANCH_STACK ); attr->branch_sample_type &= ~(PERF_SAMPLE_BRANCH_USER | -PERF_SAMPLE_BRANCH_CALL_STACK ); +PERF_SAMPLE_BRANCH_CALL_STACK | +PERF_SAMPLE_BRANCH_HW_INDEX ); }if (param->record_mode ==CALLCHAIN_DWARF ) {perf_evsel__reset_sample_bit (evsel,REGS_USER );
@@ -1673,6 +1675,8 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, evsel->core.attr.ksymbol =0 ;if (perf_missing_features.bpf) evsel->core.attr.bpf_event =0 ; +if (perf_missing_features.branch_hw_idx) + evsel->core.attr.branch_sample_type &= ~PERF_SAMPLE_BRANCH_HW_INDEX ; retry_sample_id:if (perf_missing_features.sample_id_all) evsel->core.attr.sample_id_all =0 ;
@@ -1784,7 +1788,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,* Must probe features in the order they were added to the * perf_event_attr interface. */ -if (!perf_missing_features.aux_output && evsel->core.attr.aux_output) { +if (!perf_missing_features.branch_hw_idx && + (evsel->core.attr.branch_sample_type &PERF_SAMPLE_BRANCH_HW_INDEX )) { + perf_missing_features.branch_hw_idx = true; +pr_debug2 ("switching off branch HW index support\n" ); + goto fallback_missing_features; + }else if (!perf_missing_features.aux_output && evsel->core.attr.aux_output) { perf_missing_features.aux_output = true;pr_debug2_peo ("Kernel has no attr.aux_output support, bailing out\n" ); goto out_close;
tools/perf/util/evsel.h +1 -0
@@ -119,6 +119,7 @@ struct perf_missing_features {bool ksymbol;bool bpf;bool aux_output; +bool branch_hw_idx; };extern struct perf_missing_features perf_missing_features;
tools/perf/util/perf_event_attr_fprintf.c +1 -0
@@ -50,6 +50,7 @@ static void __p_branch_sample_type(char *buf, size_t size, u64 value)bit_name (ABORT_TX ),bit_name (IN_TX ),bit_name (NO_TX ),bit_name (COND ),bit_name (CALL_STACK ),bit_name (IND_JUMP ),bit_name (CALL ),bit_name (NO_FLAGS ),bit_name (NO_CYCLES ), +bit_name (HW_INDEX ), { .name = NULL, } };#undef bit_name
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 10/19 perf header: Add check for unexpected use of reserved membrs in event attr
In reply to Arnaldo Carvalho de MeloFrom: Kan Liang <[email protected]>
The perf.data may be generated by a newer version of perf tool, which support new input bits in attr, e.g. new bit for branch_sample_type.
The perf.data may be parsed by an older version of perf tool later. The old perf tool may parse the perf.data incorrectly. There is no warning message for this case.
Current perf header never check for unknown input bits in attr.
When read the event desc from header, check the stored event attr. The reserved bits, sample type, read format and branch sample type will be checked.
--- tools/perf/util/header.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tools/perf/util/header.c +37 -0
@@ -1590,6 +1590,40 @@ static void free_event_desc(struct evsel *events)free (events); } +static bool perf_attr_check (struct perf_event_attr *attr) +{ +if (attr->__reserved_1 || attr->__reserved_2 || attr->__reserved_3) { +pr_warning ("Reserved bits are set unexpectedly. " +"Please update perf tool.\n" ); +return false; + } + +if (attr->sample_type & ~(PERF_SAMPLE_MAX -1 )) { +pr_warning ("Unknown sample type (0x%llx) is detected. " +"Please update perf tool.\n" , + attr->sample_type); +return false; + } + +if (attr->read_format & ~(PERF_FORMAT_MAX -1 )) { +pr_warning ("Unknown read format (0x%llx) is detected. " +"Please update perf tool.\n" , + attr->read_format); +return false; + } + +if ((attr->sample_type &PERF_SAMPLE_BRANCH_STACK ) && + (attr->branch_sample_type & ~(PERF_SAMPLE_BRANCH_MAX -1 ))) { +pr_warning ("Unknown branch sample type (0x%llx) is detected. " +"Please update perf tool.\n" , + attr->branch_sample_type); + +return false; + } + +return true; +} +static struct evsel *read_event_desc (struct feat_fd *ff) {struct evsel *evsel, *events =NULL ;
@@ -1634,6 +1668,9 @@ static struct evsel *read_event_desc(struct feat_fd *ff)memcpy (&evsel->core.attr, buf, msz); +if (!perf_attr_check (&evsel->core.attr)) + goto error; +if (do_read_u32 (ff, &nr)) goto error;
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 11/19 perf expr: Add expr.c object
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Add generic expr code into new expr.c object.
The expr.c object will be mainly used in following change that will get rid of the manual flex code,
--- tools/perf/util/Build | 1 + tools/perf/util/expr.c | 19 +++++++++++++++++++ tools/perf/util/expr.y | 16 ---------------- 3 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 tools/perf/util/expr.c
tools/perf/util/Build +1 -0
@@ -122,6 +122,7 @@ perf-y += vsprintf.o perf-y += units.o perf-y += time-utils.o perf-y += expr-bison.o +perf-y += expr.o perf-y += branch.o perf-y += mem2node.o
tools/perf/util/expr.c new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <assert.h> +#include "expr.h" + +/* Caller must make sure id is allocated */ +void expr__add_id (struct parse_ctx *ctx,const char *name,double val) +{ +int idx; + +assert (ctx->num_ids <MAX_PARSE_ID ); + idx = ctx->num_ids++; + ctx->ids[idx].name = name; + ctx->ids[idx].val = val; +} + +void expr__ctx_init (struct parse_ctx *ctx) +{ + ctx->num_ids =0 ; +}
tools/perf/util/expr.y +0 -16
@@ -6,7 +6,6 @@ #define IN_EXPR_Y 1 #include "expr.h" #include "smt.h" -#include <assert.h> #include <string.h> #define MAXIDLEN 256
@@ -169,21 +168,6 @@ static int expr__lex(YYSTYPE *res, const char **pp) return tok; } -/* Caller must make sure id is allocated */ -void expr__add_id(struct parse_ctx *ctx, const char *name, double val) -{ - int idx; - assert(ctx->num_ids < MAX_PARSE_ID); - idx = ctx->num_ids++; - ctx->ids[idx].name = name; - ctx->ids[idx].val = val; -} - -void expr__ctx_init(struct parse_ctx *ctx) -{ - ctx->num_ids = 0; -} - static bool already_seen(const char *val, const char *one, const char **other, int num_other) {
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 12/19 perf expr: Move expr lexer to flex
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Adding expr flex code instead of the manual parser code. So it's easily extensible in upcoming changes.
The new flex code is in flex.l object and gets compiled like all the other flexers we use. It's defined as flex reentrant parser.
It's used by both expr__parse and expr__find_other interfaces by separating the starting point.
There's no intended change of functionality ;-) the test expr is passing.
--- tools/perf/util/Build | 10 ++- tools/perf/util/expr.c | 93 +++++++++++++++++++++++ tools/perf/util/expr.h | 2 - tools/perf/util/expr.l | 114 +++++++++++++++++++++++++++ tools/perf/util/expr.y | 169 ++++++++--------------------------------- 5 files changed, 247 insertions(+), 141 deletions(-) create mode 100644 tools/perf/util/expr.l
tools/perf/util/Build +9 -1
@@ -121,6 +121,7 @@ perf-y += mem-events.o perf-y += vsprintf.o perf-y += units.o perf-y += time-utils.o +perf-y += expr-flex.o perf-y += expr-bison.o perf-y += expr.o perf-y += branch.o
@@ -190,9 +191,13 @@ $(OUTPUT)util/parse-events-bison.c: util/parse-events.y $(call rule_mkdir) $(Q)$(call echo-cmd,bison)$(BISON) -v util/parse-events.y -d $(PARSER_DEBUG_BISON) -o $@ -p parse_events_ +$(OUTPUT)util/expr-flex.c: util/expr.l $(OUTPUT)util/expr-bison.c + $(call rule_mkdir) + $(Q)$(call echo-cmd,flex)$(FLEX) -o $@ --header-file=$(OUTPUT)util/expr-flex.h $(PARSER_DEBUG_FLEX) util/expr.l + $(OUTPUT)util/expr-bison.c: util/expr.y $(call rule_mkdir) - $(Q)$(call echo-cmd,bison)$(BISON) -v util/expr.y -d $(PARSER_DEBUG_BISON) -o $@ -p expr__ + $(Q)$(call echo-cmd,bison)$(BISON) -v util/expr.y -d $(PARSER_DEBUG_BISON) -o $@ -p expr_ $(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c $(call rule_mkdir)
@@ -204,12 +209,14 @@ $(OUTPUT)util/pmu-bison.c: util/pmu.y CFLAGS_parse-events-flex.o += -w CFLAGS_pmu-flex.o += -w +CFLAGS_expr-flex.o += -w CFLAGS_parse-events-bison.o += -DYYENABLE_NLS=0 -w CFLAGS_pmu-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w CFLAGS_expr-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w $(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c +$(OUTPUT)util/expr.o: $(OUTPUT)util/expr-flex.c $(OUTPUT)util/expr-bison.c CFLAGS_bitmap.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_find_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
@@ -217,6 +224,7 @@ CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ET CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_parse-events.o += -Wno-redundant-decls +CFLAGS_expr.o += -Wno-redundant-decls CFLAGS_header.o += -include $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE
tools/perf/util/expr.c +93 -0
102 lines not on this page · raw message
tools/perf/util/expr.h +0 -2
@@ -17,9 +17,7 @@ struct parse_ctx {void expr__ctx_init (struct parse_ctx *ctx);void expr__add_id (struct parse_ctx *ctx,const char *id,double val); -#ifndef IN_EXPR_Y int expr__parse (double *final_val,struct parse_ctx *ctx,const char **pp); -#endif int expr__find_other (const char *p,const char *one,const char ***other,int *num_other);
tools/perf/util/expr.l new file +114 -0
114 lines not on this page · raw message
tools/perf/util/expr.y +31 -138
207 lines not on this page · raw message
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 13/19 perf expr: Increase EXPR_MAX_OTHER to support metrics with more than 15 variables
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
We have metrics that define more than 15 variables, like Branch_Misprediction_Cost. Increasing the allowed variables count to 20.
As Andy pointed out, we can't go too high in here, because some of the code has O(n^2) complexity (already_seen) and we might want to do some other changes (like using hash tables) before increasing the maximum even more.
--- tools/perf/util/expr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/expr.h +1 -1
@@ -2,7 +2,7 @@#ifndef PARSE_CTX_H #define PARSE_CTX_H 1 -#define EXPR_MAX_OTHER 15 +#define EXPR_MAX_OTHER 20#define MAX_PARSE_ID EXPR_MAX_OTHER struct parse_id {
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 14/19 perf expr: Straighten expr__parse()/expr__find_other() interface
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
Now that we have a flex parser we don't need to update the parsed string pointer, so the interface can just be passed the pointer to the expression instead of a pointer to pointer.
--- tools/perf/tests/expr.c | 6 +++--- tools/perf/util/expr.c | 8 ++++---- tools/perf/util/expr.h | 4 ++-- tools/perf/util/stat-shadow.c | 4 +--- 4 files changed, 10 insertions(+), 12 deletions(-)
tools/perf/tests/expr.c +3 -3
@@ -10,7 +10,7 @@ static int test(struct parse_ctx *ctx, const char *e, double val2) {double val; -if (expr__parse (&val, ctx, &e)) +if (expr__parse (&val, ctx, e))TEST_ASSERT_VAL ("parse test failed" ,0 );TEST_ASSERT_VAL ("unexpected value" , val == val2);return 0 ;
@@ -44,11 +44,11 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)return ret; p ="FOO/0" ; - ret =expr__parse (&val, &ctx, &p); + ret =expr__parse (&val, &ctx, p);TEST_ASSERT_VAL ("division by zero" , ret ==1 ); p ="BAR/" ; - ret =expr__parse (&val, &ctx, &p); + ret =expr__parse (&val, &ctx, p);TEST_ASSERT_VAL ("missing operand" , ret ==1 ); TEST_ASSERT_VAL("find other",
tools/perf/util/expr.c +4 -4
@@ -52,9 +52,9 @@ __expr__parse(double *val, struct parse_ctx *ctx, const char *expr,return ret; } -int expr__parse (double *final_val,struct parse_ctx *ctx,const char **pp) +int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr) { -return __expr__parse (final_val, ctx, *pp,EXPR_PARSE ); +return __expr__parse (final_val, ctx, expr,EXPR_PARSE ); } static bool
@@ -71,14 +71,14 @@ already_seen(const char *val, const char *one, const char **other,return false; } -int expr__find_other (const char *p,const char *one,const char ***other, +int expr__find_other (const char *expr,const char *one,const char ***other,int *num_other) {int err, i =0 , j =0 ;struct parse_ctx ctx;expr__ctx_init (&ctx); - err =__expr__parse (NULL , &ctx, p,EXPR_OTHER ); + err =__expr__parse (NULL , &ctx, expr,EXPR_OTHER );if (err)return -1 ;
tools/perf/util/expr.h +2 -2
@@ -17,8 +17,8 @@ struct parse_ctx {void expr__ctx_init (struct parse_ctx *ctx);void expr__add_id (struct parse_ctx *ctx,const char *id,double val); -int expr__parse (double *final_val,struct parse_ctx *ctx,const char **pp); -int expr__find_other (const char *p,const char *one,const char ***other, +int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr); +int expr__find_other (const char *expr,const char *one,const char ***other,int *num_other);#endif
tools/perf/util/stat-shadow.c +1 -3
@@ -777,9 +777,7 @@ static void generic_metric(struct perf_stat_config *config, }if (!metric_events[i]) { -const char *p = metric_expr; - -if (expr__parse (&ratio, &pctx, &p) ==0 ) { +if (expr__parse (&ratio, &pctx, metric_expr) ==0 ) {char *unit;char metric_bf[64 ];
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 15/19 perf expr: Make expr__parse() return -1 on error
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
To match the error value of the expr__find_other function, so all exported expr functions return the same values:
0 on success, -1 on error.
--- tools/perf/tests/expr.c | 4 ++-- tools/perf/util/expr.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/tests/expr.c +2 -2
@@ -45,11 +45,11 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) p ="FOO/0" ; ret =expr__parse (&val, &ctx, p); -TEST_ASSERT_VAL ("division by zero" , ret ==1 ); +TEST_ASSERT_VAL ("division by zero" , ret ==-1 ); p ="BAR/" ; ret =expr__parse (&val, &ctx, p); -TEST_ASSERT_VAL ("missing operand" , ret ==1 ); +TEST_ASSERT_VAL ("missing operand" , ret ==-1 );TEST_ASSERT_VAL ("find other" ,expr__find_other ("FOO + BAR + BAZ + BOZO" ,"FOO" , &other, &num_other) ==0 );
tools/perf/util/expr.c +1 -1
@@ -54,7 +54,7 @@ __expr__parse(double *val, struct parse_ctx *ctx, const char *expr,int expr__parse (double *final_val,struct parse_ctx *ctx,const char *expr) { -return __expr__parse (final_val, ctx, expr,EXPR_PARSE ); +return __expr__parse (final_val, ctx, expr,EXPR_PARSE ) ?-1 :0 ; } static bool
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 16/19 perf block-info: Fix wrong block address comparison in block_info__cmp()
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Commit 6041441870ab ("perf block: Cleanup and refactor block info functions") introduces block_info__cmp(), which compares two blocks.
But the issues are:
1. It should return the strcmp cmp value only if it's not 0.
2. When symbol names are matched, we need to compare the addresses of blocks further. But it wrongly uses the symbol addresses for comparison.
3. If the syms are both NULL, we can't consider these two blocks are matched.
This patch fixes above 3 issues.
--- tools/perf/util/block-info.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
tools/perf/util/block-info.c +6 -15
@@ -74,30 +74,21 @@ int64_t block_info__cmp(struct perf_hpp_fmt *fmt __maybe_unused,if (!bi_l->sym || !bi_r->sym) {if (!bi_l->sym && !bi_r->sym) -return 0 ; +return -1 ;else if (!bi_l->sym)return -1 ;else return 1 ; } -if (bi_l->sym == bi_r->sym) { -if (bi_l->start == bi_r->start) { -if (bi_l->end == bi_r->end) -return 0 ; -else -return (int64_t )(bi_r->end - bi_l->end); - }else -return (int64_t )(bi_r->start - bi_l->start); - }else { - cmp =strcmp (bi_l->sym->name, bi_r->sym->name); + cmp =strcmp (bi_l->sym->name, bi_r->sym->name); +if (cmp)return cmp; - } -if (bi_l->sym->start != bi_r->sym->start) -return (int64_t )(bi_r->sym->start - bi_l->sym->start); +if (bi_l->start != bi_r->start) +return (int64_t )(bi_r->start - bi_l->start); -return (int64_t )(bi_r->sym->end - bi_l->sym->end); +return (int64_t )(bi_r->end - bi_l->end); } static void init_block_info(struct block_info *bi, struct symbol *sym,
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 17/19 perf diff: Use __block_info__cmp() to replace block_pair_cmp()
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
'perf diff' uses block_pair_cmp() to compare two blocks. But block_info__cmp() has the similar functionality and it's a bit more complete.
This patch removes block_pair_cmp() and uses __block_info__cmp() instead. __block_info__cmp() is wrapped by block_info__cmp() and it doesn't receives a perf_hpp_fmt parameter.
--- tools/perf/builtin-diff.c | 21 ++------------------- tools/perf/util/block-info.c | 9 +++++++-- tools/perf/util/block-info.h | 2 ++ 3 files changed, 11 insertions(+), 21 deletions(-)
tools/perf/builtin-diff.c +2 -19
@@ -572,29 +572,12 @@ static void init_block_hist(struct block_hist *bh) bh->valid = true; } -static int block_pair_cmp (struct hist_entry *a,struct hist_entry *b) -{ -struct block_info *bi_a = a->block_info; -struct block_info *bi_b = b->block_info; -int cmp; - -if (!bi_a->sym || !bi_b->sym) -return -1 ; - - cmp =strcmp (bi_a->sym->name, bi_b->sym->name); - -if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end)) -return 0 ; - -return -1 ; -} -static struct hist_entry *get_block_pair (struct hist_entry *he,struct hists *hists_pair) {struct rb_root_cached *root = hists_pair->entries_in;struct rb_node *next =rb_first_cached (root); -int cmp; +int64_t cmp;while (next !=NULL ) { struct hist_entry *he_pair = rb_entry(next, struct hist_entry,
@@ -602,7 +585,7 @@ static struct hist_entry *get_block_pair(struct hist_entry *he, next =rb_next (&he_pair->rb_node_in); - cmp =block_pair_cmp (he_pair, he); + cmp =__block_info__cmp (he_pair, he);if (!cmp)return he_pair; }
tools/perf/util/block-info.c +7 -2
@@ -65,8 +65,7 @@ struct block_info *block_info__new(void)return bi; } -int64_t block_info__cmp (struct perf_hpp_fmt *fmt__maybe_unused , -struct hist_entry *left,struct hist_entry *right) +int64_t __block_info__cmp (struct hist_entry *left,struct hist_entry *right) {struct block_info *bi_l = left->block_info;struct block_info *bi_r = right->block_info;
@@ -91,6 +90,12 @@ int64_t block_info__cmp(struct perf_hpp_fmt *fmt __maybe_unused,return (int64_t )(bi_r->end - bi_l->end); } +int64_t block_info__cmp (struct perf_hpp_fmt *fmt__maybe_unused , +struct hist_entry *left,struct hist_entry *right) +{ +return __block_info__cmp (left, right); +} +static void init_block_info (struct block_info *bi,struct symbol *sym,struct cyc_hist *ch,int offset,u64 total_cycles)
tools/perf/util/block-info.h +2 -0
@@ -61,6 +61,8 @@ static inline void __block_info__zput(struct block_info **bi)#define block_info__zput (bi) __block_info__zput(&bi) +int64_t __block_info__cmp (struct hist_entry *left,struct hist_entry *right); +int64_t block_info__cmp (struct perf_hpp_fmt *fmt__maybe_unused ,struct hist_entry *left,struct hist_entry *right);
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 18/19 perf block-info: Allow selecting which columns to report and its order
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
Currently we use a predefined array to set the block info output formats, it's fixed and inflexible.
This patch adds two parameters "block_hpps" and "nr_hpps" in block_info__create_report and other static functions, in order to let user decide which columns to report and with specified report ordering. It should be more flexible.
Buffers will be allocated to contain the new fmts, of course, we need to release them before perf exits.
--- tools/perf/builtin-report.c | 21 ++++++++++++--- tools/perf/util/block-info.c | 51 +++++++++++++++++++++++++----------- tools/perf/util/block-info.h | 7 ++++- 3 files changed, 59 insertions(+), 20 deletions(-)
tools/perf/builtin-report.c +18 -3
@@ -104,6 +104,7 @@ struct report {bool symbol_ipc;bool total_cycles_mode;struct block_report *block_reports; +int nr_block_reports; };static int report__config (const char *var,const char *value,void *cb)
@@ -966,8 +967,19 @@ static int __cmd_report(struct report *rep)report__output_resort (rep);if (rep->total_cycles_mode) { +int block_hpps[6 ] = { +PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_LBR_CYCLES , +PERF_HPP_REPORT__BLOCK_CYCLES_PCT , +PERF_HPP_REPORT__BLOCK_AVG_CYCLES , +PERF_HPP_REPORT__BLOCK_RANGE , +PERF_HPP_REPORT__BLOCK_DSO , + }; + rep->block_reports =block_info__create_report (session->evlist, - rep->total_cycles); + rep->total_cycles, + block_hpps,6 , + &rep->nr_block_reports);if (!rep->block_reports)return -1 ; }
@@ -1551,8 +1563,11 @@ int cmd_report(int argc, const char **argv)zfree (&report.ptime_range); } -if (report.block_reports) -zfree (&report.block_reports); +if (report.block_reports) { +block_info__free_report (report.block_reports, + report.nr_block_reports); + report.block_reports =NULL ; + }zstd_fini (&(session->zstd_data));perf_session__delete (session);
tools/perf/util/block-info.c +35 -16
110 lines not on this page · raw message
tools/perf/util/block-info.h +6 -1
@@ -45,6 +45,7 @@ struct block_report {struct block_hist hist;u64 cycles;struct block_fmt fmts[PERF_HPP_REPORT__BLOCK_MAX_INDEX ]; +int nr_fmts; };struct block_hist ;
@@ -70,7 +71,11 @@ int block_info__process_sym(struct hist_entry *he, struct block_hist *bh, u64 *block_cycles_aggr, u64 total_cycles);struct block_report *block_info__create_report (struct evlist *evlist, -u64 total_cycles); +u64 total_cycles, +int *block_hpps,int nr_hpps, +int *nr_reps); + +void block_info__free_report (struct block_report *reps,int nr_reps); int report__browse_block_hists(struct block_hist *bh, float min_percent, struct evsel *evsel, struct perf_env *env,
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 19/19 perf block-info: Support color ops to print block percents in color
In reply to Arnaldo Carvalho de MeloFrom: Jin Yao <[email protected]>
It would be nice to print the block percents with colors.
This patch supports the 'Sampled Cycles%' and 'Avg Cycles%' printed in colors.
For example,
perf record -b ...
perf report --total-cycles or perf report --total-cycles --stdio
percent > 5%, colored in red
percent > 0.5%, colored in green
percent < 0.5%, default color
--- tools/perf/util/block-info.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
tools/perf/util/block-info.c +15 -10
@@ -181,6 +181,17 @@ static int block_column_width(struct perf_hpp_fmt *fmt,return block_fmt->width; } +static int color_pct (struct perf_hpp *hpp,int width,double pct) +{ +#ifdef HAVE_SLANG_SUPPORT +if (use_browser) { +return __hpp__slsmg_color_printf (hpp,"%*.2f%%" , + width -1 , pct); + } +#endif +return hpp_color_scnprintf (hpp,"%*.2f%%" , width -1 , pct); +} +static int block_total_cycles_pct_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he)
@@ -188,14 +199,11 @@ static int block_total_cycles_pct_entry(struct perf_hpp_fmt *fmt, struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);struct block_info *bi = he->block_info;double ratio =0.0 ; -char buf[16 ];if (block_fmt->total_cycles) ratio = (double )bi->cycles / (double )block_fmt->total_cycles; -sprintf (buf,"%.2f%%" ,100.0 * ratio); - -return scnprintf (hpp->buf, hpp->size,"%*s" , block_fmt->width, buf); +return color_pct (hpp, block_fmt->width,100.0 * ratio); } static int64_t block_total_cycles_pct_sort(struct perf_hpp_fmt *fmt,
@@ -248,16 +256,13 @@ static int block_cycles_pct_entry(struct perf_hpp_fmt *fmt,struct block_info *bi = he->block_info;double ratio =0.0 ;u64 avg; -char buf[16 ];if (block_fmt->block_cycles && bi->num_aggr) { avg = bi->cycles_aggr / bi->num_aggr; ratio = (double )avg / (double )block_fmt->block_cycles; } -sprintf (buf,"%.2f%%" ,100.0 * ratio); - -return scnprintf (hpp->buf, hpp->size,"%*s" , block_fmt->width, buf); +return color_pct (hpp, block_fmt->width,100.0 * ratio); } static int block_avg_cycles_entry(struct perf_hpp_fmt *fmt,
@@ -345,7 +350,7 @@ static void hpp_register(struct block_fmt *block_fmt, int idx,switch (idx) {case PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT : - fmt->entry = block_total_cycles_pct_entry; + fmt->color = block_total_cycles_pct_entry; fmt->cmp = block_info__cmp; fmt->sort = block_total_cycles_pct_sort;break ;
@@ -353,7 +358,7 @@ static void hpp_register(struct block_fmt *block_fmt, int idx, fmt->entry = block_cycles_lbr_entry;break ;case PERF_HPP_REPORT__BLOCK_CYCLES_PCT : - fmt->entry = block_cycles_pct_entry; + fmt->color = block_cycles_pct_entry;break ;case PERF_HPP_REPORT__BLOCK_AVG_CYCLES : fmt->entry = block_avg_cycles_entry;
Signature · 1 line
2.21.1