perf/core improvements and fixes
Subsystems (6)
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
Best regards,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit fd7d55172d1e2e501e6da0a5c1de25f06612dc2e:
perf/cgroups: Don't rotate events for cgroups unnecessarily (2019-06-24 19:30:04 +0200)
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.3-20190701
for you to fetch changes up to 06c642c0e9fceafd16b1a4c80d44b1c09e282215:
perf jevents: Use nonlocal include statements in pmu-events.c (2019-07-01 22:50:42 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
perf annotate:
Mao Han:
- Add support for the csky processor architecture.
perf stat:
Andi Kleen:
- Fix metrics with --no-merge.
- Don't merge events in the same PMU.
- Fix group lookup for metric group.
Intel PT:
Adrian Hunter:
- Improve CBR (Core to Bus Ratio) packets support.
- Fix thread stack return from kernel for kernel only case.
- Export power and ptwrite events to sqlite and postgresql.
core libraries:
Arnaldo Carvalho de Melo:
- Find routines in tools/perf/util/ that have implementations in the kernel libraries (lib/*.c), such as strreplace(), strim(), skip_spaces() and reuse them after making a copy into tools/lib and tools/include/.
This continues the effort of having tools/ code looking as much as possible like kernel source code, to help encourage people to work on both the kernel and in tools hosted in the kernel sources.
That in turn will help moving stuff that uses those routines to tools/lib/perf/ where they will be made available for use in other tools.
In the process ditch old cruft, remove unused variables and add missing include directives for headers providing things used in places that were building by sheer luck.
Kyle Meyer:
- Bump MAX_NR_CPUS and MAX_CACHES to get these tools to work on more machines.
----------------------------------------------------------------
Adrian Hunter (9):
perf thread-stack: Fix thread stack return from kernel for kernel-only case perf thread-stack: Eliminate code duplicating thread_stack__pop_ks() perf intel-pt: Decoder to output CBR changes immediately
perf intel-pt: Cater for CBR change in PSB+
perf intel-pt: Add CBR value to decoder state
perf intel-pt: Synthesize CBR events when last seen value changes
perf db-export: Export synth events
perf scripts python: export-to-sqlite.py: Export Intel PT power and ptwrite events perf scripts python: export-to-postgresql.py: Export Intel PT power and ptwrite events
Andi Kleen (4):
perf stat: Make metric event lookup more robust perf stat: Don't merge events in the same PMU perf stat: Fix group lookup for metric group perf stat: Fix metrics with --no-merge
Arnaldo Carvalho de Melo (26):
perf ctype: Remove unused 'graph_line' variable
perf ui stdio: No need to use 'spaces' to left align
perf ctype: Remove now unused 'spaces' variable
perf string: Move 'dots' and 'graph_dotted_line' out of sane_ctype.h tools x86 machine: Add missing util.h to pick up 'page_size' perf kallsyms: Adopt hex2u64 from tools/perf/util/util.h
perf symbols: We need util.h in symbol-elf.c for zfree()
perf tools: Remove old baggage that is util/include/linux/ctype.h perf tools: Add missing util.h to pick up 'page_size' variable tools perf: Move from sane_ctype.h obtained from git to the Linux's original perf tools: Use linux/ctype.h in more places
tools lib: Adopt skip_spaces() from the kernel sources
perf stat: Use recently introduced skip_spaces()
perf header: Use skip_spaces() in __write_cpudesc()
perf time-utils: Use skip_spaces()
perf probe: Use skip_spaces() for argv handling
perf strfilter: Use skip_spaces()
perf metricgroup: Use strsep()
perf report: Use skip_spaces()
perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel tools lib: Adopt strim() from the kernel
perf tools: Remove trim() implementation, use tools/lib's strim() perf tools: Ditch rtrim(), use strim() from tools/lib
tools lib: Adopt strreplace() from the kernel
perf tools: Drop strxfrchar(), use strreplace() equivalent from kernel tools lib: Move argv_{split,free} from tools/perf/util/
Kyle Meyer (1):
perf tools: Increase MAX_NR_CPUS and MAX_CACHES
Luke Mujica (1):
perf jevents: Use nonlocal include statements in pmu-events.c
Mao Han (1):
perf annotate: Add csky support
Numfor Mbiziwo-Tiapo (1):
perf tools: Fix cache.h include directive
tools/include/linux/ctype.h | 75 ++++++ tools/include/linux/string.h | 11 +- tools/lib/argv_split.c | 100 ++++++++ tools/lib/ctype.c | 35 +++ tools/lib/string.c | 55 +++++ tools/lib/symbol/kallsyms.c | 14 +- tools/lib/symbol/kallsyms.h | 2 + tools/perf/MANIFEST | 2 + tools/perf/arch/arm/util/cs-etm.c | 1 + tools/perf/arch/csky/annotate/instructions.c | 48 ++++ tools/perf/arch/s390/util/header.c | 2 +- tools/perf/arch/x86/tests/intel-cqm.c | 1 + tools/perf/arch/x86/util/intel-pt.c | 1 + tools/perf/arch/x86/util/machine.c | 3 +- tools/perf/builtin-kmem.c | 3 +- tools/perf/builtin-report.c | 5 +- tools/perf/builtin-sched.c | 3 +- tools/perf/builtin-script.c | 14 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-top.c | 3 +- tools/perf/builtin-trace.c | 2 +- tools/perf/check-headers.sh | 2 + tools/perf/perf.c | 1 + tools/perf/perf.h | 2 +- tools/perf/pmu-events/jevents.c | 4 +- tools/perf/scripts/python/export-to-postgresql.py | 251 +++++++++++++++++++++ tools/perf/scripts/python/export-to-sqlite.py | 239 ++++++++++++++++++++ tools/perf/tests/builtin-test.c | 3 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/ui/browser.c | 4 +- tools/perf/ui/browsers/hists.c | 10 +- tools/perf/ui/browsers/map.c | 2 +- tools/perf/ui/gtk/hists.c | 5 +- tools/perf/ui/progress.c | 2 +- tools/perf/ui/stdio/hist.c | 16 +- tools/perf/util/Build | 9 + tools/perf/util/annotate.c | 20 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/ctype.c | 49 ---- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/debug.c | 2 +- tools/perf/util/demangle-java.c | 2 +- tools/perf/util/dso.c | 3 +- tools/perf/util/env.c | 2 +- tools/perf/util/event.c | 6 +- tools/perf/util/evsel.c | 3 +- tools/perf/util/header.c | 15 +- tools/perf/util/include/linux/ctype.h | 1 - .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 24 +- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 1 + tools/perf/util/intel-pt.c | 65 ++++-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/machine.c | 3 +- tools/perf/util/metricgroup.c | 52 +++-- tools/perf/util/pmu.c | 5 +- tools/perf/util/print_binary.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-finder.h | 2 +- tools/perf/util/python-ext-sources | 3 +- tools/perf/util/python.c | 1 + tools/perf/util/sane_ctype.h | 52 ----- .../util/scripting-engines/trace-event-python.c | 46 +++- tools/perf/util/srcline.c | 3 +- tools/perf/util/stat-display.c | 14 +- tools/perf/util/stat-shadow.c | 23 +- tools/perf/util/strfilter.c | 6 +- tools/perf/util/string.c | 169 +------------- tools/perf/util/string2.h | 15 +- tools/perf/util/symbol-elf.c | 3 +- tools/perf/util/symbol.c | 2 +- tools/perf/util/thread-stack.c | 48 ++-- tools/perf/util/thread_map.c | 3 +- tools/perf/util/time-utils.c | 8 +- tools/perf/util/trace-event-parse.c | 2 +- tools/perf/util/util.c | 13 -- tools/perf/util/util.h | 1 - 79 files changed, 1167 insertions(+), 450 deletions(-) create mode 100644 tools/include/linux/ctype.h create mode 100644 tools/lib/argv_split.c create mode 100644 tools/lib/ctype.c create mode 100644 tools/perf/arch/csky/annotate/instructions.c delete mode 100644 tools/perf/util/ctype.c delete mode 100644 tools/perf/util/include/linux/ctype.h delete mode 100644 tools/perf/util/sane_ctype.h
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.
Investigating the failure for ubuntu:18.04-x-arm, doesn't look like something introduced by this patchkit.
$ export PERF_TARBALL=http://192.168.124.1/perf/perf-5.2.0-rc6.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:edge : Ok gcc (Alpine 8.3.0) 8.3.0, Alpine clang version 7.0.1 (tags/RELEASE_701/final) (based on LLVM 7.0.1) 9 amazonlinux:1 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2), clang version 3.6.2 (tags/RELEASE_362/final) 10 amazonlinux:2 : Ok gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5), clang version 7.0.1 (Amazon Linux 2 7.0.1-1.amzn2.0.2) 11 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 12 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 13 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 14 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23) 15 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), clang version 3.4.2 (tags/RELEASE_34/dot2-final) 16 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) 17 debian:9 : Ok gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, clang version 3.8.1-24 (tags/RELEASE_381/final) 18 debian:experimental : Ok gcc (Debian 8.3.0-7) 8.3.0, clang version 7.0.1-8 (tags/RELEASE_701/final) 19 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0 20 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0 21 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 8.3.0-7) 8.3.0 22 debian:experimental-x-mipsel : Ok mipsel-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0 23 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7), clang version 3.4.2 (tags/RELEASE_34/dot2-final) 24 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6), clang version 3.5.0 (tags/RELEASE_350/final) 25 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6), clang version 3.7.0 (tags/RELEASE_370/final) 26 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1), clang version 3.8.1 (tags/RELEASE_381/final) 27 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 28 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1), clang version 3.9.1 (tags/RELEASE_391/final) 29 fedora:26 : Ok gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2), clang version 4.0.1 (tags/RELEASE_401/final) 30 fedora:27 : Ok gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6), clang version 5.0.2 (tags/RELEASE_502/final) 31 fedora:28 : Ok gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2), clang version 6.0.1 (tags/RELEASE_601/final) 32 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) 33 fedora:30 : Ok gcc (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1), clang version 8.0.0 (Fedora 8.0.0-1.fc30) 34 fedora:30-x-ARC-glibc : Ok arc-linux-gcc (ARC HS GNU/Linux glibc toolchain 2019.03-rc1) 8.3.1 20190225 35 fedora:30-x-ARC-uClibc : Ok arc-linux-gcc (ARCv2 ISA Linux uClibc toolchain 2019.03-rc1) 8.3.1 20190225 36 fedora:31 : Ok gcc (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2), clang version 8.0.0 (Fedora 8.0.0-3.fc31) 37 fedora:rawhide : Ok gcc (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2), clang version 8.0.0 (Fedora 8.0.0-3.fc31) 38 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 8.3.0-r1 p1.1) 8.3.0 39 mageia:5 : Ok gcc (GCC) 4.9.2, clang version 3.5.2 (tags/RELEASE_352/final) 40 mageia:6 : Ok gcc (Mageia 5.5.0-1.mga6) 5.5.0, clang version 3.9.1 (tags/RELEASE_391/final) 41 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) 42 manjaro:latest : Ok gcc (GCC) 8.3.0, clang version 8.0.0 (tags/RELEASE_800/final) 43 openmandriva:cooker : Ok gcc (GCC) 9.1.0 20190503 (OpenMandriva) 44 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) 45 opensuse:15.1 : Ok gcc (SUSE Linux) 7.4.0, clang version 7.0.1 (tags/RELEASE_701/final 349238) 46 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5, clang version 3.8.0 (tags/RELEASE_380/final 262553) 47 opensuse:tumbleweed : Ok gcc (SUSE Linux) 9.1.1 20190520 [gcc-9-branch revision 271396], clang version 8.0.0 (tags/RELEASE_800/final 356365) 48 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23.0.1) 49 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36.0.1), clang version 3.4.2 (tags/RELEASE_34/dot2-final) 50 ubuntu:12.04 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 51 ubuntu:14.04 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4, Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) 52 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609, clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) 53 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 54 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 55 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 56 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 57 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 58 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 59 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) 60 ubuntu:18.04-x-arm : FAIL arm-linux-gnueabihf-gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0
arch/arm64/util/dwarf-regs.c: In function 'regs_query_register_offset':
arch/arm64/util/dwarf-regs.c:26:43: error: dereferencing pointer to incomplete type 'struct user_pt_regs'
(index * sizeof((struct user_pt_regs *)0)->regs[0])
^
arch/arm64/util/dwarf-regs.c:91:11: note: in expansion of macro 'DWARFNUM2OFFSET'
return DWARFNUM2OFFSET(roff->dwarfnum);
^~~~~~~~~~~~~~~ mv: cannot stat '/tmp/build/perf/arch/arm64/util/.dwarf-regs.o.tmp': No such file or directory
61 ubuntu:18.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0 62 ubuntu:18.04-x-m68k : Ok m68k-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 63 ubuntu:18.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 64 ubuntu:18.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 65 ubuntu:18.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 66 ubuntu:18.04-x-riscv64 : Ok riscv64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 67 ubuntu:18.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 68 ubuntu:18.04-x-sh4 : Ok sh4-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 69 ubuntu:18.04-x-sparc64 : Ok sparc64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 70 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) 71 ubuntu:19.04 : Ok gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0, clang version 8.0.0-3 (tags/RELEASE_800/final) 72 ubuntu:19.04-x-alpha : Ok alpha-linux-gnu-gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0 73 ubuntu:19.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 8.3.0-6ubuntu1) 8.3.0 74 ubuntu:19.04-x-hppa : Ok hppa-linux-gnu-gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0 75 ubuntu:19.10 : Ok gcc (Ubuntu 8.3.0-14ubuntu1) 8.3.0, clang version 8.0.1-+rc1-1~exp1 (tags/RELEASE_801/rc1)
$
# uname -a
Linux quaco 5.2.0-rc7 #2 SMP Mon Jul 1 23:05:41 -03 2019 x86_64 x86_64 x86_64 GNU/Linux
# git log --oneline -1
06c642c0e9fc perf jevents: Use nonlocal include statements in pmu-events.c
# perf version --build-options
perf version 5.2.rc6.g06c642c0e9fc
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 mg : Ok
32: Sort output of hist entries : Ok
33: Cumulate child hist entries : Ok
34: Track with sched_switch : Ok
35: Filter fds with revents mask in a fdarray : Ok
36: Add fd to a fdarray, making it autogrow : Ok
37: kmod_path__parse : Ok
38: Thread map : Ok
39: LLVM search and compile :
39.1: Basic BPF llvm compile : Ok
39.2: kbuild searching : Ok
39.3: Compile source for BPF prologue generation : Ok
39.4: Compile source for BPF relocation : Ok
40: Session topology : Ok
41: BPF filter :
41.1: Basic BPF filtering : Ok
41.2: BPF pinning : Ok
41.3: BPF prologue generation : Ok
41.4: BPF relocation checker : Ok
42: Synthesize thread map : Ok
43: Remove thread map : Ok
44: Synthesize cpu map : Ok
45: Synthesize stat config : Ok
46: Synthesize stat : Ok
47: Synthesize stat round : Ok
48: Synthesize attr update : Ok
49: Event times : Ok
50: Read backward ring buffer : Ok
51: Print cpu map : Ok
52: Probe SDT events : Ok
53: is_printable_array : Ok
54: Print bitmap : Ok
55: perf hooks : Ok
56: builtin clang support : Skip (not compiled in)
57: unit_number__scnprintf : Ok
58: mem2node : Ok
59: time utils : Ok
60: map_groups__merge_in : Ok
61: x86 rdpmc : Ok
62: Convert perf time to TSC : Ok
63: DWARF unwind : Ok
64: x86 instruction decoder - new instructions : Ok
65: Intel PT packet decoder : Ok
66: x86 bp modify : Ok
67: probe libc's inet_pton & backtrace it with ping : Ok
68: Use vfs_getname probe to get syscall args filenames : Ok
69: Add vfs_getname probe to get syscall args filenames : Ok
70: Check open filename arg using perf trace + vfs_getname: Ok
71: Zstd perf.data compression/decompression : Ok $ make -C tools/perf build-test
make: Entering directory '/home/acme/git/perf/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_no_libbpf_O: make NO_LIBBPF=1
make_no_libperl_O: make NO_LIBPERL=1
make_no_libunwind_O: make NO_LIBUNWIND=1
make_static_O: make LDFLAGS=-static
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_with_babeltrace_O: make LIBBABELTRACE=1
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_install_prefix_O: make install prefix=/tmp/krava
make_no_libelf_O: make NO_LIBELF=1
make_no_auxtrace_O: make NO_AUXTRACE=1
make_no_demangle_O: make NO_DEMANGLE=1
make_no_backtrace_O: make NO_BACKTRACE=1
make_no_gtk2_O: make NO_GTK2=1
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_doc_O: make doc
make_help_O: make help
make_perf_o_O: make perf.o
make_no_libpython_O: make NO_LIBPYTHON=1
make_no_libaudit_O: make NO_LIBAUDIT=1
make_debug_O: make DEBUG=1
make_pure_O: make
make_install_O: make install
make_install_bin_O: make install-bin
make_no_newt_O: make NO_NEWT=1
make_cscope_O: make cscope
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
make_tags_O: make tags
make_no_libnuma_O: make NO_LIBNUMA=1
make_util_map_o_O: make util/map.o
make_no_slang_O: make NO_SLANG=1
make_clean_all_O: make clean all
make_with_clangllvm_O: make LIBCLANGLLVM=1
make_no_libbionic_O: make NO_LIBBIONIC=1
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$Arnaldo Carvalho de Melo
maintainerPATCH 1/43 perf tools: Fix cache.h include directive
From: Numfor Mbiziwo-Tiapo <[email protected]>
Change the include path so that progress.c can find cache.h since it was previously searching in the wrong directory.
Committer notes:
$ ls -la tools/perf/ui/../cache.h ls: cannot access 'tools/perf/ui/../cache.h': No such file or directory
So it really should include ../../util/cache.h, or plain cache.h, since we have -Iutil in INC_FLAGS in tools/perf/Makefile.config
To: Ian Rogers <[email protected]>
--- tools/perf/ui/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/ui/progress.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> -#include "../cache.h" +#include "../util/cache.h" #include "progress.h" static void null_progress__update (struct ui_progress *p__maybe_unused )
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 2/43 perf thread-stack: Fix thread stack return from kernel for kernel-only case
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Commit f08046cb3082 ("perf thread-stack: Represent jmps to the start of a different symbol") had the side-effect of introducing more stack entries before return from kernel space.
When user space is also traced, those entries are popped before entry to user space, but when user space is not traced, they get stuck at the bottom of the stack, making the stack grow progressively larger.
Fix by detecting a return-from-kernel branch type, and popping kernel addresses from the stack then.
Note, the problem and fix affect the exported Call Graph / Tree but not the callindent option used by "perf script --call-trace".
Example:
perf-with-kcore record example -e intel_pt//k -- ls perf-with-kcore script example --itrace=bep -s ~/libexec/perf-core/scripts/python/export-to-sqlite.py example.db branches calls ~/libexec/perf-core/scripts/python/exported-sql-viewer.py example.db
Menu option: Reports -> Context-Sensitive Call Graph
Before: (showing Call Path column only)
Call Path
▶ perf
▼ ls
▼ 12111:12111
▶ setup_new_exec
▶ __task_pid_nr_ns
▶ perf_event_pid_type
▶ perf_event_comm_output
▶ perf_iterate_ctx
▶ perf_iterate_sb
▶ perf_event_comm
▶ __set_task_comm
▶ load_elf_binary
▶ search_binary_handler
▶ __do_execve_file.isra.41
▶ __x64_sys_execve
▶ do_syscall_64
▼ entry_SYSCALL_64_after_hwframe
▼ swapgs_restore_regs_and_return_to_usermode
▼ native_iret
▶ error_entry
▶ do_page_fault
▼ error_exit
▼ retint_user
▶ prepare_exit_to_usermode
▼ native_iret
▶ error_entry
▶ do_page_fault
▼ error_exit
▼ retint_user
▶ prepare_exit_to_usermode
▼ native_iret
▶ error_entry
▶ do_page_fault
▼ error_exit
▼ retint_user
▶ prepare_exit_to_usermode
▶ native_iretAfter: (showing Call Path column only)
Call Path
▶ perf
▼ ls
▼ 12111:12111
▶ setup_new_exec
▶ __task_pid_nr_ns
▶ perf_event_pid_type
▶ perf_event_comm_output
▶ perf_iterate_ctx
▶ perf_iterate_sb
▶ perf_event_comm
▶ __set_task_comm
▶ load_elf_binary
▶ search_binary_handler
▶ __do_execve_file.isra.41
▶ __x64_sys_execve
▶ do_syscall_64
▶ entry_SYSCALL_64_after_hwframe
▶ page_fault
▼ entry_SYSCALL_64
▼ do_syscall_64
▶ __x64_sys_brk
▶ __x64_sys_access
▶ __x64_sys_openat
▶ __x64_sys_newfstat
▶ __x64_sys_mmap
▶ __x64_sys_close
▶ __x64_sys_read
▶ __x64_sys_mprotect
▶ __x64_sys_arch_prctl
▶ __x64_sys_munmap
▶ exit_to_usermode_loop
▶ __x64_sys_set_tid_address
▶ __x64_sys_set_robust_list
▶ __x64_sys_rt_sigaction
▶ __x64_sys_rt_sigprocmask
▶ __x64_sys_prlimit64
▶ __x64_sys_statfs
▶ __x64_sys_ioctl
▶ __x64_sys_getdents64
▶ __x64_sys_write
▶ __x64_sys_exit_groupCommitter notes:
The first arg to the perf-with-kcore needs to be the same for the 'record' and 'script' lines, otherwise we'll record the perf.data file and kcore_dir/ files in one directory ('example') to then try to use it from the 'bep' directory, fix the instructions above it so that both use 'example'.
--- tools/perf/util/thread-stack.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
tools/perf/util/thread-stack.c +29 -1
@@ -628,6 +628,23 @@ static int thread_stack__bottom(struct thread_stack *ts, true, false); } +static int thread_stack__pop_ks (struct thread *thread,struct thread_stack *ts, +struct perf_sample *sample,u64 ref) +{ +u64 tm = sample->time; +int err; + +/* Return to userspace, so pop all kernel addresses */ +while (thread_stack__in_kernel (ts)) { + err =thread_stack__call_return (thread, ts, --ts->cnt, + tm, ref, true); +if (err) +return err; + } + +return 0 ; +} + static int thread_stack__no_call_return(struct thread *thread, struct thread_stack *ts, struct perf_sample *sample,
@@ -910,7 +927,18 @@ int thread_stack__process(struct thread *thread, struct comm *comm, ts->rstate =X86_RETPOLINE_DETECTED ; }else if (sample->flags &PERF_IP_FLAG_RETURN ) { -if (!sample->ip || !sample->addr) +if (!sample->addr) { +u32 return_from_kernel =PERF_IP_FLAG_SYSCALLRET | +PERF_IP_FLAG_INTERRUPT ; + +if (!(sample->flags & return_from_kernel)) +return 0 ; + +/* Pop kernel stack */ +return thread_stack__pop_ks (thread, ts, sample, ref); + } + +if (!sample->ip)return 0 ;/* x86 retpoline 'return' doesn't match the stack */
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 3/43 perf thread-stack: Eliminate code duplicating thread_stack__pop_ks()
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Use new function thread_stack__pop_ks() in place of equivalent code.
--- tools/perf/util/thread-stack.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
tools/perf/util/thread-stack.c +6 -12
@@ -664,12 +664,9 @@ static int thread_stack__no_call_return(struct thread *thread,if (ip >= ks && addr < ks) {/* Return to userspace, so pop all kernel addresses */ -while (thread_stack__in_kernel (ts)) { - err =thread_stack__call_return (thread, ts, --ts->cnt, - tm, ref, true); -if (err) -return err; - } + err =thread_stack__pop_ks (thread, ts, sample, ref); +if (err) +return err;/* If the stack is empty, push the userspace address */ if (!ts->cnt) {
@@ -679,12 +676,9 @@ static int thread_stack__no_call_return(struct thread *thread, } }else if (thread_stack__in_kernel (ts) && ip < ks) {/* Return to userspace, so pop all kernel addresses */ -while (thread_stack__in_kernel (ts)) { - err =thread_stack__call_return (thread, ts, --ts->cnt, - tm, ref, true); -if (err) -return err; - } + err =thread_stack__pop_ks (thread, ts, sample, ref); +if (err) +return err; }if (ts->cnt)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 4/43 perf tools: Increase MAX_NR_CPUS and MAX_CACHES
In reply to Arnaldo Carvalho de MeloFrom: Kyle Meyer <[email protected]>
Attempting to profile 1024 or more CPUs with perf causes two errors:
perf record -a
[ perf record: Woken up X times to write data ]
way too many cpu caches..
[ perf record: Captured and wrote X MB perf.data (X samples) ]
perf report -C 1024
Error: failed to set cpu bitmap
Requested CPU 1024 too large. Consider raising MAX_NR_CPUS
Increasing MAX_NR_CPUS from 1024 to 2048 and redefining MAX_CACHES as MAX_NR_CPUS * 4 returns normal functionality to perf:
perf record -a
[ perf record: Woken up X times to write data ]
[ perf record: Captured and wrote X MB perf.data (X samples) ]
perf report -C 1024
...
--- tools/perf/perf.h | 2 +- tools/perf/util/header.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/perf.h +1 -1
@@ -26,7 +26,7 @@ static inline unsigned long long rdclock(void) }#ifndef MAX_NR_CPUS -#define MAX_NR_CPUS 1024 +#define MAX_NR_CPUS 2048#endif extern const char *input_name;
tools/perf/util/header.c +1 -1
@@ -1121,7 +1121,7 @@ static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp)return 0 ; } -#define MAX_CACHES 2000 +#define MAX_CACHES (MAX_NR_CPUS * 4)static int write_cache (struct feat_fd *ff,struct perf_evlist *evlist__maybe_unused )
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 5/43 perf intel-pt: Decoder to output CBR changes immediately
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The core-to-bus ratio (CBR) provides the CPU frequency. With branches enabled, the decoder was outputting CBR changes only when there was a branch. That loses the correct time of the change if the trace is not in context (e.g. not tracing kernel space). Change to output the CBR change immediately.
--- .../util/intel-pt-decoder/intel-pt-decoder.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +6 -10
@@ -2015,16 +2015,8 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)case INTEL_PT_CBR :intel_pt_calc_cbr (decoder); -if (!decoder->branch_enable && - decoder->cbr != decoder->cbr_seen) { - decoder->cbr_seen = decoder->cbr; - decoder->state.type =INTEL_PT_CBR_CHG ; - decoder->state.from_ip = decoder->ip; - decoder->state.to_ip =0 ; - decoder->state.cbr_payload = - decoder->packet.payload; +if (decoder->cbr != decoder->cbr_seen)return 0 ; - }break ;case INTEL_PT_MODE_EXEC :
@@ -2626,8 +2618,12 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) decoder->sample_tot_cyc_cnt = decoder->tot_cyc_cnt; }else { decoder->state.err =0 ; -if (decoder->cbr != decoder->cbr_seen && decoder->state.type) { +if (decoder->cbr != decoder->cbr_seen) { decoder->cbr_seen = decoder->cbr; +if (!decoder->state.type) { + decoder->state.from_ip = decoder->ip; + decoder->state.to_ip =0 ; + } decoder->state.type |=INTEL_PT_CBR_CHG ; decoder->state.cbr_payload = decoder->cbr_payload; }
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 6/43 perf intel-pt: Cater for CBR change in PSB+
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
PSB+ provides status information only so the core-to-bus ratio (CBR) in PSB+ will not have changed from its previous value. However, cater for the possibility of a another CBR change that gets caught up in the PSB+ anyway.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +7 -0
@@ -1975,6 +1975,13 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder) goto next;if (err)return err; +/* +* PSB+ CBR will not have changed but cater for the +* possibility of another CBR change that gets caught up +* in the PSB+. +*/ +if (decoder->cbr != decoder->cbr_seen) +return 0 ;break ;case INTEL_PT_PIP :
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 7/43 perf intel-pt: Add CBR value to decoder state
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
For convenience, add the core-to-bus ratio (CBR) value to the decoder state.
--- tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + tools/perf/util/intel-pt-decoder/intel-pt-decoder.h | 1 + 2 files changed, 2 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
@@ -2633,6 +2633,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) } decoder->state.type |=INTEL_PT_CBR_CHG ; decoder->state.cbr_payload = decoder->cbr_payload; + decoder->state.cbr = decoder->cbr; }if (intel_pt_sample_time (decoder->pkt_state)) {intel_pt_update_sample_time (decoder);
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +1 -0
@@ -213,6 +213,7 @@ struct intel_pt_state {uint64_t pwre_payload;uint64_t pwrx_payload;uint64_t cbr_payload; +uint32_t cbr;uint32_t flags;enum intel_pt_insn_op insn_op;int insn_len;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 8/43 perf intel-pt: Synthesize CBR events when last seen value changes
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The first core-to-bus ratio (CBR) event will not be shown if --itrace 's' option (skip initial number of events) is used, nor if time intervals are specified that do not include the start of tracing. Change the logic to record the last CBR value seen by the user, and synthesize CBR events whenever that changes.
--- tools/perf/util/intel-pt.c | 65 ++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 24 deletions(-)
tools/perf/util/intel-pt.c +41 -24
@@ -171,6 +171,7 @@ struct intel_pt_queue {u64 last_in_cyc_cnt;u64 last_br_insn_cnt;u64 last_br_cyc_cnt; +unsigned int cbr_seen;char insn[INTEL_PT_INSN_BUF_SZ ]; };
@@ -1052,6 +1053,8 @@ static int intel_pt_setup_queue(struct intel_pt *pt, ptq->cpu = queue->cpu; ptq->tid = queue->tid; + ptq->cbr_seen =UINT_MAX ; +if (pt->sampling_mode && !pt->snapshot_mode && pt->timeless_decoding) ptq->step_through_buffers = true;
@@ -1184,6 +1187,17 @@ static inline bool intel_pt_skip_event(struct intel_pt *pt) pt->num_events++ < pt->synth_opts.initial_skip; } +/* +* Cannot count CBR as skipped because it won't go away until cbr == cbr_seen. +* Also ensure CBR is first non-skipped event by allowing for 4 more samples +* from this decoder state. +*/ +static inline bool intel_pt_skip_cbr_event (struct intel_pt *pt) +{ +return pt->synth_opts.initial_skip && + pt->num_events +4 < pt->synth_opts.initial_skip; +} +static void intel_pt_prep_a_sample (struct intel_pt_queue *ptq,union perf_event *event,struct perf_sample *sample)
@@ -1429,9 +1443,11 @@ static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)struct perf_synth_intel_cbr raw;u32 flags; -if (intel_pt_skip_event (pt)) +if (intel_pt_skip_cbr_event (pt))return 0 ; + ptq->cbr_seen = ptq->state->cbr; +intel_pt_prep_p_sample (pt, ptq, event, &sample); sample.id = ptq->pt->cbr_id;
@@ -1868,8 +1884,7 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip) }#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \ - INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \ - INTEL_PT_CBR_CHG) + INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT)static int intel_pt_sample (struct intel_pt_queue *ptq) {
@@ -1901,31 +1916,33 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)return err; } -if (pt->sample_pwr_events && (state->type &INTEL_PT_PWR_EVT )) { -if (state->type &INTEL_PT_CBR_CHG ) { +if (pt->sample_pwr_events) { +if (ptq->state->cbr != ptq->cbr_seen) { err =intel_pt_synth_cbr_sample (ptq);if (err)return err; } -if (state->type &INTEL_PT_MWAIT_OP ) { - err =intel_pt_synth_mwait_sample (ptq); -if (err) -return err; - } -if (state->type &INTEL_PT_PWR_ENTRY ) { - err =intel_pt_synth_pwre_sample (ptq); -if (err) -return err; - } -if (state->type &INTEL_PT_EX_STOP ) { - err =intel_pt_synth_exstop_sample (ptq); -if (err) -return err; - } -if (state->type &INTEL_PT_PWR_EXIT ) { - err =intel_pt_synth_pwrx_sample (ptq); -if (err) -return err; +if (state->type &INTEL_PT_PWR_EVT ) { +if (state->type &INTEL_PT_MWAIT_OP ) { + err =intel_pt_synth_mwait_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_ENTRY ) { + err =intel_pt_synth_pwre_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_EX_STOP ) { + err =intel_pt_synth_exstop_sample (ptq); +if (err) +return err; + } +if (state->type &INTEL_PT_PWR_EXIT ) { + err =intel_pt_synth_pwrx_sample (ptq); +if (err) +return err; + } } }
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 9/43 perf db-export: Export synth events
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Synthesized events are samples but with architecture-specific data stored in sample->raw_data. They are identified by attribute type PERF_TYPE_SYNTH. Add a function to export them.
--- .../scripting-engines/trace-event-python.c | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +44 -2
@@ -112,6 +112,7 @@ struct tables {PyObject *sample_handler;PyObject *call_path_handler;PyObject *call_return_handler; +PyObject *synth_handler;bool db_export_mode; };
@@ -947,6 +948,12 @@ static int tuple_set_string(PyObject *t, unsigned int pos, const char *s)return PyTuple_SetItem (t, pos,_PyUnicode_FromString (s)); } +static int tuple_set_bytes (PyObject *t,unsigned int pos,void *bytes, +unsigned int sz) +{ +return PyTuple_SetItem (t, pos,_PyBytes_FromStringAndSize (bytes, sz)); +} +static int python_export_evsel (struct db_export *dbe,struct perf_evsel *evsel) { struct tables *tables = container_of(dbe, struct tables, dbe);
@@ -1105,8 +1112,8 @@ static int python_export_branch_type(struct db_export *dbe, u32 branch_type,return 0 ; } -static int python_export_sample (struct db_export *dbe, -struct export_sample *es) +static void python_export_sample_table (struct db_export *dbe, +struct export_sample *es) { struct tables *tables = container_of(dbe, struct tables, dbe);PyObject *t;
@@ -1141,6 +1148,33 @@ static int python_export_sample(struct db_export *dbe,call_object (tables->sample_handler, t,"sample_table" );Py_DECREF (t); +} + +static void python_export_synth (struct db_export *dbe,struct export_sample *es) +{ + struct tables *tables = container_of(dbe, struct tables, dbe); +PyObject *t; + + t =tuple_new (3 ); + +tuple_set_u64 (t,0 , es->db_id); +tuple_set_u64 (t,1 , es->evsel->attr.config); +tuple_set_bytes (t,2 , es->sample->raw_data, es->sample->raw_size); + +call_object (tables->synth_handler, t,"synth_data" ); + +Py_DECREF (t); +} + +static int python_export_sample (struct db_export *dbe, +struct export_sample *es) +{ + struct tables *tables = container_of(dbe, struct tables, dbe); + +python_export_sample_table (dbe, es); + +if (es->evsel->attr.type ==PERF_TYPE_SYNTH && tables->synth_handler) +python_export_synth (dbe, es);return 0 ; }
@@ -1477,6 +1511,14 @@ static void set_table_handlers(struct tables *tables)SET_TABLE_HANDLER (sample);SET_TABLE_HANDLER (call_path);SET_TABLE_HANDLER (call_return); + +/* +* Synthesized events are samples but with architecture-specific data +* stored in sample->raw_data. They are exported via +* python_export_sample() and consequently do not need a separate export +* callback. +*/ + tables->synth_handler =get_handler ("synth_data" ); }#if PY_MAJOR_VERSION <3
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 10/43 perf scripts python: export-to-sqlite.py: Export Intel PT power and ptwrite events
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The format of synthesized events is determined by the attribute config. For the formats for Intel PT power and ptwrite events, create tables and populate them when the synth_data handler is called. If the tables remain empty, drop them at the end.
The tables and views, including a combined power_events_view, will display automatically from the tables menu of the exported exported-sql-viewer.py script.
Note, currently only Atoms since Gemini Lake have support for ptwrite and mwait, pwre, exstop and pwrx, but all Intel PT implementations support cbr.
--- tools/perf/scripts/python/export-to-sqlite.py | 239 ++++++++++++++++++ 1 file changed, 239 insertions(+)
tools/perf/scripts/python/export-to-sqlite.py +239 -0
@@ -271,6 +271,38 @@ if perf_db_export_calls: 'insn_count bigint,' 'cyc_count bigint)') +do_query(query, 'CREATE TABLE ptwrite (' + 'id integer NOT NULL PRIMARY KEY,' + 'payload bigint,' + 'exact_ip integer)') + +do_query(query, 'CREATE TABLE cbr (' + 'id integer NOT NULL PRIMARY KEY,' + 'cbr integer,' + 'mhz integer,' + 'percent integer)') + +do_query(query, 'CREATE TABLE mwait (' + 'id integer NOT NULL PRIMARY KEY,' + 'hints integer,' + 'extensions integer)') + +do_query(query, 'CREATE TABLE pwre (' + 'id integer NOT NULL PRIMARY KEY,' + 'cstate integer,' + 'subcstate integer,' + 'hw integer)') + +do_query(query, 'CREATE TABLE exstop (' + 'id integer NOT NULL PRIMARY KEY,' + 'exact_ip integer)') + +do_query(query, 'CREATE TABLE pwrx (' + 'id integer NOT NULL PRIMARY KEY,' + 'deepest_cstate integer,' + 'last_cstate integer,' + 'wake_reason integer)') + # printf was added to sqlite in version 3.8.3 sqlite_has_printf = False try:
@@ -399,6 +431,102 @@ do_query(query, 'CREATE VIEW samples_view AS ' 'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC' ' FROM samples') +do_query(query, 'CREATE VIEW ptwrite_view AS ' + 'SELECT ' + 'ptwrite.id,' + 'time,' + 'cpu,' + + emit_to_hex('payload') + ' AS payload_hex,' + 'CASE WHEN exact_ip=0 THEN \'False\' ELSE \'True\' END AS exact_ip' + ' FROM ptwrite' + ' INNER JOIN samples ON samples.id = ptwrite.id') + +do_query(query, 'CREATE VIEW cbr_view AS ' + 'SELECT ' + 'cbr.id,' + 'time,' + 'cpu,' + 'cbr,' + 'mhz,' + 'percent' + ' FROM cbr' + ' INNER JOIN samples ON samples.id = cbr.id') + +do_query(query, 'CREATE VIEW mwait_view AS ' + 'SELECT ' + 'mwait.id,' + 'time,' + 'cpu,' + + emit_to_hex('hints') + ' AS hints_hex,' + + emit_to_hex('extensions') + ' AS extensions_hex' + ' FROM mwait' + ' INNER JOIN samples ON samples.id = mwait.id') + +do_query(query, 'CREATE VIEW pwre_view AS ' + 'SELECT ' + 'pwre.id,' + 'time,' + 'cpu,' + 'cstate,' + 'subcstate,' + 'CASE WHEN hw=0 THEN \'False\' ELSE \'True\' END AS hw' + ' FROM pwre' + ' INNER JOIN samples ON samples.id = pwre.id') + +do_query(query, 'CREATE VIEW exstop_view AS ' + 'SELECT ' + 'exstop.id,' + 'time,' + 'cpu,' + 'CASE WHEN exact_ip=0 THEN \'False\' ELSE \'True\' END AS exact_ip' + ' FROM exstop' + ' INNER JOIN samples ON samples.id = exstop.id') + +do_query(query, 'CREATE VIEW pwrx_view AS ' + 'SELECT ' + 'pwrx.id,' + 'time,' + 'cpu,' + 'deepest_cstate,' + 'last_cstate,' + 'CASE WHEN wake_reason=1 THEN \'Interrupt\'' + ' WHEN wake_reason=2 THEN \'Timer Deadline\'' + ' WHEN wake_reason=4 THEN \'Monitored Address\'' + ' WHEN wake_reason=8 THEN \'HW\'' + ' ELSE wake_reason ' + 'END AS wake_reason' + ' FROM pwrx' + ' INNER JOIN samples ON samples.id = pwrx.id') + +do_query(query, 'CREATE VIEW power_events_view AS ' + 'SELECT ' + 'samples.id,' + 'time,' + 'cpu,' + 'selected_events.name AS event,' + 'CASE WHEN selected_events.name=\'cbr\' THEN (SELECT cbr FROM cbr WHERE cbr.id = samples.id) ELSE "" END AS cbr,' + 'CASE WHEN selected_events.name=\'cbr\' THEN (SELECT mhz FROM cbr WHERE cbr.id = samples.id) ELSE "" END AS mhz,' + 'CASE WHEN selected_events.name=\'cbr\' THEN (SELECT percent FROM cbr WHERE cbr.id = samples.id) ELSE "" END AS percent,' + 'CASE WHEN selected_events.name=\'mwait\' THEN (SELECT ' + emit_to_hex('hints') + ' FROM mwait WHERE mwait.id = samples.id) ELSE "" END AS hints_hex,' + 'CASE WHEN selected_events.name=\'mwait\' THEN (SELECT ' + emit_to_hex('extensions') + ' FROM mwait WHERE mwait.id = samples.id) ELSE "" END AS extensions_hex,' + 'CASE WHEN selected_events.name=\'pwre\' THEN (SELECT cstate FROM pwre WHERE pwre.id = samples.id) ELSE "" END AS cstate,' + 'CASE WHEN selected_events.name=\'pwre\' THEN (SELECT subcstate FROM pwre WHERE pwre.id = samples.id) ELSE "" END AS subcstate,' + 'CASE WHEN selected_events.name=\'pwre\' THEN (SELECT hw FROM pwre WHERE pwre.id = samples.id) ELSE "" END AS hw,' + 'CASE WHEN selected_events.name=\'exstop\' THEN (SELECT exact_ip FROM exstop WHERE exstop.id = samples.id) ELSE "" END AS exact_ip,' + 'CASE WHEN selected_events.name=\'pwrx\' THEN (SELECT deepest_cstate FROM pwrx WHERE pwrx.id = samples.id) ELSE "" END AS deepest_cstate,' + 'CASE WHEN selected_events.name=\'pwrx\' THEN (SELECT last_cstate FROM pwrx WHERE pwrx.id = samples.id) ELSE "" END AS last_cstate,' + 'CASE WHEN selected_events.name=\'pwrx\' THEN (SELECT ' + 'CASE WHEN wake_reason=1 THEN \'Interrupt\'' + ' WHEN wake_reason=2 THEN \'Timer Deadline\'' + ' WHEN wake_reason=4 THEN \'Monitored Address\'' + ' WHEN wake_reason=8 THEN \'HW\'' + ' ELSE wake_reason ' + 'END' + ' FROM pwrx WHERE pwrx.id = samples.id) ELSE "" END AS wake_reason' + ' FROM samples' + ' INNER JOIN selected_events ON selected_events.id = evsel_id' + ' WHERE selected_events.name IN (\'cbr\',\'mwait\',\'exstop\',\'pwre\',\'pwrx\')') + do_query(query, 'END TRANSACTION') evsel_query = QSqlQuery(db)
@@ -428,6 +556,18 @@ if perf_db_export_calls or perf_db_export_callchains: if perf_db_export_calls: call_query = QSqlQuery(db) call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") +ptwrite_query = QSqlQuery(db) +ptwrite_query.prepare("INSERT INTO ptwrite VALUES (?, ?, ?)") +cbr_query = QSqlQuery(db) +cbr_query.prepare("INSERT INTO cbr VALUES (?, ?, ?, ?)") +mwait_query = QSqlQuery(db) +mwait_query.prepare("INSERT INTO mwait VALUES (?, ?, ?)") +pwre_query = QSqlQuery(db) +pwre_query.prepare("INSERT INTO pwre VALUES (?, ?, ?, ?)") +exstop_query = QSqlQuery(db) +exstop_query.prepare("INSERT INTO exstop VALUES (?, ?)") +pwrx_query = QSqlQuery(db) +pwrx_query.prepare("INSERT INTO pwrx VALUES (?, ?, ?, ?)") def trace_begin(): printdate("Writing records...")
@@ -446,6 +586,16 @@ def trace_begin(): unhandled_count = 0 +def is_table_empty(table_name): + do_query(query, 'SELECT * FROM ' + table_name + ' LIMIT 1'); + if query.next(): + return False + return True + +def drop(table_name): + do_query(query, 'DROP VIEW ' + table_name + '_view'); + do_query(query, 'DROP TABLE ' + table_name); + def trace_end(): do_query(query, 'END TRANSACTION')
@@ -454,6 +604,18 @@ def trace_end(): do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') + printdate("Dropping unused tables") + if is_table_empty("ptwrite"): + drop("ptwrite") + if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"): + drop("mwait") + drop("pwre") + drop("exstop") + drop("pwrx") + do_query(query, 'DROP VIEW power_events_view'); + if is_table_empty("cbr"): + drop("cbr") + if (unhandled_count): printdate("Warning: ", unhandled_count, " unhandled events") printdate("Done")
@@ -509,3 +671,80 @@ def call_path_table(*x): def call_return_table(*x): bind_exec(call_query, 14, x) + +def ptwrite(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + flags = data[0] + payload = data[1] + exact_ip = flags & 1 + ptwrite_query.addBindValue(str(id)) + ptwrite_query.addBindValue(str(payload)) + ptwrite_query.addBindValue(str(exact_ip)) + do_query_(ptwrite_query) + +def cbr(id, raw_buf): + data = struct.unpack_from("<BBBBII", raw_buf) + cbr = data[0] + MHz = (data[4] + 500) / 1000 + percent = ((cbr * 1000 / data[2]) + 5) / 10 + cbr_query.addBindValue(str(id)) + cbr_query.addBindValue(str(cbr)) + cbr_query.addBindValue(str(MHz)) + cbr_query.addBindValue(str(percent)) + do_query_(cbr_query) + +def mwait(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + payload = data[1] + hints = payload & 0xff + extensions = (payload >> 32) & 0x3 + mwait_query.addBindValue(str(id)) + mwait_query.addBindValue(str(hints)) + mwait_query.addBindValue(str(extensions)) + do_query_(mwait_query) + +def pwre(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + payload = data[1] + hw = (payload >> 7) & 1 + cstate = (payload >> 12) & 0xf + subcstate = (payload >> 8) & 0xf + pwre_query.addBindValue(str(id)) + pwre_query.addBindValue(str(cstate)) + pwre_query.addBindValue(str(subcstate)) + pwre_query.addBindValue(str(hw)) + do_query_(pwre_query) + +def exstop(id, raw_buf): + data = struct.unpack_from("<I", raw_buf) + flags = data[0] + exact_ip = flags & 1 + exstop_query.addBindValue(str(id)) + exstop_query.addBindValue(str(exact_ip)) + do_query_(exstop_query) + +def pwrx(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + payload = data[1] + deepest_cstate = payload & 0xf + last_cstate = (payload >> 4) & 0xf + wake_reason = (payload >> 8) & 0xf + pwrx_query.addBindValue(str(id)) + pwrx_query.addBindValue(str(deepest_cstate)) + pwrx_query.addBindValue(str(last_cstate)) + pwrx_query.addBindValue(str(wake_reason)) + do_query_(pwrx_query) + +def synth_data(id, config, raw_buf, *x): + if config == 0: + ptwrite(id, raw_buf) + elif config == 1: + mwait(id, raw_buf) + elif config == 2: + pwre(id, raw_buf) + elif config == 3: + exstop(id, raw_buf) + elif config == 4: + pwrx(id, raw_buf) + elif config == 5: + cbr(id, raw_buf)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 11/43 perf scripts python: export-to-postgresql.py: Export Intel PT power and ptwrite events
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
The format of synthesized events is determined by the attribute config. For the formats for Intel PT power and ptwrite events, create tables and populate them when the synth_data handler is called. If the tables remain empty, drop them at the end.
The tables and views, including a combined power_events_view, will display automatically from the tables menu of the exported exported-sql-viewer.py script.
Note, currently only Atoms since Gemini Lake have support for ptwrite and mwait, pwre, exstop and pwrx, but all Intel PT implementations support cbr.
--- .../scripts/python/export-to-postgresql.py | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+)
tools/perf/scripts/python/export-to-postgresql.py +251 -0
@@ -447,6 +447,38 @@ if perf_db_export_calls: 'insn_count bigint,' 'cyc_count bigint)') +do_query(query, 'CREATE TABLE ptwrite (' + 'id bigint NOT NULL,' + 'payload bigint,' + 'exact_ip boolean)') + +do_query(query, 'CREATE TABLE cbr (' + 'id bigint NOT NULL,' + 'cbr integer,' + 'mhz integer,' + 'percent integer)') + +do_query(query, 'CREATE TABLE mwait (' + 'id bigint NOT NULL,' + 'hints integer,' + 'extensions integer)') + +do_query(query, 'CREATE TABLE pwre (' + 'id bigint NOT NULL,' + 'cstate integer,' + 'subcstate integer,' + 'hw boolean)') + +do_query(query, 'CREATE TABLE exstop (' + 'id bigint NOT NULL,' + 'exact_ip boolean)') + +do_query(query, 'CREATE TABLE pwrx (' + 'id bigint NOT NULL,' + 'deepest_cstate integer,' + 'last_cstate integer,' + 'wake_reason integer)') + do_query(query, 'CREATE VIEW machines_view AS ' 'SELECT ' 'id,'
@@ -561,6 +593,104 @@ do_query(query, 'CREATE VIEW samples_view AS ' 'CASE WHEN cyc_count=0 THEN CAST(0 AS NUMERIC(20, 2)) ELSE CAST((CAST(insn_count AS FLOAT) / cyc_count) AS NUMERIC(20, 2)) END AS IPC' ' FROM samples') +do_query(query, 'CREATE VIEW ptwrite_view AS ' + 'SELECT ' + 'ptwrite.id,' + 'time,' + 'cpu,' + 'to_hex(payload) AS payload_hex,' + 'CASE WHEN exact_ip=FALSE THEN \'False\' ELSE \'True\' END AS exact_ip' + ' FROM ptwrite' + ' INNER JOIN samples ON samples.id = ptwrite.id') + +do_query(query, 'CREATE VIEW cbr_view AS ' + 'SELECT ' + 'cbr.id,' + 'time,' + 'cpu,' + 'cbr,' + 'mhz,' + 'percent' + ' FROM cbr' + ' INNER JOIN samples ON samples.id = cbr.id') + +do_query(query, 'CREATE VIEW mwait_view AS ' + 'SELECT ' + 'mwait.id,' + 'time,' + 'cpu,' + 'to_hex(hints) AS hints_hex,' + 'to_hex(extensions) AS extensions_hex' + ' FROM mwait' + ' INNER JOIN samples ON samples.id = mwait.id') + +do_query(query, 'CREATE VIEW pwre_view AS ' + 'SELECT ' + 'pwre.id,' + 'time,' + 'cpu,' + 'cstate,' + 'subcstate,' + 'CASE WHEN hw=FALSE THEN \'False\' ELSE \'True\' END AS hw' + ' FROM pwre' + ' INNER JOIN samples ON samples.id = pwre.id') + +do_query(query, 'CREATE VIEW exstop_view AS ' + 'SELECT ' + 'exstop.id,' + 'time,' + 'cpu,' + 'CASE WHEN exact_ip=FALSE THEN \'False\' ELSE \'True\' END AS exact_ip' + ' FROM exstop' + ' INNER JOIN samples ON samples.id = exstop.id') + +do_query(query, 'CREATE VIEW pwrx_view AS ' + 'SELECT ' + 'pwrx.id,' + 'time,' + 'cpu,' + 'deepest_cstate,' + 'last_cstate,' + 'CASE WHEN wake_reason=1 THEN \'Interrupt\'' + ' WHEN wake_reason=2 THEN \'Timer Deadline\'' + ' WHEN wake_reason=4 THEN \'Monitored Address\'' + ' WHEN wake_reason=8 THEN \'HW\'' + ' ELSE CAST ( wake_reason AS VARCHAR(2) )' + 'END AS wake_reason' + ' FROM pwrx' + ' INNER JOIN samples ON samples.id = pwrx.id') + +do_query(query, 'CREATE VIEW power_events_view AS ' + 'SELECT ' + 'samples.id,' + 'samples.time,' + 'samples.cpu,' + 'selected_events.name AS event,' + 'FORMAT(\'%6s\', cbr.cbr) AS cbr,' + 'FORMAT(\'%6s\', cbr.mhz) AS MHz,' + 'FORMAT(\'%5s\', cbr.percent) AS percent,' + 'to_hex(mwait.hints) AS hints_hex,' + 'to_hex(mwait.extensions) AS extensions_hex,' + 'FORMAT(\'%3s\', pwre.cstate) AS cstate,' + 'FORMAT(\'%3s\', pwre.subcstate) AS subcstate,' + 'CASE WHEN pwre.hw=FALSE THEN \'False\' WHEN pwre.hw=TRUE THEN \'True\' ELSE NULL END AS hw,' + 'CASE WHEN exstop.exact_ip=FALSE THEN \'False\' WHEN exstop.exact_ip=TRUE THEN \'True\' ELSE NULL END AS exact_ip,' + 'FORMAT(\'%3s\', pwrx.deepest_cstate) AS deepest_cstate,' + 'FORMAT(\'%3s\', pwrx.last_cstate) AS last_cstate,' + 'CASE WHEN pwrx.wake_reason=1 THEN \'Interrupt\'' + ' WHEN pwrx.wake_reason=2 THEN \'Timer Deadline\'' + ' WHEN pwrx.wake_reason=4 THEN \'Monitored Address\'' + ' WHEN pwrx.wake_reason=8 THEN \'HW\'' + ' ELSE FORMAT(\'%2s\', pwrx.wake_reason)' + 'END AS wake_reason' + ' FROM cbr' + ' FULL JOIN mwait ON mwait.id = cbr.id' + ' FULL JOIN pwre ON pwre.id = cbr.id' + ' FULL JOIN exstop ON exstop.id = cbr.id' + ' FULL JOIN pwrx ON pwrx.id = cbr.id' + ' INNER JOIN samples ON samples.id = coalesce(cbr.id, mwait.id, pwre.id, exstop.id, pwrx.id)' + ' INNER JOIN selected_events ON selected_events.id = samples.evsel_id' + ' ORDER BY samples.id') file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0) file_trailer = b"\377\377"
@@ -620,6 +750,12 @@ if perf_db_export_calls or perf_db_export_callchains: call_path_file = open_output_file("call_path_table.bin") if perf_db_export_calls: call_file = open_output_file("call_table.bin") +ptwrite_file = open_output_file("ptwrite_table.bin") +cbr_file = open_output_file("cbr_table.bin") +mwait_file = open_output_file("mwait_table.bin") +pwre_file = open_output_file("pwre_table.bin") +exstop_file = open_output_file("exstop_table.bin") +pwrx_file = open_output_file("pwrx_table.bin") def trace_begin(): printdate("Writing to intermediate files...")
@@ -637,6 +773,16 @@ def trace_begin(): unhandled_count = 0 +def is_table_empty(table_name): + do_query(query, 'SELECT * FROM ' + table_name + ' LIMIT 1'); + if query.next(): + return False + return True + +def drop(table_name): + do_query(query, 'DROP VIEW ' + table_name + '_view'); + do_query(query, 'DROP TABLE ' + table_name); + def trace_end(): printdate("Copying to database...") copy_output_file(evsel_file, "selected_events")
@@ -652,6 +798,12 @@ def trace_end(): copy_output_file(call_path_file, "call_paths") if perf_db_export_calls: copy_output_file(call_file, "calls") + copy_output_file(ptwrite_file, "ptwrite") + copy_output_file(cbr_file, "cbr") + copy_output_file(mwait_file, "mwait") + copy_output_file(pwre_file, "pwre") + copy_output_file(exstop_file, "exstop") + copy_output_file(pwrx_file, "pwrx") printdate("Removing intermediate files...") remove_output_file(evsel_file)
@@ -667,6 +819,12 @@ def trace_end(): remove_output_file(call_path_file) if perf_db_export_calls: remove_output_file(call_file) + remove_output_file(ptwrite_file) + remove_output_file(cbr_file) + remove_output_file(mwait_file) + remove_output_file(pwre_file) + remove_output_file(exstop_file) + remove_output_file(pwrx_file) os.rmdir(output_dir_name) printdate("Adding primary keys") do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
@@ -682,6 +840,12 @@ def trace_end(): do_query(query, 'ALTER TABLE call_paths ADD PRIMARY KEY (id)') if perf_db_export_calls: do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE ptwrite ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE cbr ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE mwait ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE pwre ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE exstop ADD PRIMARY KEY (id)') + do_query(query, 'ALTER TABLE pwrx ADD PRIMARY KEY (id)') printdate("Adding foreign keys") do_query(query, 'ALTER TABLE threads '
@@ -717,6 +881,30 @@ def trace_end(): 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)') do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') + do_query(query, 'ALTER TABLE ptwrite ' + 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE cbr ' + 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE mwait ' + 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE pwre ' + 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE exstop ' + 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + do_query(query, 'ALTER TABLE pwrx ' + 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') + + printdate("Dropping unused tables") + if is_table_empty("ptwrite"): + drop("ptwrite") + if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"): + drop("mwait") + drop("pwre") + drop("exstop") + drop("pwrx") + do_query(query, 'DROP VIEW power_events_view'); + if is_table_empty("cbr"): + drop("cbr") if (unhandled_count): printdate("Warning: ", unhandled_count, " unhandled events")
@@ -800,3 +988,66 @@ def call_return_table(cr_id, thread_id, comm_id, call_path_id, call_time, return fmt = "!hiqiqiqiqiqiqiqiqiqiqiiiqiqiq" value = struct.pack(fmt, 14, 8, cr_id, 8, thread_id, 8, comm_id, 8, call_path_id, 8, call_time, 8, return_time, 8, branch_count, 8, call_id, 8, return_id, 8, parent_call_path_id, 4, flags, 8, parent_id, 8, insn_cnt, 8, cyc_cnt) call_file.write(value) + +def ptwrite(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + flags = data[0] + payload = data[1] + exact_ip = flags & 1 + value = struct.pack("!hiqiqiB", 3, 8, id, 8, payload, 1, exact_ip) + ptwrite_file.write(value) + +def cbr(id, raw_buf): + data = struct.unpack_from("<BBBBII", raw_buf) + cbr = data[0] + MHz = (data[4] + 500) / 1000 + percent = ((cbr * 1000 / data[2]) + 5) / 10 + value = struct.pack("!hiqiiiiii", 4, 8, id, 4, cbr, 4, MHz, 4, percent) + cbr_file.write(value) + +def mwait(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + payload = data[1] + hints = payload & 0xff + extensions = (payload >> 32) & 0x3 + value = struct.pack("!hiqiiii", 3, 8, id, 4, hints, 4, extensions) + mwait_file.write(value) + +def pwre(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + payload = data[1] + hw = (payload >> 7) & 1 + cstate = (payload >> 12) & 0xf + subcstate = (payload >> 8) & 0xf + value = struct.pack("!hiqiiiiiB", 4, 8, id, 4, cstate, 4, subcstate, 1, hw) + pwre_file.write(value) + +def exstop(id, raw_buf): + data = struct.unpack_from("<I", raw_buf) + flags = data[0] + exact_ip = flags & 1 + value = struct.pack("!hiqiB", 2, 8, id, 1, exact_ip) + exstop_file.write(value) + +def pwrx(id, raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + payload = data[1] + deepest_cstate = payload & 0xf + last_cstate = (payload >> 4) & 0xf + wake_reason = (payload >> 8) & 0xf + value = struct.pack("!hiqiiiiii", 4, 8, id, 4, deepest_cstate, 4, last_cstate, 4, wake_reason) + pwrx_file.write(value) + +def synth_data(id, config, raw_buf, *x): + if config == 0: + ptwrite(id, raw_buf) + elif config == 1: + mwait(id, raw_buf) + elif config == 2: + pwre(id, raw_buf) + elif config == 3: + exstop(id, raw_buf) + elif config == 4: + pwrx(id, raw_buf) + elif config == 5: + cbr(id, raw_buf)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 12/43 perf ctype: Remove unused 'graph_line' variable
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Not being used at all anywhere.
--- tools/perf/util/ctype.c | 4 ---- tools/perf/util/sane_ctype.h | 1 - 2 files changed, 5 deletions(-)
tools/perf/util/ctype.c +0 -4
@@ -31,10 +31,6 @@ unsigned char sane_ctype[256] = {/* Nothing in the 128.. range */ }; -const char *graph_line = -"_____________________________________________________________________" -"_____________________________________________________________________" -"_____________________________________________________________________" ;const char *graph_dotted_line ="---------------------------------------------------------------------" "---------------------------------------------------------------------"
tools/perf/util/sane_ctype.h +0 -1
@@ -2,7 +2,6 @@#ifndef _PERF_SANE_CTYPE_H#define _PERF_SANE_CTYPE_H -extern const char *graph_line;extern const char *graph_dotted_line;extern const char *spaces;extern const char *dots;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 13/43 perf ui stdio: No need to use 'spaces' to left align
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We can just use the 'field width' for the %s used to print the alignment, this way we'll get the same result without requiring having a variable with just lots of space chars.
No way to do that for the dots tho, we still need that variable filled with dot chars.
# perf report --stdio --hierarchy > before # perf report --stdio --hierarchy > after # diff before after #
I.e. it continues as:
# perf report --stdio --hierarchy | head -15
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 107 of event 'cycles'
# Event count (approx.): 31378313
#
# Overhead Command / Shared Object / Symbol
# .............. ............................................
#
80.13% swapper
72.29% [kernel.vmlinux]
49.85% [k] intel_idle
9.05% [k] tick_nohz_next_event
#--- tools/perf/ui/stdio/hist.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/perf/ui/stdio/hist.c +7 -3
@@ -566,10 +566,14 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,static int print_hierarchy_indent (const char *sep,int indent,const char *line,FILE *fp) { +int width; +if (sep !=NULL || indent <2 )return 0 ; -return fprintf (fp,"%-.*s" , (indent -2 ) *HIERARCHY_INDENT , line); + width = (indent -2 ) *HIERARCHY_INDENT ; + +return fprintf (fp,"%-*.*s" , width, width, line); } static int hists__fprintf_hierarchy_headers(struct hists *hists,
@@ -587,7 +591,7 @@ static int hists__fprintf_hierarchy_headers(struct hists *hists, indent = hists->nr_hpp_node;/* preserve max indent depth for column headers */ -print_hierarchy_indent (sep, indent, spaces, fp); +print_hierarchy_indent (sep, indent," " , fp);/* the first hpp_list_node is for overhead columns */ fmt_node = list_first_entry(&hists->hpp_formats,
@@ -816,7 +820,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,if (!h->leaf && !hist_entry__has_hierarchy_children (h, min_pcnt)) {int depth = hists->nr_hpp_node + h->depth +1 ; -print_hierarchy_indent (sep, depth, spaces, fp); +print_hierarchy_indent (sep, depth," " , fp);fprintf (fp,"%*sno entry >= %.2f%%\n" , indent,"" , min_pcnt);if (max_rows && ++nr_rows >= max_rows)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 14/43 perf ctype: Remove now unused 'spaces' variable
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We can left justify just fine using the 'field width' modifier in %s printf, ditch this variable.
--- tools/perf/util/ctype.c | 4 ---- tools/perf/util/sane_ctype.h | 1 - 2 files changed, 5 deletions(-)
tools/perf/util/ctype.c +0 -4
@@ -35,10 +35,6 @@ const char *graph_dotted_line ="---------------------------------------------------------------------" "---------------------------------------------------------------------" "---------------------------------------------------------------------" ; -const char *spaces = -" " -" " -" " ;const char *dots ="....................................................................." "....................................................................."
tools/perf/util/sane_ctype.h +0 -1
@@ -3,7 +3,6 @@#define _PERF_SANE_CTYPE_Hextern const char *graph_dotted_line; -extern const char *spaces;extern const char *dots;/* Sane ctype - no locale, and works with signed chars */
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 15/43 perf string: Move 'dots' and 'graph_dotted_line' out of sane_ctype.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Those are not in that file in the git repo, lets move it from there so that we get that sane ctype code fully isolated to allow getting it in sync either with the git sources or better with the kernel sources (include/linux/ctype.h + lib/ctype.h), that way we can use check_headers.h to get notified when changes are made in the original code so that we can cherry-pick.
--- tools/perf/builtin-kmem.c | 1 + tools/perf/builtin-sched.c | 1 + tools/perf/builtin-top.c | 1 + tools/perf/util/ctype.c | 9 --------- tools/perf/util/evsel.c | 1 + tools/perf/util/sane_ctype.h | 3 --- tools/perf/util/string.c | 9 +++++++++ tools/perf/util/string2.h | 3 +++ 8 files changed, 16 insertions(+), 12 deletions(-)
tools/perf/builtin-kmem.c +1 -0
@@ -21,6 +21,7 @@#include "util/cpumap.h" #include "util/debug.h" +#include "util/string2.h" #include <linux/kernel.h> #include <linux/rbtree.h>
tools/perf/builtin-sched.c +1 -0
@@ -15,6 +15,7 @@#include "util/thread_map.h" #include "util/color.h" #include "util/stat.h" +#include "util/string2.h" #include "util/callchain.h" #include "util/time-utils.h"
tools/perf/builtin-top.c +1 -0
@@ -40,6 +40,7 @@#include "util/cpumap.h" #include "util/xyarray.h" #include "util/sort.h" +#include "util/string2.h" #include "util/term.h" #include "util/intlist.h" #include "util/parse-branch-options.h"
tools/perf/util/ctype.c +0 -9
@@ -30,12 +30,3 @@ unsigned char sane_ctype[256] = { A, A, A, A, A, A, A, A, A, A, A, R, R, P, P, 0, /* 112..127 */ /* Nothing in the 128.. range */ }; - -const char *graph_dotted_line = -"---------------------------------------------------------------------" -"---------------------------------------------------------------------" -"---------------------------------------------------------------------" ; -const char *dots = -"....................................................................." -"....................................................................." -"....................................................................." ;
tools/perf/util/evsel.c +1 -0
@@ -35,6 +35,7 @@#include "debug.h" #include "trace-event.h" #include "stat.h" +#include "string2.h" #include "memswap.h" #include "util/parse-branch-options.h"
tools/perf/util/sane_ctype.h +0 -3
@@ -2,9 +2,6 @@#ifndef _PERF_SANE_CTYPE_H#define _PERF_SANE_CTYPE_H -extern const char *graph_dotted_line; -extern const char *dots; -/* Sane ctype - no locale, and works with signed chars */ #undef isascii#undef isspace
tools/perf/util/string.c +9 -0
@@ -6,6 +6,15 @@#include "sane_ctype.h" +const char *graph_dotted_line = +"---------------------------------------------------------------------" +"---------------------------------------------------------------------" +"---------------------------------------------------------------------" ; +const char *dots = +"....................................................................." +"....................................................................." +"....................................................................." ; +#define K 1024LL/* * perf_atoll()
tools/perf/util/string2.h +3 -0
@@ -6,6 +6,9 @@#include <stddef.h> #include <string.h> +extern const char *graph_dotted_line; +extern const char *dots; +s64 perf_atoll (const char *str);char **argv_split (const char *str,int *argcp);void argv_free (char **argv);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 16/43 tools x86 machine: Add missing util.h to pick up 'page_size'
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We're getting it by sheer luck, add that util.h to get the 'page_size' definition.
--- tools/perf/arch/x86/util/machine.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/arch/x86/util/machine.c +1 -0
@@ -3,6 +3,7 @@#include <linux/string.h> #include <stdlib.h> +#include "../../util/util.h" #include "../../util/machine.h" #include "../../util/map.h" #include "../../util/symbol.h"
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 17/43 perf kallsyms: Adopt hex2u64 from tools/perf/util/util.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Just removing more stuff from tools/perf/, this is mostly used in the kallsyms parsing and in places in perf where kallsyms is involved, so we get it for free there.
With this we reduce a bit more util.h.
--- tools/lib/symbol/kallsyms.c | 13 +++++++++++++ tools/lib/symbol/kallsyms.h | 2 ++ tools/perf/util/util.c | 13 ------------- tools/perf/util/util.h | 1 - 4 files changed, 15 insertions(+), 14 deletions(-)
tools/lib/symbol/kallsyms.c +13 -0
@@ -16,6 +16,19 @@ bool kallsyms__is_function(char symbol_type)return symbol_type =='T' || symbol_type =='W' ; } +/* +* While we find nice hex chars, build a long_val. +* Return number of chars processed. +*/ +int hex2u64 (const char *ptr,u64 *long_val) +{ +char *p; + + *long_val =strtoull (ptr, &p,16 ); + +return p - ptr; +} +int kallsyms__parse (const char *filename,void *arg,int (*process_symbol)(void *arg,const char *name,char type,u64 start))
tools/lib/symbol/kallsyms.h +2 -0
@@ -18,6 +18,8 @@ static inline u8 kallsyms2elf_binding(char type)return isupper (type) ?STB_GLOBAL :STB_LOCAL ; } +int hex2u64 (const char *ptr,u64 *long_val); +u8 kallsyms2elf_type (char type);bool kallsyms__is_function (char symbol_type);
tools/perf/util/util.c +0 -13
@@ -434,19 +434,6 @@ size_t hex_width(u64 v)return n; } -/* -* While we find nice hex chars, build a long_val. -* Return number of chars processed. -*/ -int hex2u64 (const char *ptr,u64 *long_val) -{ -char *p; - - *long_val =strtoull (ptr, &p,16 ); - -return p - ptr; -} -int perf_event_paranoid (void ) {int value;
tools/perf/util/util.h +0 -1
@@ -43,7 +43,6 @@ ssize_t readn(int fd, void *buf, size_t n);ssize_t writen (int fd,const void *buf,size_t n);size_t hex_width (u64 v); -int hex2u64 (const char *ptr,u64 *val);extern unsigned int page_size;int __pure cacheline_size (void );
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 18/43 perf symbols: We need util.h in symbol-elf.c for zfree()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Continuing to untangle the headers, we're about to remove the old odd baggage that is tools/perf/util/include/linux/ctype.h.
--- tools/perf/util/symbol-elf.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/symbol-elf.c +1 -0
@@ -14,6 +14,7 @@#include "machine.h" #include "vdso.h" #include "debug.h" +#include "util.h" #include "sane_ctype.h" #include <symbol/kallsyms.h>
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 19/43 perf tools: Remove old baggage that is util/include/linux/ctype.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It was just including a ../util.h that wasn't even there:
$ cat tools/perf/util/include/linux/../util.h cat: tools/perf/util/include/linux/../util.h: No such file or directory $
This would make kallsyms.h get util.h somehow and then files including it would get util.h defined stuff, a mess, fix it.
--- tools/lib/symbol/kallsyms.h | 1 - tools/perf/util/include/linux/ctype.h | 1 - 2 files changed, 2 deletions(-) delete mode 100644 tools/perf/util/include/linux/ctype.h
tools/lib/symbol/kallsyms.h +0 -1
@@ -3,7 +3,6 @@#define __TOOLS_KALLSYMS_H_ 1#include <elf.h> -#include <linux/ctype.h> #include <linux/types.h> #ifndef KSYM_NAME_LEN
tools/perf/util/include/linux/ctype.h deleted +0 -1
@@ -1 +0,0 @@ -#include "../util.h"
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 20/43 perf tools: Add missing util.h to pick up 'page_size' variable
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Not to depend of getting it indirectly.
--- tools/perf/arch/arm/util/cs-etm.c | 1 + tools/perf/arch/x86/tests/intel-cqm.c | 1 + tools/perf/arch/x86/util/intel-pt.c | 1 + tools/perf/perf.c | 1 + tools/perf/util/machine.c | 1 + tools/perf/util/python.c | 1 + 6 files changed, 6 insertions(+)
tools/perf/arch/arm/util/cs-etm.c +1 -0
@@ -22,6 +22,7 @@#include "../../util/pmu.h" #include "../../util/thread_map.h" #include "../../util/cs-etm.h" +#include "../../util/util.h" #include <errno.h> #include <stdlib.h>
tools/perf/arch/x86/tests/intel-cqm.c +1 -0
@@ -6,6 +6,7 @@#include "evlist.h" #include "evsel.h" #include "arch-tests.h" +#include "util.h" #include <signal.h> #include <sys/mman.h>
tools/perf/arch/x86/util/intel-pt.c +1 -0
@@ -25,6 +25,7 @@#include "../../util/auxtrace.h" #include "../../util/tsc.h" #include "../../util/intel-pt.h" +#include "../../util/util.h" #define KiB (x) ((x) * 1024)#define MiB (x) ((x) * 1024 * 1024)
tools/perf/perf.c +1 -0
@@ -18,6 +18,7 @@#include "util/bpf-loader.h" #include "util/debug.h" #include "util/event.h" +#include "util/util.h" #include <api/fs/fs.h> #include <api/fs/tracing_path.h> #include <errno.h>
tools/perf/util/machine.c +1 -0
@@ -15,6 +15,7 @@#include "strlist.h" #include "thread.h" #include "vdso.h" +#include "util.h" #include <stdbool.h> #include <sys/types.h> #include <sys/stat.h>
tools/perf/util/python.c +1 -0
@@ -12,6 +12,7 @@#include "print_binary.h" #include "thread_map.h" #include "mmap.h" +#include "util.h" #if PY_MAJOR_VERSION <3 #define _PyUnicode_FromString (arg) \
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 21/43 tools perf: Move from sane_ctype.h obtained from git to the Linux's original
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We got the sane_ctype.h headers from git and kept using it so far, but since that code originally came from the kernel sources to the git sources, perhaps its better to just use the one in the kernel, so that we can leverage tools/perf/check_headers.sh to be notified when our copy gets out of sync, i.e. when fixes or goodies are added to the code we've copied.
This will help with things like tools/lib/string.c where we want to have more things in common with the kernel, such as strim(), skip_spaces(), etc so as to go on removing the things that we have in tools/perf/util/ and instead using the code in the kernel, indirectly and removing things like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements are made to the original code.
Hopefully this also should help with reducing the difference of code hosted in tools/ to the one in the kernel proper.
--- tools/include/linux/ctype.h | 75 +++++++++++++++++++++++++++++ tools/lib/ctype.c | 35 ++++++++++++++ tools/lib/symbol/kallsyms.c | 1 - tools/lib/symbol/kallsyms.h | 1 + tools/perf/MANIFEST | 1 + tools/perf/arch/x86/util/machine.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/check-headers.sh | 2 + tools/perf/tests/code-reading.c | 2 +- tools/perf/ui/browser.c | 2 +- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/browsers/map.c | 2 +- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/Build | 4 ++ tools/perf/util/annotate.c | 2 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/ctype.c | 32 ------------ tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/debug.c | 2 +- tools/perf/util/demangle-java.c | 2 +- tools/perf/util/env.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/evsel.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/jitdump.c | 2 +- tools/perf/util/machine.c | 2 +- tools/perf/util/print_binary.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-finder.h | 2 +- tools/perf/util/python-ext-sources | 2 +- tools/perf/util/sane_ctype.h | 47 ------------------ tools/perf/util/stat-display.c | 2 +- tools/perf/util/strfilter.c | 2 +- tools/perf/util/string.c | 2 +- tools/perf/util/symbol-elf.c | 2 +- tools/perf/util/symbol.c | 2 +- tools/perf/util/trace-event-parse.c | 2 +- 46 files changed, 155 insertions(+), 117 deletions(-) create mode 100644 tools/include/linux/ctype.h create mode 100644 tools/lib/ctype.c delete mode 100644 tools/perf/util/ctype.c delete mode 100644 tools/perf/util/sane_ctype.h
tools/include/linux/ctype.h new file +75 -0
@@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CTYPE_H +#define _LINUX_CTYPE_H + +/* +* NOTE! This ctype does not handle EOF like the standard C +* library is required to. +*/ + +#define _U 0x01/* upper */ +#define _L 0x02/* lower */ +#define _D 0x04/* digit */ +#define _C 0x08/* cntrl */ +#define _P 0x10/* punct */ +#define _S 0x20/* white space (space/lf/tab) */ +#define _X 0x40/* hex digit */ +#define _SP 0x80/* hard space (0x20) */ + +extern const unsigned char _ctype[]; + +#define __ismask (x) (_ctype[(int)(unsigned char)(x)]) + +#define isalnum (c) ((__ismask(c)&(_U|_L|_D)) != 0) +#define isalpha (c) ((__ismask(c)&(_U|_L)) != 0) +#define iscntrl (c) ((__ismask(c)&(_C)) != 0) +static inline int __isdigit (int c) +{ +return '0' <= c && c <='9' ; +} +#define isdigit (c) __isdigit(c) +#define isgraph (c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) +#define islower (c) ((__ismask(c)&(_L)) != 0) +#define isprint (c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) +#define ispunct (c) ((__ismask(c)&(_P)) != 0) +/* Note: isspace() must return false for %NUL-terminator */ +#define isspace (c) ((__ismask(c)&(_S)) != 0) +#define isupper (c) ((__ismask(c)&(_U)) != 0) +#define isxdigit (c) ((__ismask(c)&(_D|_X)) != 0) + +#define isascii (c) (((unsigned char)(c))<=0x7f) +#define toascii (c) (((unsigned char)(c))&0x7f) + +static inline unsigned char __tolower (unsigned char c) +{ +if (isupper (c)) + c -='A' -'a' ; +return c; +} + +static inline unsigned char __toupper (unsigned char c) +{ +if (islower (c)) + c -='a' -'A' ; +return c; +} + +#define tolower (c) __tolower(c) +#define toupper (c) __toupper(c) + +/* +* Fast implementation of tolower() for internal usage. Do not use in your +* code. +*/ +static inline char _tolower (const char c) +{ +return c |0x20 ; +} + +/* Fast check for octal digit */ +static inline int isodigit (const char c) +{ +return c >='0' && c <='7' ; +} + +#endif
tools/lib/ctype.c new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* linux/lib/ctype.c +* +* Copyright (C) 1991, 1992 Linus Torvalds +*/ + +#include <linux/ctype.h> +#include <linux/compiler.h> + +const unsigned char _ctype[] = { +_C,_C,_C,_C,_C,_C,_C,_C,/* 0-7 */ +_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,/* 8-15 */ +_C,_C,_C,_C,_C,_C,_C,_C,/* 16-23 */ +_C,_C,_C,_C,_C,_C,_C,_C,/* 24-31 */ +_S|_SP,_P,_P,_P,_P,_P,_P,_P,/* 32-39 */ +_P,_P,_P,_P,_P,_P,_P,_P,/* 40-47 */ +_D,_D,_D,_D,_D,_D,_D,_D,/* 48-55 */ +_D,_D,_P,_P,_P,_P,_P,_P,/* 56-63 */ +_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,/* 64-71 */ +_U,_U,_U,_U,_U,_U,_U,_U,/* 72-79 */ +_U,_U,_U,_U,_U,_U,_U,_U,/* 80-87 */ +_U,_U,_U,_P,_P,_P,_P,_P,/* 88-95 */ +_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,/* 96-103 */ +_L,_L,_L,_L,_L,_L,_L,_L,/* 104-111 */ +_L,_L,_L,_L,_L,_L,_L,_L,/* 112-119 */ +_L,_L,_L,_P,_P,_P,_P,_C,/* 120-127 */ +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* 128-143 */ +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* 144-159 */ +_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,/* 160-175 */ +_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,/* 176-191 */ +_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,/* 192-207 */ +_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,/* 208-223 */ +_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,/* 224-239 */ +_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};/* 240-255 */
tools/lib/symbol/kallsyms.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include <ctype.h> #include "symbol/kallsyms.h" #include <stdio.h> #include <stdlib.h>
tools/lib/symbol/kallsyms.h +1 -0
@@ -3,6 +3,7 @@#define __TOOLS_KALLSYMS_H_ 1#include <elf.h> +#include <linux/ctype.h> #include <linux/types.h> #ifndef KSYM_NAME_LEN
tools/perf/MANIFEST +1 -0
@@ -7,6 +7,7 @@ tools/lib/traceevent tools/lib/api tools/lib/bpf tools/lib/subcmd +tools/lib/ctype.c tools/lib/hweight.c tools/lib/rbtree.c tools/lib/string.c
tools/perf/arch/x86/util/machine.c +1 -1
@@ -7,7 +7,7 @@#include "../../util/machine.h" #include "../../util/map.h" #include "../../util/symbol.h" -#include "../../util/sane_ctype.h" +#include <linux/ctype.h> #include <symbol/kallsyms.h>
tools/perf/builtin-kmem.c +1 -1
@@ -31,7 +31,7 @@#include <locale.h> #include <regex.h> -#include "sane_ctype.h" +#include <linux/ctype.h> static int kmem_slab;static int kmem_page;
tools/perf/builtin-report.c +1 -1
@@ -47,7 +47,7 @@#include <errno.h> #include <inttypes.h> #include <regex.h> -#include "sane_ctype.h" +#include <linux/ctype.h> #include <signal.h> #include <linux/bitmap.h> #include <linux/stringify.h>
tools/perf/builtin-sched.c +1 -1
@@ -37,7 +37,7 @@#include <api/fs/fs.h> #include <linux/time64.h> -#include "sane_ctype.h" +#include <linux/ctype.h> #define PR_SET_NAME 15/* Set process name */ #define MAX_CPUS 4096
tools/perf/builtin-script.c +1 -1
@@ -49,7 +49,7 @@#include <unistd.h> #include <subcmd/pager.h> -#include "sane_ctype.h" +#include <linux/ctype.h> static char const *script_name;static char const *generate_script_lang;
tools/perf/builtin-stat.c +1 -1
@@ -82,7 +82,7 @@#include <sys/time.h> #include <sys/resource.h> -#include "sane_ctype.h" +#include <linux/ctype.h> #define DEFAULT_SEPARATOR " "#define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi"
tools/perf/builtin-top.c +1 -1
@@ -76,7 +76,7 @@#include <linux/time64.h> #include <linux/types.h> -#include "sane_ctype.h" +#include <linux/ctype.h> static volatile int done;static volatile int resize;
tools/perf/builtin-trace.c +1 -1
@@ -64,7 +64,7 @@#include <fcntl.h> #include <sys/sysmacros.h> -#include "sane_ctype.h" +#include <linux/ctype.h> #ifndef O_CLOEXEC # define O_CLOEXEC 02000000
tools/perf/check-headers.sh +2 -0
@@ -105,6 +105,8 @@ check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/ex check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"' check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"' check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"' +check include/linux/ctype.h '-I "isdigit("' +check lib/ctype.c '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B' # diff non-symmetric files check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl
tools/perf/tests/code-reading.c +1 -1
@@ -22,7 +22,7 @@#include "tests.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #define BUFSZ 1024#define READLEN 128
tools/perf/ui/browser.c +1 -1
@@ -16,7 +16,7 @@#include "helpline.h" #include "keysyms.h" #include "../color.h" -#include "sane_ctype.h" +#include <linux/ctype.h> static int ui_browser__percent_color (struct ui_browser *browser,double percent,bool current)
tools/perf/ui/browsers/hists.c +1 -1
@@ -33,7 +33,7 @@#include "units.h" #include "time-utils.h" -#include "sane_ctype.h" +#include <linux/ctype.h> extern void hist_browser__init_hpp (void );
tools/perf/ui/browsers/map.c +1 -1
@@ -13,7 +13,7 @@#include "../keysyms.h" #include "map.h" -#include "sane_ctype.h" +#include <linux/ctype.h> struct map_browser {struct ui_browser b;
tools/perf/ui/stdio/hist.c +1 -1
@@ -13,7 +13,7 @@#include "../../util/srcline.h" #include "../../util/string2.h" #include "../../util/thread.h" -#include "../../util/sane_ctype.h" +#include <linux/ctype.h> static size_t callchain__fprintf_left_margin (FILE *fp,int left_margin) {
tools/perf/util/Build +4 -0
@@ -213,6 +213,10 @@ $(OUTPUT)util/bitmap.o: ../lib/bitmap.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)util/ctype.o: ../lib/ctype.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)util/find_bit.o: ../lib/find_bit.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)
tools/perf/util/annotate.c +1 -1
@@ -49,7 +49,7 @@#define DARROW_CHAR ((unsigned char)'.')#define UARROW_CHAR ((unsigned char)'-') -#include "sane_ctype.h" +#include <linux/ctype.h> struct annotation_options annotation__default_options = { .use_offset = true,
tools/perf/util/auxtrace.c +1 -1
@@ -51,7 +51,7 @@#include "arm-spe.h" #include "s390-cpumsf.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include "symbol/kallsyms.h" static bool auxtrace__dont_decode (struct perf_session *session)
tools/perf/util/build-id.c +1 -1
@@ -29,7 +29,7 @@#include "probe-file.h" #include "strlist.h" -#include "sane_ctype.h" +#include <linux/ctype.h> static bool no_buildid_cache;
tools/perf/util/config.c +1 -1
@@ -24,7 +24,7 @@#include <unistd.h> #include <linux/string.h> -#include "sane_ctype.h" +#include <linux/ctype.h> #define MAXNAME (256)
tools/perf/util/cpumap.c +1 -1
@@ -10,7 +10,7 @@#include <linux/bitmap.h> #include "asm/bug.h" -#include "sane_ctype.h" +#include <linux/ctype.h> static int max_cpu_num;static int max_present_cpu_num;
tools/perf/util/ctype.c deleted +0 -32
@@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Sane locale-independent, ASCII ctype. -* -* No surprises, and works with signed and unsigned chars. -*/ -#include "sane_ctype.h" - -enum { -S =GIT_SPACE , -A =GIT_ALPHA , -D =GIT_DIGIT , -G =GIT_GLOB_SPECIAL ,/* *, ?, [, \\ */ -R =GIT_REGEX_SPECIAL ,/* $, (, ), +, ., ^, {, | * */ -P =GIT_PRINT_EXTRA ,/* printable - alpha - digit - glob - regex */ - -PS =GIT_SPACE |GIT_PRINT_EXTRA , -}; - -unsigned char sane_ctype[256 ] = { -/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ - -0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,S ,S ,0 ,0 ,S ,0 ,0 ,/* 0.. 15 */ -0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,/* 16.. 31 */ -PS ,P ,P ,P ,R ,P ,P ,P ,R ,R ,G ,R ,P ,P ,R ,P ,/* 32.. 47 */ -D ,D ,D ,D ,D ,D ,D ,D ,D ,D ,P ,P ,P ,P ,P ,G ,/* 48.. 63 */ -P ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,/* 64.. 79 */ -A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,G ,G ,P ,R ,P ,/* 80.. 95 */ -P ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,/* 96..111 */ -A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,A ,R ,R ,P ,P ,0 ,/* 112..127 */ -/* Nothing in the 128.. range */ -};
tools/perf/util/data-convert-bt.c +1 -1
@@ -29,7 +29,7 @@#include "evsel.h" #include "machine.h" #include "config.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #define pr_N (n, fmt, ...) \ eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
tools/perf/util/debug.c +1 -1
@@ -21,7 +21,7 @@#include "util.h" #include "target.h" -#include "sane_ctype.h" +#include <linux/ctype.h> int verbose;bool dump_trace = false, quiet = false;
tools/perf/util/demangle-java.c +1 -1
@@ -8,7 +8,7 @@#include "demangle-java.h" -#include "sane_ctype.h" +#include <linux/ctype.h> enum {MODE_PREFIX =0 ,
tools/perf/util/env.c +1 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "cpumap.h" #include "env.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include "util.h" #include "bpf-event.h" #include <errno.h>
tools/perf/util/event.c +1 -1
@@ -20,7 +20,7 @@#include "strlist.h" #include "thread.h" #include "thread_map.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include "map.h" #include "symbol.h" #include "symbol/kallsyms.h"
tools/perf/util/evsel.c +1 -1
@@ -39,7 +39,7 @@#include "memswap.h" #include "util/parse-branch-options.h" -#include "sane_ctype.h" +#include <linux/ctype.h> struct perf_missing_features perf_missing_features;
tools/perf/util/header.c +1 -1
@@ -43,7 +43,7 @@#include "cputopo.h" #include "bpf-event.h" -#include "sane_ctype.h" +#include <linux/ctype.h> /* * magic2 = "PERFILE2"
tools/perf/util/jitdump.c +1 -1
@@ -28,7 +28,7 @@#include "genelf.h" #include "../builtin.h" -#include "sane_ctype.h" +#include <linux/ctype.h> struct jit_buf_desc {struct perf_data *output;
tools/perf/util/machine.c +1 -1
@@ -25,7 +25,7 @@#include "asm/bug.h" #include "bpf-event.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include <symbol/kallsyms.h> #include <linux/mman.h>
tools/perf/util/print_binary.c +1 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "print_binary.h" #include <linux/log2.h> -#include "sane_ctype.h" +#include <linux/ctype.h> int binary__fprintf(unsigned char *data, size_t len, size_t bytes_per_line, binary__fprintf_t printer,
tools/perf/util/probe-event.c +1 -1
@@ -39,7 +39,7 @@#include "session.h" #include "string2.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #define PERFPROBE_GROUP "probe"
tools/perf/util/probe-finder.h +1 -1
@@ -5,7 +5,7 @@#include <stdbool.h> #include "intlist.h" #include "probe-event.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #define MAX_PROBE_BUFFER 1024#define MAX_PROBES 128
tools/perf/util/python-ext-sources +1 -1
@@ -6,7 +6,7 @@ # util/python.c -util/ctype.c +../lib/ctype.c util/evlist.c util/evsel.c util/cpumap.c
tools/perf/util/sane_ctype.h deleted +0 -47
47 lines not on this page · raw message
tools/perf/util/stat-display.c +1 -1
@@ -10,7 +10,7 @@#include "thread_map.h" #include "cpumap.h" #include "string2.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include "cgroup.h" #include <math.h> #include <api/fs/fs.h>
tools/perf/util/strfilter.c +1 -1
@@ -4,7 +4,7 @@#include "strfilter.h" #include <errno.h> -#include "sane_ctype.h" +#include <linux/ctype.h> /* Operators */ static const char *OP_and ="&" ;/* Logical AND */
tools/perf/util/string.c +1 -1
@@ -4,7 +4,7 @@#include <linux/string.h> #include <stdlib.h> -#include "sane_ctype.h" +#include <linux/ctype.h> const char *graph_dotted_line ="---------------------------------------------------------------------"
tools/perf/util/symbol-elf.c +1 -1
@@ -15,7 +15,7 @@#include "vdso.h" #include "debug.h" #include "util.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include <symbol/kallsyms.h> #ifndef EM_AARCH64
tools/perf/util/symbol.c +1 -1
@@ -25,7 +25,7 @@#include "namespaces.h" #include "header.h" #include "path.h" -#include "sane_ctype.h" +#include <linux/ctype.h> #include <elf.h> #include <limits.h>
tools/perf/util/trace-event-parse.c +1 -1
@@ -11,7 +11,7 @@#include "debug.h" #include "trace-event.h" -#include "sane_ctype.h" +#include <linux/ctype.h> static int get_common_field (struct scripting_context *context,int *offset,int *size,const char *type)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 22/43 perf tools: Use linux/ctype.h in more places
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
There were a few places where we still were using the libc version of ctype.h, switch to the one in tools/lib/ctype.c that the rest of perf uses.
--- tools/perf/arch/s390/util/header.c | 2 +- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/time-utils.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/arch/s390/util/header.c +1 -1
@@ -11,7 +11,7 @@#include <unistd.h> #include <stdio.h> #include <string.h> -#include <ctype.h> +#include <linux/ctype.h> #include "../../util/header.h" #include "../../util/util.h"
tools/perf/util/metricgroup.c +1 -1
@@ -17,7 +17,7 @@#include "pmu-events/pmu-events.h" #include "strlist.h" #include <assert.h> -#include <ctype.h> +#include <linux/ctype.h> struct metric_event *metricgroup__lookup(struct rblist *metric_events, struct perf_evsel *evsel,
tools/perf/util/time-utils.c +1 -1
@@ -7,7 +7,7 @@#include <errno.h> #include <inttypes.h> #include <math.h> -#include <ctype.h> +#include <linux/ctype.h> #include "perf.h" #include "debug.h"
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 23/43 tools lib: Adopt skip_spaces() from the kernel sources
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Same implementation, will be used to replace ad-hoc equivalent code in tools/.
--- tools/include/linux/string.h | 4 +++- tools/lib/string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
tools/include/linux/string.h +3 -1
@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; } -#endif /* _LINUX_STRING_H_ */ +extern char *__must_check skip_spaces (const char *); + +#endif /* _TOOLS_LINUX_STRING_H_ */
tools/lib/string.c +14 -0
@@ -17,6 +17,7 @@#include <string.h> #include <errno.h> #include <linux/string.h> +#include <linux/ctype.h> #include <linux/compiler.h> /**
@@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) }return ret; } + +/** +* skip_spaces - Removes leading whitespace from @str. +* @str: The string to be stripped. +* +* Returns a pointer to the first non-whitespace character in @str. +*/ +char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str; +return (char *)str; +}
Signature · 1 line
2.20.1
Re: [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources
Quoted 60 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Same implementation, will be used to replace ad-hoc equivalent code in
tools/.Cc Adrian Hunter <[email protected]>Cc André Goddard Rosa <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/include/linux/string.h | 4 +++- tools/lib/string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)tools/include/linux/string.h +3
-1@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; } -#endif /* _LINUX_STRING_H_ */ +extern char *__must_check skip_spaces (const char *); + +#endif /* _TOOLS_LINUX_STRING_H_ */ tools/lib/string.c +14
-0@@ -17,6 +17,7 @@#include <string.h> #include <errno.h> #include <linux/string.h> +#include <linux/ctype.h> #include <linux/compiler.h> /** @@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) }return ret; } + +/** +* skip_spaces - Removes leading whitespace from @str. +* @str: The string to be stripped. +* +* Returns a pointer to the first non-whitespace character in @str. +*/ +char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str; +return (char *)str; +}Signature · 1 line
2.20.1
this breaks objtool build, because it adds _ctype dependency via isspace call patch below fixes it for me
jirka
---
tools/objtool/Build +5 -0
@@ -9,6 +9,7 @@ objtool-y += special.o objtool-y += objtool.o objtool-y += libstring.o +objtool-y += libctype.o objtool-y += str_error_r.o CFLAGS += -I$(srctree)/tools/lib
@@ -17,6 +18,10 @@ $(OUTPUT)libstring.o: ../lib/string.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)libctype.o: ../lib/ctype.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)str_error_r.o: ../lib/str_error_r.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)
Re: [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources
Em Tue, Jul 02, 2019 at 02:12:40PM +0200, Jiri Olsa escreveu:
Quoted 56 lines · Arnaldo Carvalho de Melo
Quoted 55 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Same implementation, will be used to replace ad-hoc equivalent code in
tools/.Cc Adrian Hunter <[email protected]>Cc André Goddard Rosa <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/include/linux/string.h | 4 +++- tools/lib/string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)tools/include/linux/string.h +3
-1@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; } -#endif /* _LINUX_STRING_H_ */ +extern char *__must_check skip_spaces (const char *); + +#endif /* _TOOLS_LINUX_STRING_H_ */ tools/lib/string.c +12
-0@@ -17,6 +17,7 @@#include <string.h> #include <errno.h> #include <linux/string.h> +#include <linux/ctype.h> #include <linux/compiler.h> /** @@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) }return ret; } + +/** +* skip_spaces - Removes leading whitespace from @str. +* @str: The string to be stripped. +* +* Returns a pointer to the first non-whitespace character in @str. +*/ +char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str;
Quoted 8 lines
Quoted 5 lines
tools/lib/string.c +2
-0+return (char *)str; +}Signature · 1 line
2.20.1this breaks objtool build, because it adds
_ctypedependency via isspace call patch below fixes it for me
Thanks for spotting this, I'll have it in my next pull request.
- Arnaldo
Quoted 27 lines
jirka
---
tools/objtool/Build +5
-0@@ -9,6 +9,7 @@ objtool-y += special.o objtool-y += objtool.o objtool-y += libstring.o +objtool-y += libctype.o objtool-y += str_error_r.o CFLAGS += -I$(srctree)/tools/lib@@ -17,6 +18,10 @@ $(OUTPUT)libstring.o: ../lib/string.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)libctype.o: ../lib/ctype.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)str_error_r.o: ../lib/str_error_r.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)
Signature · 1 line
- Arnaldo
Re: [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources
Em Tue, Jul 02, 2019 at 10:46:03AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 66 lines
Em Tue, Jul 02, 2019 at 02:12:40PM +0200, Jiri Olsa escreveu:
Quoted 56 lines · Arnaldo Carvalho de Melo
Quoted 55 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Same implementation, will be used to replace ad-hoc equivalent code in
tools/.Cc Adrian Hunter <[email protected]>Cc André Goddard Rosa <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/include/linux/string.h | 4 +++- tools/lib/string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)tools/include/linux/string.h +3
-1@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; } -#endif /* _LINUX_STRING_H_ */ +extern char *__must_check skip_spaces (const char *); + +#endif /* _TOOLS_LINUX_STRING_H_ */ tools/lib/string.c +12
-0@@ -17,6 +17,7 @@#include <string.h> #include <errno.h> #include <linux/string.h> +#include <linux/ctype.h> #include <linux/compiler.h> /** @@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) }return ret; } + +/** +* skip_spaces - Removes leading whitespace from @str. +* @str: The string to be stripped. +* +* Returns a pointer to the first non-whitespace character in @str. +*/ +char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str;Quoted 8 lines
Quoted 5 lines
tools/lib/string.c +2
-0+return (char *)str; +}Signature · 1 line
2.20.1this breaks objtool build, because it adds
_ctypedependency via isspace call patch below fixes it for me
Quoted 1 line
Thanks for spotting this, I'll have it in my next pull request.
I'm adding a Signed-off-by: you, ok?
- Arnaldo
Quoted 33 lines
- Arnaldo
Quoted 27 lines
jirka
---
tools/objtool/Build +5
-0@@ -9,6 +9,7 @@ objtool-y += special.o objtool-y += objtool.o objtool-y += libstring.o +objtool-y += libctype.o objtool-y += str_error_r.o CFLAGS += -I$(srctree)/tools/lib@@ -17,6 +18,10 @@ $(OUTPUT)libstring.o: ../lib/string.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)libctype.o: ../lib/ctype.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)str_error_r.o: ../lib/str_error_r.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
Re: [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources
Quoted 67 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 02, 2019 at 10:46:03AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 66 lines
Em Tue, Jul 02, 2019 at 02:12:40PM +0200, Jiri Olsa escreveu:
Quoted 64 lines · Arnaldo Carvalho de Melo
Quoted 60 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Same implementation, will be used to replace ad-hoc equivalent code in
tools/.Cc Adrian Hunter <[email protected]>Cc André Goddard Rosa <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/include/linux/string.h | 4 +++- tools/lib/string.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)tools/include/linux/string.h +3
-1@@ -29,4 +29,6 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; } -#endif /* _LINUX_STRING_H_ */ +extern char *__must_check skip_spaces (const char *); + +#endif /* _TOOLS_LINUX_STRING_H_ */ tools/lib/string.c +14
-0@@ -17,6 +17,7 @@#include <string.h> #include <errno.h> #include <linux/string.h> +#include <linux/ctype.h> #include <linux/compiler.h> /** @@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) }return ret; } + +/** +* skip_spaces - Removes leading whitespace from @str. +* @str: The string to be stripped. +* +* Returns a pointer to the first non-whitespace character in @str. +*/ +char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str; +return (char *)str; +}Signature · 1 line
2.20.1this breaks objtool build, because it adds
_ctypedependency via isspace call patch below fixes it for me
Quoted 3 lines
Quoted 1 line
Thanks for spotting this, I'll have it in my next pull request.
I'm adding a Signed-off-by: you, ok?
sure, I did not post full patch, because I thought you might thought of some other solution
thanks,
jirka
Re: [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources
Em Tue, Jul 02, 2019 at 03:54:32PM +0200, Jiri Olsa escreveu:
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 4 lines
Em Tue, Jul 02, 2019 at 10:46:03AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 3 lines
Em Tue, Jul 02, 2019 at 02:12:40PM +0200, Jiri Olsa escreveu:
Quoted 2 lines
this breaks objtool build, because it adds
_ctypedependency via isspace call patch below fixes it for me
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Thanks for spotting this, I'll have it in my next pull request.
I'm adding a Signed-off-by: you, ok?
sure, I did not post full patch, because I thought you might thought of some other solution
I think this is it for now, at some point we need to make a tools/lib/liblinux.{a,so} to group what we're getting from the linux lib/ directory to adapt and use in tools/ living code and then, as a a starter, tools/objtool/ and tools/perf/ should link with it.
- Arnaldo
Re: [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources
In reply to Arnaldo Carvalho de MeloQuoted 6 lines · Arnaldo Carvalho de Melo
Em Tue, Jul 02, 2019 at 02:12:40PM +0200, Jiri Olsa escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 4 lines
From: Arnaldo Carvalho de Melo <[email protected]>
Same implementation, will be used to replace ad-hoc equivalent code in
tools/.
[]
Quoted 1 line
Quoted 1 line
tools/lib/string.c
Quoted 1 line
tools/lib/string.c +0
-0
[]
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tools/lib/string.c +5
-0@@ -106,3 +107,16 @@ size_t __weak strlcpy(char *dest, const char *src, size_t size) }return ret; } + +/** +* skip_spaces - Removes leading whitespace from @str. +* @str: The string to be stripped. +*
Quoted 8 lines
Quoted 8 lines
tools/lib/string.c size_t __weak strlcpy(char *dest, const char *src, size_t size) · line 122
Quoted 8 lines
tools/lib/string.c +8
-0+* Returns a pointer to the first non-whitespace character in @str. +*/ +char *skip_spaces (const char *str) +{ +while (isspace (*str)) + ++str; +return (char *)str; +}
pity about duplicating losing the const
tip-bot for Jiri Olsa
merge bot[tip:perf/core] objtool: Fix build by linking against tools/lib/ctype.o sources
In reply to Jiri Olsaobjtool: Fix build by linking against tools/lib/ctype.o sources
Commit-ID: 0c69b93112428d43b8c103d032143ea89b895d43 Gitweb: https://git.kernel.org/tip/0c69b93112428d43b8c103d032143ea89b895d43 Author: Jiri Olsa <[email protected]> AuthorDate: Tue, 2 Jul 2019 14:12:40 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 2 Jul 2019 10:49:31 -0300
objtool: Fix build by linking against tools/lib/ctype.o sources
Fix objtool build, because it adds _ctype dependency via isspace call patch.
--- tools/objtool/Build | 5 +++++ 1 file changed, 5 insertions(+)
tools/objtool/Build +5 -0
@@ -9,6 +9,7 @@ objtool-y += special.o objtool-y += objtool.o objtool-y += libstring.o +objtool-y += libctype.o objtool-y += str_error_r.o CFLAGS += -I$(srctree)/tools/lib
@@ -17,6 +18,10 @@ $(OUTPUT)libstring.o: ../lib/string.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)libctype.o: ../lib/ctype.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)str_error_r.o: ../lib/str_error_r.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)
Arnaldo Carvalho de Melo
maintainerPATCH 24/43 perf stat: Use recently introduced skip_spaces()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour.
--- tools/perf/util/stat-display.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/stat-display.c +2 -3
@@ -1,5 +1,6 @@#include <stdio.h> #include <inttypes.h> +#include <linux/string.h> #include <linux/time64.h> #include <math.h> #include "color.h"
@@ -215,9 +216,7 @@ static void print_metric_csv(struct perf_stat_config *config __maybe_unused,while (isdigit (*ends) || *ends =='.' ) ends++; *ends =0 ; -while (isspace (*unit)) - unit++; -fprintf (out,"%s%s%s%s" , config->csv_sep, vals, config->csv_sep, unit); +fprintf (out,"%s%s%s%s" , config->csv_sep, vals, config->csv_sep,skip_spaces (unit)); }/* Filter out some columns that don't work well in metrics only mode */
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 25/43 perf header: Use skip_spaces() in __write_cpudesc()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour.
--- tools/perf/util/header.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/header.c +2 -3
@@ -13,6 +13,7 @@#include <linux/list.h> #include <linux/kernel.h> #include <linux/bitops.h> +#include <linux/string.h> #include <linux/stringify.h> #include <sys/stat.h> #include <sys/utsname.h>
@@ -416,10 +417,8 @@ static int __write_cpudesc(struct feat_fd *ff, const char *cpuinfo_proc)while (*p) {if (isspace (*p)) {char *r = p +1 ; -char *q = r; +char *q =skip_spaces (r); *p =' ' ; -while (*q &&isspace (*q)) - q++;if (q != (p+1 ))while ((*r++ = *q++)); }
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 26/43 perf time-utils: Use skip_spaces()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour intended.
--- tools/perf/util/time-utils.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/time-utils.c +2 -4
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <stdlib.h> #include <string.h> +#include <linux/string.h> #include <sys/time.h> #include <linux/time64.h> #include <time.h>
@@ -141,10 +142,7 @@ static int perf_time__parse_strs(struct perf_time_interval *ptime,for (i =0 , p = str; i < num -1 ; i++) { arg = p;/* Find next comma, there must be one */ - p =strchr (p,',' ) +1 ; -/* Skip white space */ -while (isspace (*p)) - p++; + p =skip_spaces (strchr (p,',' ) +1 );/* Skip the value, must not contain space or comma */ while (*p && !isspace (*p)) {if (*p++ ==',' ) {
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 27/43 perf probe: Use skip_spaces() for argv handling
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
The skip_sep() routine has the same implementation as skip_spaces(), recently adopted from the kernel, sources, switch to it.
--- tools/perf/util/string.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
tools/perf/util/string.c +2 -14
@@ -69,18 +69,6 @@ s64 perf_atoll(const char *str)return -1 ; } -/* -* Helper function for splitting a string into an argv-like array. -* originally copied from lib/argv_split.c -*/ -static const char *skip_sep (const char *cp) -{ -while (*cp &&isspace (*cp)) - cp++; - -return cp; -} -static const char *skip_arg (const char *cp) {while (*cp && !isspace (*cp))
@@ -94,7 +82,7 @@ static int count_argc(const char *str)int count =0 ;while (*str) { - str =skip_sep (str); + str =skip_spaces (str);if (*str) { count++; str =skip_arg (str);
@@ -148,7 +136,7 @@ char **argv_split(const char *str, int *argcp) argvp = argv;while (*str) { - str =skip_sep (str); + str =skip_spaces (str);if (*str) {const char *p = str;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 28/43 perf strfilter: Use skip_spaces()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour.
--- tools/perf/util/strfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/strfilter.c +2 -2
@@ -5,6 +5,7 @@#include <errno.h> #include <linux/ctype.h> +#include <linux/string.h> /* Operators */ static const char *OP_and ="&" ;/* Logical AND */
@@ -37,8 +38,7 @@ static const char *get_token(const char *s, const char **e) {const char *p; -while (isspace (*s))/* Skip spaces */ - s++; + s =skip_spaces (s);if (*s =='\0' ) { p = s;
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 29/43 perf metricgroup: Use strsep()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour intended, trivial optimization done by avoiding looking for spaces in 'g' right after setting it to "No_group".
--- tools/perf/util/metricgroup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/metricgroup.c +1 -2
@@ -308,10 +308,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,struct mep *me;char *s; + g =skip_spaces (g);if (*g ==0 ) g ="No_group" ; -while (isspace (*g)) - g++;if (filter && !strstr (g, filter))continue ;if (raw)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 30/43 perf report: Use skip_spaces()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour intended.
--- tools/perf/builtin-report.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/builtin-report.c +1 -2
@@ -941,8 +941,7 @@ parse_time_quantum(const struct option *opt, const char *arg,pr_err ("time quantum cannot be 0" );return -1 ; } -while (isspace (*end)) - end++; + end =skip_spaces (end);if (*end ==0 )return 0 ;if (!strcmp (end,"s" )) {
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 31/43 perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour, just using the same kernel idiom for such operation.
--- tools/perf/builtin-script.c | 12 ++++++------ tools/perf/ui/browser.c | 2 +- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/gtk/hists.c | 4 ++-- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/annotate.c | 10 +++++----- tools/perf/util/event.c | 4 +--- tools/perf/util/pmu.c | 3 ++- tools/perf/util/stat-display.c | 4 ++-- tools/perf/util/string.c | 14 -------------- tools/perf/util/string2.h | 4 ++-- 11 files changed, 23 insertions(+), 38 deletions(-)
tools/perf/builtin-script.c +6 -6
@@ -2880,7 +2880,7 @@ static int read_script_info(struct script_desc *desc, const char *filename)return -1 ;while (fgets (line,sizeof (line), fp)) { - p =ltrim (line); + p =skip_spaces (line);if (strlen (p) ==0 )continue ;if (*p !='#' )
@@ -2889,19 +2889,19 @@ static int read_script_info(struct script_desc *desc, const char *filename)if (strlen (p) && *p =='!' )continue ; - p =ltrim (p); + p =skip_spaces (p);if (strlen (p) && p[strlen (p) -1 ] =='\n' ) p[strlen (p) -1 ] ='\0' ;if (!strncmp (p,"description:" ,strlen ("description:" ))) { p +=strlen ("description:" ); - desc->half_liner =strdup (ltrim (p)); + desc->half_liner =strdup (skip_spaces (p));continue ; }if (!strncmp (p,"args:" ,strlen ("args:" ))) { p +=strlen ("args:" ); - desc->args =strdup (ltrim (p)); + desc->args =strdup (skip_spaces (p));continue ; } }
@@ -3008,7 +3008,7 @@ static int check_ev_match(char *dir_name, char *scriptname,return -1 ;while (fgets (line,sizeof (line), fp)) { - p =ltrim (line); + p =skip_spaces (line);if (*p =='#' )continue ;
@@ -3018,7 +3018,7 @@ static int check_ev_match(char *dir_name, char *scriptname,break ; p +=2 ; - p =ltrim (p); + p =skip_spaces (p); len =strcspn (p," \t" );if (!len)break ;
tools/perf/ui/browser.c +1 -1
@@ -594,7 +594,7 @@ static int ui_browser__color_config(const char *var, const char *value,break ; *bg ='\0' ; - bg =ltrim (++bg); + bg =skip_spaces (bg +1 ); ui_browser__colorsets[i].bg = bg; ui_browser__colorsets[i].fg = fg;return 0 ;
tools/perf/ui/browsers/hists.c +1 -1
@@ -1470,7 +1470,7 @@ static int hist_browser__show_hierarchy_entry(struct hist_browser *browser,int i =0 ; width -= fmt->entry (fmt, &hpp, entry); -ui_browser__printf (&browser->b,"%s" ,ltrim (s)); +ui_browser__printf (&browser->b,"%s" ,skip_spaces (s));while (isspace (s[i++])) width++;
tools/perf/ui/gtk/hists.c +2 -2
@@ -459,7 +459,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists *hists,advance_hpp (hpp, ret +2 ); } -gtk_tree_store_set (store, &iter, col_idx,ltrim (rtrim (bf)),-1 ); +gtk_tree_store_set (store, &iter, col_idx,trim (bf),-1 );if (!he->leaf) { hpp->buf = bf;
@@ -555,7 +555,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, struct hists *hists, first_col = false; fmt->header (fmt, &hpp, hists,0 ,NULL ); -strcat (buf,ltrim (rtrim (hpp.buf))); +strcat (buf,trim (hpp.buf)); } }
tools/perf/ui/stdio/hist.c +1 -1
@@ -516,7 +516,7 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,* dynamic entries are right-aligned but we want left-aligned * in the hierarchy mode */ - printed +=fprintf (fp,"%s%s" , sep ?:" " ,ltrim (buf)); + printed +=fprintf (fp,"%s%s" , sep ?:" " ,skip_spaces (buf)); } printed +=putc ('\n' , fp);
tools/perf/util/annotate.c +5 -5
@@ -557,7 +557,7 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_syif (comment ==NULL )return 0 ; - comment =ltrim (comment); + comment =skip_spaces (comment);comment__symbol (ops->source.raw, comment +1 , &ops->source.addr, &ops->source.name);comment__symbol (ops->target.raw, comment +1 , &ops->target.addr, &ops->target.name);
@@ -602,7 +602,7 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *opsif (comment ==NULL )return 0 ; - comment =ltrim (comment); + comment =skip_spaces (comment);comment__symbol (ops->target.raw, comment +1 , &ops->target.addr, &ops->target.name);return 0 ;
@@ -1098,7 +1098,7 @@ static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, strstatic int disasm_line__parse (char *line,const char **namep,char **rawp) { -char tmp, *name =ltrim (line); +char tmp, *name =skip_spaces (line);if (name[0 ] =='\0' )return -1 ;
@@ -1116,7 +1116,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) goto out_free_name; (*rawp)[0 ] = tmp; - *rawp =ltrim (*rawp); + *rawp =skip_spaces (*rawp);return 0 ;
@@ -1503,7 +1503,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,return 0 ; } - tmp =ltrim (parsed_line); + tmp =skip_spaces (parsed_line);if (*tmp) {/* * Parse hexa addresses followed by ':'
tools/perf/util/event.c +1 -3
@@ -158,9 +158,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,if (name) {char *nl; - name +=5 ;/* strlen("Name:") */ - name =ltrim (name); - + name =skip_spaces (name +5 );/* strlen("Name:") */ nl =strchr (name,'\n' );if (nl) *nl ='\0' ;
tools/perf/util/pmu.c +2 -1
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/list.h> #include <linux/compiler.h> +#include <linux/string.h> #include <sys/types.h> #include <errno.h> #include <fcntl.h>
@@ -1339,7 +1340,7 @@ static void wordwrap(char *s, int start, int max, int corr)break ; s += wlen; column += n; - s =ltrim (s); + s =skip_spaces (s); } }
tools/perf/util/stat-display.c +2 -2
@@ -212,7 +212,7 @@ static void print_metric_csv(struct perf_stat_config *config __maybe_unused,return ; }snprintf (buf,sizeof (buf), fmt, val); - ends = vals =ltrim (buf); + ends = vals =skip_spaces (buf);while (isdigit (*ends) || *ends =='.' ) ends++; *ends =0 ;
@@ -280,7 +280,7 @@ static void print_metric_only_csv(struct perf_stat_config *config __maybe_unusedreturn ; unit =fixunit (tbuf, os->evsel, unit);snprintf (buf,sizeof buf, fmt, val); - ends = vals =ltrim (buf); + ends = vals =skip_spaces (buf);while (isdigit (*ends) || *ends =='.' ) ends++; *ends =0 ;
tools/perf/util/string.c +0 -14
@@ -318,20 +318,6 @@ char *strxfrchar(char *s, char from, char to)return s; } -/** -* ltrim - Removes leading whitespace from @s. -* @s: The string to be stripped. -* -* Return pointer to the first non-whitespace character in @s. -*/ -char *ltrim (char *s) -{ -while (isspace (*s)) - s++; - -return s; -} -/** * rtrim - Removes trailing whitespace from @s. * @s: The string to be stripped.
tools/perf/util/string2.h +2 -2
@@ -2,6 +2,7 @@#ifndef PERF_STRING_H #define PERF_STRING_H +#include <linux/string.h> #include <linux/types.h> #include <stddef.h> #include <string.h>
@@ -22,12 +23,11 @@ static inline bool strisglob(const char *str)int strtailcmp (const char *s1,const char *s2);char *strxfrchar (char *s,char from,char to); -char *ltrim (char *s);char *rtrim (char *s);static inline char *trim (char *s) { -return ltrim (rtrim (s)); +return skip_spaces (rtrim (s)); }char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 32/43 tools lib: Adopt strim() from the kernel
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Since we're working on moving stuff out of tools/perf/util/ to tools/lib/, take the opportunity to adopt routines from the kernel that are equivalent, so that tools/ code look more like the kernel.
--- tools/include/linux/string.h | 2 ++ tools/lib/string.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
tools/include/linux/string.h +2 -0
@@ -31,4 +31,6 @@ static inline bool strstarts(const char *str, const char *prefix)extern char *__must_check skip_spaces (const char *); +extern char *strim (char *); +#endif /* _TOOLS_LINUX_STRING_H_ */
tools/lib/string.c +25 -0
@@ -120,3 +120,28 @@ char *skip_spaces(const char *str) ++str;return (char *)str; } + +/** +* strim - Removes leading and trailing whitespace from @s. +* @s: The string to be stripped. +* +* Note that the first trailing whitespace is replaced with a %NUL-terminator +* in the given string @s. Returns a pointer to the first non-whitespace +* character in @s. +*/ +char *strim (char *s) +{ +size_t size; +char *end; + + size =strlen (s); +if (!size) +return s; + + end = s + size -1 ; +while (end >= s &&isspace (*end)) + end--; + *(end +1 ) ='\0' ; + +return skip_spaces (s); +}
Signature · 1 line
2.20.1
A message that is not in the archive (sent off-list or not yet received): CAGje9yTfFrUxj-vSX=Au856Fe_307aQqD=YrbGeWfHESQ6Rw8w@mail.gmail.com
Re: [PATCH 32/43] tools lib: Adopt strim() from the kernel
Em Mon, Jul 01, 2019 at 11:33:20PM -0400, André Goddard Rosa escreveu:
Quoted 8 lines
Quoted 5 lines · On Mon, Jul 1, 2019 at 22:28 Arnaldo Carvalho de Melo <[email protected]> wrote:
From: Arnaldo Carvalho de Melo <[email protected]>
Since we're working on moving stuff out of
tools/perf/util/totools/lib/, take the opportunity to adopt routines from the kernel that are equivalent, so thattools/code look more like the kernel.
<SNIP>
Quoted 15 lines
Quoted 15 lines
tools/lib/string.c +15
-0+char *strim (char *s) +{ +size_t size; +char *end; + + size =strlen (s); +if (!size) +return s; + + end = s + size -1 ; +while (end >= s &&isspace (*end)) + end--; + *(end +1 ) ='\0' ; + +return skip_spaces (s);
Quoted 8 lines
Quoted 3 lines
+}
--
2.20.1Small nit: could call
skip_spaces()firstly and save its pointer to return later and then remove the trailing spaces. That’ll makestrlen()iterate over a smaller string.
Hey, this is just a copy of what is in the kernel sources, so as soon as this gets improved there we'll grab a copy again can you do that for the kernel first? :-)
- Arnaldo
Arnaldo Carvalho de Melo
maintainerPATCH 33/43 perf tools: Remove trim() implementation, use tools/lib's strim()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Moving more stuff out of tools/perf/util/ and using the kernel idiom.
--- tools/perf/tests/builtin-test.c | 3 ++- tools/perf/ui/browsers/hists.c | 3 ++- tools/perf/ui/gtk/hists.c | 5 +++-- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/string2.h | 5 ----- 5 files changed, 8 insertions(+), 10 deletions(-)
tools/perf/tests/builtin-test.c +2 -1
@@ -22,6 +22,7 @@#include "string2.h" #include "symbol.h" #include <linux/kernel.h> +#include <linux/string.h> #include <subcmd/exec-cmd.h> static bool dont_fork;
@@ -438,7 +439,7 @@ static const char *shell_test__description(char *description, size_t size, description =fgets (description, size, fp);fclose (fp); -return description ?trim (description +1 ) :NULL ; +return description ?strim (description +1 ) :NULL ; }#define for_each_shell_test (dir, base, ent) \
tools/perf/ui/browsers/hists.c +2 -1
@@ -6,6 +6,7 @@#include <stdlib.h> #include <string.h> #include <linux/rbtree.h> +#include <linux/string.h> #include <sys/ttydefaults.h> #include <linux/time64.h>
@@ -1686,7 +1687,7 @@ static int hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows ret = fmt->header (fmt, &dummy_hpp, hists,0 ,NULL ); dummy_hpp.buf[ret] ='\0' ; - start =trim (dummy_hpp.buf); + start =strim (dummy_hpp.buf); ret =strlen (start);if (start != dummy_hpp.buf)
tools/perf/ui/gtk/hists.c +3 -2
@@ -9,6 +9,7 @@#include "../string2.h" #include "gtk.h" #include <signal.h> +#include <linux/string.h> #define MAX_COLUMNS 32
@@ -459,7 +460,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists *hists,advance_hpp (hpp, ret +2 ); } -gtk_tree_store_set (store, &iter, col_idx,trim (bf),-1 ); +gtk_tree_store_set (store, &iter, col_idx,strim (bf),-1 );if (!he->leaf) { hpp->buf = bf;
@@ -555,7 +556,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, struct hists *hists, first_col = false; fmt->header (fmt, &hpp, hists,0 ,NULL ); -strcat (buf,trim (hpp.buf)); +strcat (buf,strim (hpp.buf)); } }
tools/perf/ui/stdio/hist.c +1 -1
@@ -620,7 +620,7 @@ static int hists__fprintf_hierarchy_headers(struct hists *hists, fmt->header (fmt, hpp, hists,0 ,NULL ); - header_width +=fprintf (fp,"%s" ,trim (hpp->buf)); + header_width +=fprintf (fp,"%s" ,strim (hpp->buf)); } }
tools/perf/util/string2.h +0 -5
@@ -25,11 +25,6 @@ char *strxfrchar(char *s, char from, char to);char *rtrim (char *s); -static inline char *trim (char *s) -{ -return skip_spaces (rtrim (s)); -} -char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints);static inline char *asprintf_expr_in_ints (const char *var,size_t nints,int *ints)
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 34/43 perf tools: Ditch rtrim(), use strim() from tools/lib
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Cleaning up a bit more tools/perf/util/ by using things we got from the kernel and have in tools/lib/
--- tools/perf/ui/browsers/hists.c | 3 ++- tools/perf/util/annotate.c | 3 ++- tools/perf/util/header.c | 6 +++--- tools/perf/util/pmu.c | 2 +- tools/perf/util/python-ext-sources | 1 + tools/perf/util/srcline.c | 3 ++- tools/perf/util/string.c | 23 ----------------------- tools/perf/util/string2.h | 2 -- tools/perf/util/thread_map.c | 3 ++- 9 files changed, 13 insertions(+), 33 deletions(-)
tools/perf/ui/browsers/hists.c +2 -1
@@ -2071,7 +2071,8 @@ static int hist_browser__fprintf_hierarchy_entry(struct hist_browser *browser,advance_hpp (&hpp, ret); } - printed +=fprintf (fp,"%s\n" ,rtrim (s)); +strim (s); + printed +=fprintf (fp,"%s\n" , s);if (he->leaf && folded_sign =='-' ) { printed += hist_browser__fprintf_callchain(browser, he, fp,
tools/perf/util/annotate.c +2 -1
@@ -35,6 +35,7 @@#include <pthread.h> #include <linux/bitops.h> #include <linux/kernel.h> +#include <linux/string.h> #include <bpf/libbpf.h> /* FIXME: For the HE_COLORSET */
@@ -1495,7 +1496,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,return -1 ; line_ip =-1 ; - parsed_line =rtrim (line); + parsed_line =strim (line);/* /filename:linenr ? Save line number and ignore. */ if (regexec (&file_lineno, parsed_line,2 , match,0 ) ==0 ) {
tools/perf/util/header.c +3 -3
@@ -1048,7 +1048,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 levreturn -1 ; cache->type[len] =0 ; - cache->type =rtrim (cache->type); + cache->type =strim (cache->type);scnprintf (file,PATH_MAX ,"%s/size" , path);if (sysfs__read_str (file, &cache->size, &len)) {
@@ -1057,7 +1057,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev } cache->size[len] =0 ; - cache->size =rtrim (cache->size); + cache->size =strim (cache->size);scnprintf (file,PATH_MAX ,"%s/shared_cpu_list" , path);if (sysfs__read_str (file, &cache->map, &len)) {
@@ -1067,7 +1067,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev } cache->map[len] =0 ; - cache->map =rtrim (cache->map); + cache->map =strim (cache->map);return 0 ; }
tools/perf/util/pmu.c +1 -1
@@ -395,7 +395,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI buf[ret] =0 ;/* Remove trailing newline from sysfs file */ -rtrim (buf); +strim (buf);return __perf_pmu__new_alias (list, dir, name,NULL , buf,NULL ,NULL ,NULL ,NULL ,NULL ,NULL );
tools/perf/util/python-ext-sources +1 -0
@@ -16,6 +16,7 @@ util/namespaces.c ../lib/bitmap.c ../lib/find_bit.c ../lib/hweight.c +../lib/string.c ../lib/vsprintf.c util/thread_map.c util/util.c
tools/perf/util/srcline.c +2 -1
@@ -5,6 +5,7 @@#include <string.h> #include <linux/kernel.h> +#include <linux/string.h> #include "util/dso.h" #include "util/util.h"
@@ -464,7 +465,7 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr,char *srcline;struct symbol *inline_sym; -rtrim (funcname); +strim (funcname);if (getline (&filename, &filelen, fp) ==-1 ) goto out;
tools/perf/util/string.c +0 -23
@@ -318,29 +318,6 @@ char *strxfrchar(char *s, char from, char to)return s; } -/** -* rtrim - Removes trailing whitespace from @s. -* @s: The string to be stripped. -* -* Note that the first trailing whitespace is replaced with a %NUL-terminator -* in the given string @s. Returns @s. -*/ -char *rtrim (char *s) -{ -size_t size =strlen (s); -char *end; - -if (!size) -return s; - - end = s + size -1 ; -while (end >= s &&isspace (*end)) - end--; - *(end +1 ) ='\0' ; - -return s; -} -char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints) {/*
tools/perf/util/string2.h +0 -2
@@ -23,8 +23,6 @@ static inline bool strisglob(const char *str)int strtailcmp (const char *s1,const char *s2);char *strxfrchar (char *s,char from,char to); -char *rtrim (char *s); -char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints);static inline char *asprintf_expr_in_ints (const char *var,size_t nints,int *ints)
tools/perf/util/thread_map.c +2 -1
@@ -12,6 +12,7 @@#include "strlist.h" #include <string.h> #include <api/fs/fs.h> +#include <linux/string.h> #include "asm/bug.h" #include "thread_map.h" #include "util.h"
@@ -392,7 +393,7 @@ static int get_comm(char **comm, pid_t pid)* mark the end of the string. */ (*comm)[size] =0 ; -rtrim (*comm); +strim (*comm); }free (path);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 35/43 tools lib: Adopt strreplace() from the kernel
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
We'll use it to further reduce the size of tools/perf/util/string.c, replacing the strxfrchar() equivalent function we have there.
--- tools/include/linux/string.h | 2 ++ tools/lib/string.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)
tools/include/linux/string.h +2 -0
@@ -19,6 +19,8 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);char *str_error_r (int errnum,char *buf,size_t buflen); +char *strreplace (char *s,char old,char new); +/** * strstarts - does @str start with @prefix? * @str: string to examine
tools/lib/string.c +16 -0
@@ -145,3 +145,19 @@ char *strim(char *s)return skip_spaces (s); } + +/** +* strreplace - Replace all occurrences of character in string. +* @s: The string to operate on. +* @old: The character being replaced. +* @new: The character @old is replaced with. +* +* Returns pointer to the nul byte at the end of @s. +*/ +char *strreplace (char *s,char old,char new) +{ +for (; *s; ++s) +if (*s == old) + *s = new; +return s; +}
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 36/43 perf tools: Drop strxfrchar(), use strreplace() equivalent from kernel
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
No change in behaviour intended, just reducing the codebase and using something available in tools/lib/.
--- tools/perf/util/dso.c | 3 ++- tools/perf/util/string.c | 18 ------------------ tools/perf/util/string2.h | 1 - 3 files changed, 2 insertions(+), 20 deletions(-)
tools/perf/util/dso.c +2 -1
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <asm/bug.h> #include <linux/kernel.h> +#include <linux/string.h> #include <sys/time.h> #include <sys/resource.h> #include <sys/types.h>
@@ -394,7 +395,7 @@ int __kmod_path__parse(struct kmod_path *m, const char *path,return -ENOMEM ; } -strxfrchar (m->name,'-' ,'_' ); +strreplace (m->name,'-' ,'_' ); }return 0 ;
tools/perf/util/string.c +0 -18
@@ -300,24 +300,6 @@ int strtailcmp(const char *s1, const char *s2)return 0 ; } -/** -* strxfrchar - Locate and replace character in @s -* @s: The string to be searched/changed. -* @from: Source character to be replaced. -* @to: Destination character. -* -* Return pointer to the changed string. -*/ -char *strxfrchar (char *s,char from,char to) -{ -char *p = s; - -while ((p =strchr (p, from)) !=NULL ) - *p++ = to; - -return s; -} -char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints) {/*
tools/perf/util/string2.h +0 -1
@@ -21,7 +21,6 @@ static inline bool strisglob(const char *str)return strpbrk (str,"*?[" ) !=NULL ; }int strtailcmp (const char *s1,const char *s2); -char *strxfrchar (char *s,char from,char to);char *asprintf_expr_inout_ints (const char *var,bool in,size_t nints,int *ints);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 37/43 tools lib: Move argv_{split,free} from tools/perf/util/
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
This came from the kernel lib/argv_split.c, so move it to tools/lib/argv_split.c, to get it closer to the kernel structure.
We need to audit the usage of argv_split() to figure out if it is really necessary to do have one allocation per argv[] entry, looking at one of its users I guess that is not the case and we probably are even leaking those allocations by not using argv_free() judiciously, for later.
With this we further remove stuff from tools/perf/util/, reducing the perf specific codebase and encouraging other tools/ code to use these routines so as to keep the style and constructs used with the kernel.
--- tools/include/linux/string.h | 3 ++ tools/lib/argv_split.c | 100 +++++++++++++++++++++++++++++++++++ tools/perf/MANIFEST | 1 + tools/perf/util/Build | 5 ++ tools/perf/util/string.c | 91 ------------------------------- tools/perf/util/string2.h | 2 - 6 files changed, 109 insertions(+), 93 deletions(-) create mode 100644 tools/lib/argv_split.c
tools/include/linux/string.h +3 -0
@@ -7,6 +7,9 @@void *memdup (const void *src,size_t len); +char **argv_split (const char *str,int *argcp); +void argv_free (char **argv); +int strtobool (const char *s,bool *res);/*
tools/lib/argv_split.c new file +100 -0
100 lines not on this page · raw message
tools/perf/MANIFEST +1 -0
@@ -7,6 +7,7 @@ tools/lib/traceevent tools/lib/api tools/lib/bpf tools/lib/subcmd +tools/lib/argv_split.c tools/lib/ctype.c tools/lib/hweight.c tools/lib/rbtree.c
tools/perf/util/Build +5 -0
@@ -20,6 +20,7 @@ perf-y += parse-events.o perf-y += perf_regs.o perf-y += path.o perf-y += print_binary.o +perf-y += argv_split.o perf-y += rbtree.o perf-y += libstring.o perf-y += bitmap.o
@@ -209,6 +210,10 @@ $(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)util/argv_split.o: ../lib/argv_split.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)util/bitmap.o: ../lib/bitmap.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c)
tools/perf/util/string.c +0 -91
97 lines not on this page · raw message
tools/perf/util/string2.h +0 -2
@@ -11,8 +11,6 @@ extern const char *graph_dotted_line;extern const char *dots;s64 perf_atoll (const char *str); -char **argv_split (const char *str,int *argcp); -void argv_free (char **argv);bool strglobmatch (const char *str,const char *pat);bool strglobmatch_nocase (const char *str,const char *pat);bool strlazymatch (const char *str,const char *pat);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 38/43 perf stat: Make metric event lookup more robust
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
After setting up metric groups through the event parser, the metricgroup code looks them up again in the event list.
Make sure we only look up events that haven't been used by some other metric. The data structures currently cannot handle more than one metric per event. This avoids problems with multiple events partially overlapping.
--- tools/perf/util/stat-shadow.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/stat-shadow.c +3 -2
@@ -304,7 +304,7 @@ static struct perf_evsel *perf_stat__find_event(struct perf_evlist *evsel_list,struct perf_evsel *c2; evlist__for_each_entry (evsel_list, c2) { -if (!strcasecmp (c2->name, name)) +if (!strcasecmp (c2->name, name) && !c2->collect_stat)return c2; }return NULL ;
@@ -343,7 +343,8 @@ void perf_stat__collect_metric_expr(struct perf_evlist *evsel_list)if (leader) {/* Search in group */ for_each_group_member (oc, leader) { -if (!strcasecmp (oc->name, metric_names[i])) { +if (!strcasecmp (oc->name, metric_names[i]) && + !oc->collect_stat) { found = true;break ; }
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 39/43 perf stat: Don't merge events in the same PMU
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Event merging is mainly to collapse similar events in lots of different duplicated PMUs.
It can break metric displaying. It's possible for two metrics to have the same event, and when the two events happen in a row the second wouldn't be displayed. This would also not show the second metric.
To avoid this don't merge events in the same PMU. This makes sense, if we have multiple events in the same PMU there is likely some reason for it (e.g. using multiple groups) and we better not merge them.
While in theory it would be possible to construct metrics that have events with the same name in different PMU no current metrics have this problem.
This is the fix for perf stat -M UPI,IPC (needs also another bug fix to completely work)
--- tools/perf/util/stat-display.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/stat-display.c +2 -1
@@ -554,7 +554,8 @@ static void collect_all_aliases(struct perf_stat_config *config, struct perf_evs alias->scale != counter->scale || alias->cgrp != counter->cgrp ||strcmp (alias->unit, counter->unit) || - perf_evsel__is_clock(alias) != perf_evsel__is_clock(counter)) +perf_evsel__is_clock (alias) !=perf_evsel__is_clock (counter) || + !strcmp(alias->pmu_name, counter->pmu_name)) break; alias->merged_stat = true;cb (config, alias, data, false);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 40/43 perf stat: Fix group lookup for metric group
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
The metric group code tries to find a group it added earlier in the evlist. Fix the lookup to handle groups with partially overlaps correctly. When a sub string match fails and we reset the match, we have to compare the first element again.
I also renamed the find_evsel function to find_evsel_group to make its purpose clearer.
With the earlier changes this fixes:
Before:
% perf stat -M UPI,IPC sleep 1
...
1,032,922 uops_retired.retire_slots # 1.1 UPI
1,896,096 inst_retired.any
1,896,096 inst_retired.any
1,177,254 cpu_clk_unhalted.threadAfter:
% perf stat -M UPI,IPC sleep 1
...
1,013,193 uops_retired.retire_slots # 1.1 UPI
932,033 inst_retired.any
932,033 inst_retired.any # 0.9 IPC
1,091,245 cpu_clk_unhalted.thread--- tools/perf/util/metricgroup.c | 47 ++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-)
tools/perf/util/metricgroup.c +35 -12
@@ -85,26 +85,49 @@ struct egroup {const char *metric_expr; }; -static struct perf_evsel *find_evsel (struct perf_evlist *perf_evlist, -const char **ids, -int idnum, -struct perf_evsel **metric_events) +static bool record_evsel (int *ind,struct perf_evsel **start, +int idnum, +struct perf_evsel **metric_events, +struct perf_evsel *ev) +{ + metric_events[*ind] = ev; +if (*ind ==0 ) + *start = ev; +if (++*ind == idnum) { + metric_events[*ind] =NULL ; +return true; + } +return false; +} + +static struct perf_evsel *find_evsel_group (struct perf_evlist *perf_evlist, +const char **ids, +int idnum, +struct perf_evsel **metric_events) {struct perf_evsel *ev, *start =NULL ;int ind =0 ; evlist__for_each_entry (perf_evlist, ev) { +if (ev->collect_stat) +continue ;if (!strcmp (ev->name, ids[ind])) { - metric_events[ind] = ev; -if (ind ==0 ) - start = ev; -if (++ind == idnum) { - metric_events[ind] =NULL ; +if (record_evsel (&ind, &start, idnum, + metric_events, ev))return start; - } }else { +/* +* We saw some other event that is not +* in our list of events. Discard +* the whole match and start again. +*/ ind =0 ; start =NULL ; +if (!strcmp (ev->name, ids[ind])) { +if (record_evsel (&ind, &start, idnum, + metric_events, ev)) +return start; + } } }/*
@@ -134,8 +157,8 @@ static int metricgroup__setup_events(struct list_head *groups, ret = -ENOMEM ;break ; } - evsel =find_evsel (perf_evlist, eg->ids, eg->idnum, - metric_events); + evsel =find_evsel_group (perf_evlist, eg->ids, eg->idnum, + metric_events);if (!evsel) {pr_debug ("Cannot resolve %s: %s\n" , eg->metric_name, eg->metric_expr);
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 41/43 perf stat: Fix metrics with --no-merge
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Since Fixes: 8c5421c016a4 ("perf pmu: Display pmu name when printing unmerged events in stat") using --no-merge adds the PMU name to the evsel name.
This breaks the metric value lookup because the parser doesn't know about this.
Remove the extra postfixes for the metric evaluation.
--- tools/perf/util/stat-shadow.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
tools/perf/util/stat-shadow.c +17 -1
@@ -724,6 +724,7 @@ static void generic_metric(struct perf_stat_config *config,double ratio;int i;void *ctxp = out->ctx; +char *n, *pn;expr__ctx_init (&pctx);expr__add_id (&pctx, name, avg);
@@ -743,7 +744,19 @@ static void generic_metric(struct perf_stat_config *config, stats = &v->stats; scale =1.0 ; } -expr__add_id (&pctx, metric_events[i]->name,avg_stats (stats)*scale); + + n =strdup (metric_events[i]->name); +if (!n) +return ; +/* +* This display code with --no-merge adds [cpu] postfixes. +* These are not supported by the parser. Remove everything +* after the space. +*/ + pn =strchr (n,' ' ); +if (pn) + *pn =0 ; +expr__add_id (&pctx, n,avg_stats (stats)*scale); }if (!metric_events[i]) {const char *p = metric_expr;
@@ -760,6 +773,9 @@ static void generic_metric(struct perf_stat_config *config, (metric_name ? metric_name : name) : "", 0); }else print_metric (config, ctxp,NULL ,NULL ,"" ,0 ); + +for (i =1 ; i < pctx.num_ids; i++) +free ((void *)pctx.ids[i].name); } void perf_stat__print_shadow_stats(struct perf_stat_config *config,
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 42/43 perf annotate: Add csky support
In reply to Arnaldo Carvalho de MeloFrom: Mao Han <[email protected]>
This patch add basic arch initialization and instruction associate support for the csky CPU architecture.
E.g.:
$ perf annotate --stdio2 Samples: 161 of event 'cpu-clock:pppH', 4000 Hz, Event count (approx.): 40250000, [percent: local period] test_4() /usr/lib/perf-test/callchain_test Percent
Disassembly of section .text:
00008420 <test_4>:
test_4():
subi sp, sp, 4
st.w r8, (sp, 0x0)
mov r8, sp
subi sp, sp, 8
subi r3, r8, 4
movi r2, 0
st.w r2, (r3, 0x0)
↓ br 2e
100.00 14: subi r3, r8, 4
ld.w r2, (r3, 0x0)
subi r3, r8, 8
st.w r2, (r3, 0x0)
subi r3, r8, 4
ld.w r3, (r3, 0x0)
addi r2, r3, 1
subi r3, r8, 4
st.w r2, (r3, 0x0)
2e: subi r3, r8, 4
ld.w r2, (r3, 0x0)
lrw r3, 0x98967f // 8598 <main+0x28> cmplt r3, r2
↑ bf 14
mov r0, r0
mov r0, r0
mov sp, r8
ld.w r8, (sp, 0x0)
addi sp, sp, 4
← rts
--- tools/perf/arch/csky/annotate/instructions.c | 48 ++++++++++++++++++++ tools/perf/util/annotate.c | 5 ++ 2 files changed, 53 insertions(+) create mode 100644 tools/perf/arch/csky/annotate/instructions.c
tools/perf/arch/csky/annotate/instructions.c new file +48 -0
@@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. + +#include <linux/compiler.h> + +static struct ins_ops *csky__associate_ins_ops (struct arch *arch, +const char *name) +{ +struct ins_ops *ops =NULL ; + +/* catch all kind of jumps */ +if (!strcmp (name,"bt" ) || + !strcmp (name,"bf" ) || + !strcmp (name,"bez" ) || + !strcmp (name,"bnez" ) || + !strcmp (name,"bnezad" ) || + !strcmp (name,"bhsz" ) || + !strcmp (name,"bhz" ) || + !strcmp (name,"blsz" ) || + !strcmp (name,"blz" ) || + !strcmp (name,"br" ) || + !strcmp (name,"jmpi" ) || + !strcmp (name,"jmp" )) + ops = &jump_ops; + +/* catch function call */ +if (!strcmp (name,"bsr" ) || + !strcmp (name,"jsri" ) || + !strcmp (name,"jsr" )) + ops = &call_ops; + +/* catch function return */ +if (!strcmp (name,"rts" )) + ops = &ret_ops; + +if (ops) +arch__associate_ins_ops (arch, name, ops); +return ops; +} + +static int csky__annotate_init (struct arch *arch,char *cpuid__maybe_unused ) +{ + arch->initialized = true; + arch->objdump.comment_char ='/' ; + arch->associate_instruction_ops = csky__associate_ins_ops; + +return 0 ; +}
tools/perf/util/annotate.c +5 -0
@@ -145,6 +145,7 @@ static int arch__associate_ins_ops(struct arch* arch, const char *name, struct i#include "arch/arc/annotate/instructions.c" #include "arch/arm/annotate/instructions.c" #include "arch/arm64/annotate/instructions.c" +#include "arch/csky/annotate/instructions.c" #include "arch/x86/annotate/instructions.c" #include "arch/powerpc/annotate/instructions.c" #include "arch/s390/annotate/instructions.c"
@@ -163,6 +164,10 @@ static struct arch architectures[] = { .name = "arm64", .init = arm64__annotate_init, }, + { + .name = "csky", + .init = csky__annotate_init, + }, { .name = "x86", .init = x86__annotate_init,
Signature · 1 line
2.20.1
Arnaldo Carvalho de Melo
maintainerPATCH 43/43 perf jevents: Use nonlocal include statements in pmu-events.c
In reply to Arnaldo Carvalho de MeloFrom: Luke Mujica <[email protected]>
Change pmu-events.c to not use local include statements. The code that creates the include statements for pmu-events.c is in jevents.c.
pmu-events.c is a generated file, and for build systems that put generated files in a separate directory, include statements with local pathing cannot find non-generated files.
--- tools/perf/pmu-events/jevents.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/pmu-events/jevents.c +2 -2
@@ -841,7 +841,7 @@ static void create_empty_mapping(const char *output_file)_Exit (1 ); } -fprintf (outfp,"#include \"../../pmu-events/pmu-events.h\"\n" ); +fprintf (outfp,"#include \"pmu-events/pmu-events.h\"\n" );print_mapping_table_prefix (outfp);print_mapping_table_suffix (outfp);fclose (outfp);
@@ -1096,7 +1096,7 @@ int main(int argc, char *argv[]) }/* Include pmu-events.h first */ -fprintf (eventsfp,"#include \"../../pmu-events/pmu-events.h\"\n" ); +fprintf (eventsfp,"#include \"pmu-events/pmu-events.h\"\n" );/* * The mapfile allows multiple CPUids to point to the same JSON file,
Signature · 1 line
2.20.1
Quoted 213 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
Best regards,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit
fd7d55172d1e2e501e6da0a5c1de25f06612dc2e:perf/cgroups: Don't rotate events for cgroups unnecessarily (2019-06-24 19:30:04 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-5.3-20190701for you to fetch changes up to
06c642c0e9fceafd16b1a4c80d44b1c09e282215:perf jevents: Use nonlocal include statements in
pmu-events.c(2019-07-01 22:50:42 -0300)----------------------------------------------------------------
perf/core improvements and fixes:perf annotate:
Mao Han:
- Add support for the csky processor architecture.
perf stat:
Andi Kleen:
- Fix metrics with --no-merge.
- Don't merge events in the same PMU.
- Fix group lookup for metric group.
Intel PT:
Adrian Hunter:
- Improve CBR (Core to Bus Ratio) packets support.
- Fix thread stack return from kernel for kernel only case.
- Export power and ptwrite events to sqlite and postgresql.
core libraries:
Arnaldo Carvalho de Melo:
- Find routines in
tools/perf/util/that have implementations in the kernel libraries (lib/*.c), such asstrreplace(),strim(),skip_spaces()and reuse them after making a copy intotools/libandtools/include/.This continues the effort of having
tools/code looking as much as possible like kernel source code, to help encourage people to work on both the kernel and in tools hosted in the kernel sources.That in turn will help moving stuff that uses those routines to
tools/lib/perf/where they will be made available for use in other tools.In the process ditch old cruft, remove unused variables and add missing include directives for headers providing things used in places that were building by sheer luck.
Kyle Meyer:
- Bump
MAX_NR_CPUSandMAX_CACHESto get these tools to work on more machines.Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Adrian Hunter (9):
perf thread-stack: Fix thread stack return from kernel for kernel-only case perf thread-stack: Eliminate code duplicatingthread_stack__pop_ks()perf intel-pt: Decoder to output CBR changes immediately
perf intel-pt: Cater for CBR change in PSB+
perf intel-pt: Add CBR value to decoder state
perf intel-pt: Synthesize CBR events when last seen value changes
perf db-export: Export synth events
perf scripts python:export-to-sqlite.py: Export Intel PT power and ptwrite events perf scripts python:export-to-postgresql.py: Export Intel PT power and ptwrite eventsAndi Kleen (4):
perf stat: Make metric event lookup more robust perf stat: Don't merge events in the same PMU perf stat: Fix group lookup for metric group perf stat: Fix metrics with --no-mergeArnaldo Carvalho de Melo (26):
perf ctype: Remove unused 'graph_line' variable
perf ui stdio: No need to use 'spaces' to left align
perf ctype: Remove now unused 'spaces' variable
perf string: Move 'dots' and 'graph_dotted_line' out ofsane_ctype.htools x86 machine: Add missingutil.hto pick up 'page_size' perf kallsyms: Adopt hex2u64 fromtools/perf/util/util.h
perf symbols: We needutil.hinsymbol-elf.cforzfree()
perf tools: Remove old baggage that isutil/include/linux/ctype.hperf tools: Add missingutil.hto pick up 'page_size' variable tools perf: Move fromsane_ctype.hobtained from git to the Linux's original perf tools: Uselinux/ctype.hin more places
tools lib: Adoptskip_spaces()from the kernel sources
perf stat: Use recently introducedskip_spaces()
perf header: Useskip_spaces()in__write_cpudesc()
perf time-utils: Useskip_spaces()
perf probe: Useskip_spaces()for argv handling
perf strfilter: Useskip_spaces()
perf metricgroup: Usestrsep()
perf report: Useskip_spaces()
perf tools: Ditchrtrim(), useskip_spaces()to get closer to the kernel tools lib: Adoptstrim()from the kernel
perf tools: Removetrim()implementation, use tools/lib'sstrim()perf tools: Ditchrtrim(), usestrim()fromtools/lib
tools lib: Adoptstrreplace()from the kernel
perf tools: Dropstrxfrchar(), usestrreplace()equivalent from kernel tools lib: Move argv_{split,free} fromtools/perf/util/Kyle Meyer (1):
perf tools: IncreaseMAX_NR_CPUSandMAX_CACHESLuke Mujica (1):
perf jevents: Use nonlocal include statements inpmu-events.cMao Han (1):
perf annotate: Add csky supportNumfor Mbiziwo-Tiapo (1):
perf tools: Fixcache.hinclude directivetools/include/linux/ctype.h | 75 ++++++ tools/include/linux/string.h | 11 +- tools/lib/argv_split.c | 100 ++++++++ tools/lib/ctype.c | 35 +++ tools/lib/string.c | 55 +++++ tools/lib/symbol/kallsyms.c | 14 +- tools/lib/symbol/kallsyms.h | 2 + tools/perf/MANIFEST | 2 + tools/perf/arch/arm/util/cs-etm.c | 1 + tools/perf/arch/csky/annotate/instructions.c | 48 ++++ tools/perf/arch/s390/util/header.c | 2 +- tools/perf/arch/x86/tests/intel-cqm.c | 1 + tools/perf/arch/x86/util/intel-pt.c | 1 + tools/perf/arch/x86/util/machine.c | 3 +- tools/perf/builtin-kmem.c | 3 +- tools/perf/builtin-report.c | 5 +- tools/perf/builtin-sched.c | 3 +- tools/perf/builtin-script.c | 14 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-top.c | 3 +- tools/perf/builtin-trace.c | 2 +- tools/perf/check-headers.sh | 2 + tools/perf/perf.c | 1 + tools/perf/perf.h | 2 +- tools/perf/pmu-events/jevents.c | 4 +- tools/perf/scripts/python/export-to-postgresql.py | 251 +++++++++++++++++++++ tools/perf/scripts/python/export-to-sqlite.py | 239 ++++++++++++++++++++ tools/perf/tests/builtin-test.c | 3 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/ui/browser.c | 4 +- tools/perf/ui/browsers/hists.c | 10 +- tools/perf/ui/browsers/map.c | 2 +- tools/perf/ui/gtk/hists.c | 5 +- tools/perf/ui/progress.c | 2 +- tools/perf/ui/stdio/hist.c | 16 +- tools/perf/util/Build | 9 + tools/perf/util/annotate.c | 20 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/build-id.c | 2 +- tools/perf/util/config.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/ctype.c | 49 ---- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/debug.c | 2 +- tools/perf/util/demangle-java.c | 2 +- tools/perf/util/dso.c | 3 +- tools/perf/util/env.c | 2 +- tools/perf/util/event.c | 6 +- tools/perf/util/evsel.c | 3 +- tools/perf/util/header.c | 15 +- tools/perf/util/include/linux/ctype.h | 1 - .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 24 +- .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 1 + tools/perf/util/intel-pt.c | 65 ++++-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/machine.c | 3 +- tools/perf/util/metricgroup.c | 52 +++-- tools/perf/util/pmu.c | 5 +- tools/perf/util/print_binary.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-finder.h | 2 +- tools/perf/util/python-ext-sources | 3 +- tools/perf/util/python.c | 1 + tools/perf/util/sane_ctype.h | 52 ----- .../util/scripting-engines/trace-event-python.c | 46 +++- tools/perf/util/srcline.c | 3 +- tools/perf/util/stat-display.c | 14 +- tools/perf/util/stat-shadow.c | 23 +- tools/perf/util/strfilter.c | 6 +- tools/perf/util/string.c | 169 +------------- tools/perf/util/string2.h | 15 +- tools/perf/util/symbol-elf.c | 3 +- tools/perf/util/symbol.c | 2 +- tools/perf/util/thread-stack.c | 48 ++-- tools/perf/util/thread_map.c | 3 +- tools/perf/util/time-utils.c | 8 +- tools/perf/util/trace-event-parse.c | 2 +- tools/perf/util/util.c | 13 -- tools/perf/util/util.h | 1 -
Quoted 8 lines
79 files changed, 1167 insertions(+), 450 deletions(-) create mode 100644 tools/include/linux/ctype.h create mode 100644 tools/lib/argv_split.c create mode 100644 tools/lib/ctype.c create mode 100644 tools/perf/arch/csky/annotate/instructions.c delete mode 100644 tools/perf/util/ctype.c delete mode 100644 tools/perf/util/include/linux/ctype.h delete mode 100644 tools/perf/util/sane_ctype.h
Pulled, thanks a lot Arnaldo!
Ingo