aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2016-07-13 02:50:54 -0400
committerIngo Molnar <mingo@kernel.org>2016-07-13 02:50:54 -0400
commit68cf16c6b8b4ed818bb6211e1975fd75b78c7e86 (patch)
tree46994b044d96741a2c4723a27e8a7f70487b4107 /tools/perf
parent44530d588e142a96cf0cd345a7cb8911c4f88720 (diff)
parent6d248fbda59c51ef5f2e90e11551d9e17aeb226f (diff)
Merge tag 'perf-core-for-mingo-20160712' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: User visible changes: - Add demangling of symbols in programs written in the Rust language (David Tolnay) - Add support for tracepoints in the python binding, including an example, that sets up and parses sched:sched_switch events, tools/perf/python/tracepoint.py (Jiri Olsa) - Introduce --stdio-color to set up the color output mode selection in 'annotate' and 'report', allowing emit color escape sequences when redirecting the output of these tools (Arnaldo Carvalho de Melo) Infrastructure changes: - Various tweaks to allow the 'perf trace' beautifiers to build without using kernel headers and in a wider range of Linux distributions/releases (Arnaldo Carvalho de Melo) - Stop using kernel source files, instead copy what is needed and check when the original kernel source file gets modified, warning the developers about it. This helps in building the tool in older systems and even in recent ones, for just added kernel features for which ABI details (struct changes, defines, etc) still are not available on system headers (Arnaldo Carvalho de Melo) - Be consistent in how to use strerror_r, adding a wrapper that makes sure that it returns a pointer to passed buffer, and using the XSI variant, that is available in more libc implementations (Arnaldo Carvalho de Melo) - Avoid checking code drift on busibox's diff perf intel-pt-decoder, as it doesn't have the '-I' command line switch to check for regexps (Arnaldo Carvalho de Melo) - Add missing headers in various places (Arnaldo Carvalho de Melo) - Remove unneeded headers from various other places (Arnaldo Carvalho de Melo) - Add feature detection for gelf_getnote(), disabling SDT support if not present (Arnaldo Carvalho de Melo) - Fix oddities with GCC 5.3.0 by initializing some variables (Arnaldo Carvalho de Melo) - With those changes in place perf now builds on Alpine Linux 3.4, in addition to on centos (5, 6, 7), debian (7, 8, experimental), fedora (21, 22, 23, 24, rawhide), mageia 5, opensuse (13.2, 42.1) and ubuntu (12.04.5, 14.04.4, 15.10, 16.04) and will be test build on those systems prior to future pull requests. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/perf-annotate.txt7
-rw-r--r--tools/perf/Documentation/perf-report.txt7
-rw-r--r--tools/perf/MANIFEST41
-rw-r--r--tools/perf/Makefile.perf63
-rw-r--r--tools/perf/arch/common.c1
-rw-r--r--tools/perf/arch/x86/tests/rdpmc.c8
-rw-r--r--tools/perf/bench/futex-hash.c15
-rw-r--r--tools/perf/bench/futex-lock-pi.c11
-rw-r--r--tools/perf/bench/futex-requeue.c11
-rw-r--r--tools/perf/bench/futex-wake-parallel.c11
-rw-r--r--tools/perf/bench/futex-wake.c11
-rw-r--r--tools/perf/bench/mem-memcpy-x86-64-asm.S2
-rw-r--r--tools/perf/bench/mem-memset-x86-64-asm.S2
-rw-r--r--tools/perf/bench/numa.c4
-rw-r--r--tools/perf/builtin-annotate.c3
-rw-r--r--tools/perf/builtin-buildid-cache.c8
-rw-r--r--tools/perf/builtin-help.c8
-rw-r--r--tools/perf/builtin-kvm.c4
-rw-r--r--tools/perf/builtin-probe.c2
-rw-r--r--tools/perf/builtin-record.c6
-rw-r--r--tools/perf/builtin-report.c3
-rw-r--r--tools/perf/builtin-sched.c2
-rw-r--r--tools/perf/builtin-stat.c4
-rw-r--r--tools/perf/builtin-top.c6
-rw-r--r--tools/perf/builtin-trace.c9
-rw-r--r--tools/perf/config/Makefile16
-rw-r--r--tools/perf/perf-sys.h18
-rw-r--r--tools/perf/perf.c18
-rwxr-xr-xtools/perf/python/tracepoint.py47
-rw-r--r--tools/perf/tests/backward-ring-buffer.c4
-rw-r--r--tools/perf/tests/bpf-script-example.c4
-rw-r--r--tools/perf/tests/bpf.c10
-rw-r--r--tools/perf/tests/builtin-test.c2
-rw-r--r--tools/perf/tests/cpumap.c7
-rw-r--r--tools/perf/tests/event-times.c2
-rw-r--r--tools/perf/tests/fdarray.c1
-rw-r--r--tools/perf/tests/llvm.c1
-rw-r--r--tools/perf/tests/mmap-basic.c9
-rw-r--r--tools/perf/tests/openat-syscall-all-cpus.c7
-rw-r--r--tools/perf/tests/openat-syscall-tp-fields.c11
-rw-r--r--tools/perf/tests/openat-syscall.c2
-rw-r--r--tools/perf/tests/perf-record.c11
-rw-r--r--tools/perf/tests/sw-clock.c4
-rw-r--r--tools/perf/tests/task-exit.c4
-rw-r--r--tools/perf/trace/beauty/flock.c17
-rw-r--r--tools/perf/trace/beauty/futex_op.c16
-rw-r--r--tools/perf/trace/beauty/mmap.c77
-rw-r--r--tools/perf/trace/beauty/msg_flags.c1
-rw-r--r--tools/perf/trace/beauty/open_flags.c15
-rw-r--r--tools/perf/trace/beauty/seccomp.c2
-rw-r--r--tools/perf/ui/browsers/hists.c2
-rw-r--r--tools/perf/ui/gtk/util.c1
-rw-r--r--tools/perf/ui/helpline.c1
-rw-r--r--tools/perf/ui/setup.c7
-rw-r--r--tools/perf/ui/tui/setup.c2
-rw-r--r--tools/perf/ui/ui.h4
-rw-r--r--tools/perf/util/Build11
-rw-r--r--tools/perf/util/alias.c1
-rw-r--r--tools/perf/util/bpf-loader.c2
-rw-r--r--tools/perf/util/build-id.c2
-rw-r--r--tools/perf/util/cache.h3
-rw-r--r--tools/perf/util/cloexec.c18
-rw-r--r--tools/perf/util/color.c3
-rw-r--r--tools/perf/util/data.c4
-rw-r--r--tools/perf/util/debug.h2
-rw-r--r--tools/perf/util/demangle-rust.c269
-rw-r--r--tools/perf/util/demangle-rust.h7
-rw-r--r--tools/perf/util/dso.c6
-rw-r--r--tools/perf/util/dso.h1
-rw-r--r--tools/perf/util/event.h1
-rw-r--r--tools/perf/util/evlist.c8
-rw-r--r--tools/perf/util/evlist.h3
-rw-r--r--tools/perf/util/evsel.c20
-rw-r--r--tools/perf/util/evsel.h18
-rw-r--r--tools/perf/util/help-unknown-cmd.c1
-rw-r--r--tools/perf/util/hist.c204
-rw-r--r--tools/perf/util/hist.h11
-rw-r--r--tools/perf/util/include/asm/alternative-asm.h9
-rw-r--r--tools/perf/util/include/asm/unistd_32.h1
-rw-r--r--tools/perf/util/include/asm/unistd_64.h1
-rw-r--r--tools/perf/util/intel-pt-decoder/Build5
-rw-r--r--tools/perf/util/levenshtein.c4
-rw-r--r--tools/perf/util/llvm-utils.c10
-rw-r--r--tools/perf/util/path.c2
-rw-r--r--tools/perf/util/probe-event.c6
-rw-r--r--tools/perf/util/probe-file.c12
-rw-r--r--tools/perf/util/probe-finder.c4
-rw-r--r--tools/perf/util/python-ext-sources2
-rw-r--r--tools/perf/util/python.c162
-rw-r--r--tools/perf/util/quote.c4
-rw-r--r--tools/perf/util/quote.h3
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c4
-rw-r--r--tools/perf/util/sort.h6
-rw-r--r--tools/perf/util/strbuf.c2
-rw-r--r--tools/perf/util/strbuf.h3
-rw-r--r--tools/perf/util/symbol-elf.c11
-rw-r--r--tools/perf/util/target.c3
-rw-r--r--tools/perf/util/trace-event.c8
-rw-r--r--tools/perf/util/trace-event.h2
-rw-r--r--tools/perf/util/util.h6
100 files changed, 1138 insertions, 299 deletions
diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
index 778f54d4d0bd..8ffbd272952d 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -61,6 +61,13 @@ OPTIONS
61 61
62--stdio:: Use the stdio interface. 62--stdio:: Use the stdio interface.
63 63
64--stdio-color::
65 'always', 'never' or 'auto', allowing configuring color output
66 via the command line, in addition to via "color.ui" .perfconfig.
67 Use '--stdio-color always' to generate color even when redirecting
68 to a pipe or file. Using just '--stdio-color' is equivalent to
69 using 'always'.
70
64--tui:: Use the TUI interface. Use of --tui requires a tty, if one is not 71--tui:: Use the TUI interface. Use of --tui requires a tty, if one is not
65 present, as when piping to other commands, the stdio interface is 72 present, as when piping to other commands, the stdio interface is
66 used. This interfaces starts by centering on the line with more 73 used. This interfaces starts by centering on the line with more
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 9cbddc290aff..2d1746295abf 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -265,6 +265,13 @@ OPTIONS
265 265
266--stdio:: Use the stdio interface. 266--stdio:: Use the stdio interface.
267 267
268--stdio-color::
269 'always', 'never' or 'auto', allowing configuring color output
270 via the command line, in addition to via "color.ui" .perfconfig.
271 Use '--stdio-color always' to generate color even when redirecting
272 to a pipe or file. Using just '--stdio-color' is equivalent to
273 using 'always'.
274
268--tui:: Use the TUI interface, that is integrated with annotate and allows 275--tui:: Use the TUI interface, that is integrated with annotate and allows
269 zooming into DSOs or threads, among other features. Use of --tui 276 zooming into DSOs or threads, among other features. Use of --tui
270 requires a tty, if one is not present, as when piping to other 277 requires a tty, if one is not present, as when piping to other
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 8c8c6b9ce915..923eda2e7d52 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -12,13 +12,23 @@ tools/arch/sparc/include/asm/barrier_32.h
12tools/arch/sparc/include/asm/barrier_64.h 12tools/arch/sparc/include/asm/barrier_64.h
13tools/arch/tile/include/asm/barrier.h 13tools/arch/tile/include/asm/barrier.h
14tools/arch/x86/include/asm/barrier.h 14tools/arch/x86/include/asm/barrier.h
15tools/arch/x86/include/asm/cpufeatures.h
16tools/arch/x86/include/asm/disabled-features.h
17tools/arch/x86/include/asm/required-features.h
18tools/arch/x86/include/uapi/asm/svm.h
19tools/arch/x86/include/uapi/asm/vmx.h
20tools/arch/x86/include/uapi/asm/kvm.h
21tools/arch/x86/include/uapi/asm/kvm_perf.h
22tools/arch/x86/lib/memcpy_64.S
23tools/arch/x86/lib/memset_64.S
24tools/arch/s390/include/uapi/asm/kvm_perf.h
25tools/arch/s390/include/uapi/asm/sie.h
15tools/arch/xtensa/include/asm/barrier.h 26tools/arch/xtensa/include/asm/barrier.h
16tools/scripts 27tools/scripts
17tools/build 28tools/build
18tools/arch/x86/include/asm/atomic.h 29tools/arch/x86/include/asm/atomic.h
19tools/arch/x86/include/asm/rmwcc.h 30tools/arch/x86/include/asm/rmwcc.h
20tools/lib/traceevent 31tools/lib/traceevent
21tools/lib/bpf
22tools/lib/api 32tools/lib/api
23tools/lib/bpf 33tools/lib/bpf
24tools/lib/subcmd 34tools/lib/subcmd
@@ -29,6 +39,9 @@ tools/lib/symbol/kallsyms.c
29tools/lib/symbol/kallsyms.h 39tools/lib/symbol/kallsyms.h
30tools/lib/find_bit.c 40tools/lib/find_bit.c
31tools/lib/bitmap.c 41tools/lib/bitmap.c
42tools/lib/str_error_r.c
43tools/lib/vsprintf.c
44tools/include/asm/alternative-asm.h
32tools/include/asm/atomic.h 45tools/include/asm/atomic.h
33tools/include/asm/barrier.h 46tools/include/asm/barrier.h
34tools/include/asm/bug.h 47tools/include/asm/bug.h
@@ -52,10 +65,15 @@ tools/include/linux/hash.h
52tools/include/linux/kernel.h 65tools/include/linux/kernel.h
53tools/include/linux/list.h 66tools/include/linux/list.h
54tools/include/linux/log2.h 67tools/include/linux/log2.h
68tools/include/uapi/linux/bpf.h
69tools/include/uapi/linux/bpf_common.h
70tools/include/uapi/linux/hw_breakpoint.h
71tools/include/uapi/linux/perf_event.h
55tools/include/linux/poison.h 72tools/include/linux/poison.h
56tools/include/linux/rbtree.h 73tools/include/linux/rbtree.h
57tools/include/linux/rbtree_augmented.h 74tools/include/linux/rbtree_augmented.h
58tools/include/linux/string.h 75tools/include/linux/string.h
76tools/include/linux/stringify.h
59tools/include/linux/types.h 77tools/include/linux/types.h
60tools/include/linux/err.h 78tools/include/linux/err.h
61tools/include/linux/bitmap.h 79tools/include/linux/bitmap.h
@@ -64,31 +82,12 @@ include/asm-generic/bitops/const_hweight.h
64include/asm-generic/bitops/fls64.h 82include/asm-generic/bitops/fls64.h
65include/asm-generic/bitops/__fls.h 83include/asm-generic/bitops/__fls.h
66include/asm-generic/bitops/fls.h 84include/asm-generic/bitops/fls.h
67include/linux/perf_event.h
68include/linux/list.h 85include/linux/list.h
69include/linux/hash.h 86include/linux/hash.h
70include/linux/stringify.h
71include/linux/swab.h 87include/linux/swab.h
72arch/*/include/asm/unistd*.h 88arch/*/include/asm/unistd*.h
73arch/*/include/uapi/asm/unistd*.h 89arch/*/include/uapi/asm/unistd*.h
74arch/*/include/uapi/asm/perf_regs.h 90tools/arch/*/include/uapi/asm/perf_regs.h
75arch/*/lib/memcpy*.S
76arch/*/lib/memset*.S
77arch/*/include/asm/*features.h
78include/linux/poison.h 91include/linux/poison.h
79include/linux/hw_breakpoint.h
80include/uapi/linux/perf_event.h
81include/uapi/linux/bpf.h
82include/uapi/linux/bpf_common.h
83include/uapi/linux/const.h 92include/uapi/linux/const.h
84include/uapi/linux/swab.h 93include/uapi/linux/swab.h
85include/uapi/linux/hw_breakpoint.h
86arch/x86/include/asm/svm.h
87arch/x86/include/asm/vmx.h
88arch/x86/include/asm/kvm_host.h
89arch/x86/include/uapi/asm/svm.h
90arch/x86/include/uapi/asm/vmx.h
91arch/x86/include/uapi/asm/kvm.h
92arch/x86/include/uapi/asm/kvm_perf.h
93arch/s390/include/uapi/asm/sie.h
94arch/s390/include/uapi/asm/kvm_perf.h
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index d0a2cb11296f..feb2c66b110b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -345,6 +345,69 @@ export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK
345include $(srctree)/tools/build/Makefile.include 345include $(srctree)/tools/build/Makefile.include
346 346
347$(PERF_IN): prepare FORCE 347$(PERF_IN): prepare FORCE
348 @(test -f ../../include/uapi/linux/perf_event.h && ( \
349 (diff -B ../include/uapi/linux/perf_event.h ../../include/uapi/linux/perf_event.h >/dev/null) \
350 || echo "Warning: tools/include/uapi/linux/perf_event.h differs from kernel" >&2 )) || true
351 @(test -f ../../include/uapi/linux/hw_breakpoint.h && ( \
352 (diff -B ../include/uapi/linux/hw_breakpoint.h ../../include/uapi/linux/hw_breakpoint.h >/dev/null) \
353 || echo "Warning: tools/include/uapi/linux/hw_breakpoint.h differs from kernel" >&2 )) || true
354 @(test -f ../../arch/x86/include/asm/disabled-features.h && ( \
355 (diff -B ../arch/x86/include/asm/disabled-features.h ../../arch/x86/include/asm/disabled-features.h >/dev/null) \
356 || echo "Warning: tools/arch/x86/include/asm/disabled-features.h differs from kernel" >&2 )) || true
357 @(test -f ../../arch/x86/include/asm/required-features.h && ( \
358 (diff -B ../arch/x86/include/asm/required-features.h ../../arch/x86/include/asm/required-features.h >/dev/null) \
359 || echo "Warning: tools/arch/x86/include/asm/required-features.h differs from kernel" >&2 )) || true
360 @(test -f ../../arch/x86/include/asm/cpufeatures.h && ( \
361 (diff -B ../arch/x86/include/asm/cpufeatures.h ../../arch/x86/include/asm/cpufeatures.h >/dev/null) \
362 || echo "Warning: tools/arch/x86/include/asm/cpufeatures.h differs from kernel" >&2 )) || true
363 @(test -f ../../arch/x86/lib/memcpy_64.S && ( \
364 (diff -B ../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memcpy_64.S >/dev/null) \
365 || echo "Warning: tools/arch/x86/lib/memcpy_64.S differs from kernel" >&2 )) || true
366 @(test -f ../../arch/x86/lib/memset_64.S && ( \
367 (diff -B ../arch/x86/lib/memset_64.S ../../arch/x86/lib/memset_64.S >/dev/null) \
368 || echo "Warning: tools/arch/x86/lib/memset_64.S differs from kernel" >&2 )) || true
369 @(test -f ../../arch/arm/include/uapi/asm/perf_regs.h && ( \
370 (diff -B ../arch/arm/include/uapi/asm/perf_regs.h ../../arch/arm/include/uapi/asm/perf_regs.h >/dev/null) \
371 || echo "Warning: tools/arch/arm/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
372 @(test -f ../../arch/arm64/include/uapi/asm/perf_regs.h && ( \
373 (diff -B ../arch/arm64/include/uapi/asm/perf_regs.h ../../arch/arm64/include/uapi/asm/perf_regs.h >/dev/null) \
374 || echo "Warning: tools/arch/arm64/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
375 @(test -f ../../arch/powerpc/include/uapi/asm/perf_regs.h && ( \
376 (diff -B ../arch/powerpc/include/uapi/asm/perf_regs.h ../../arch/powerpc/include/uapi/asm/perf_regs.h >/dev/null) \
377 || echo "Warning: tools/arch/powerpc/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
378 @(test -f ../../arch/x86/include/uapi/asm/perf_regs.h && ( \
379 (diff -B ../arch/x86/include/uapi/asm/perf_regs.h ../../arch/x86/include/uapi/asm/perf_regs.h >/dev/null) \
380 || echo "Warning: tools/arch/x86/include/uapi/asm/perf_regs.h differs from kernel" >&2 )) || true
381 @(test -f ../../arch/x86/include/uapi/asm/kvm.h && ( \
382 (diff -B ../arch/x86/include/uapi/asm/kvm.h ../../arch/x86/include/uapi/asm/kvm.h >/dev/null) \
383 || echo "Warning: tools/arch/x86/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
384 @(test -f ../../arch/x86/include/uapi/asm/kvm_perf.h && ( \
385 (diff -B ../arch/x86/include/uapi/asm/kvm_perf.h ../../arch/x86/include/uapi/asm/kvm_perf.h >/dev/null) \
386 || echo "Warning: tools/arch/x86/include/uapi/asm/kvm_perf.h differs from kernel" >&2 )) || true
387 @(test -f ../../arch/x86/include/uapi/asm/svm.h && ( \
388 (diff -B ../arch/x86/include/uapi/asm/svm.h ../../arch/x86/include/uapi/asm/svm.h >/dev/null) \
389 || echo "Warning: tools/arch/x86/include/uapi/asm/svm.h differs from kernel" >&2 )) || true
390 @(test -f ../../arch/x86/include/uapi/asm/vmx.h && ( \
391 (diff -B ../arch/x86/include/uapi/asm/vmx.h ../../arch/x86/include/uapi/asm/vmx.h >/dev/null) \
392 || echo "Warning: tools/arch/x86/include/uapi/asm/vmx.h differs from kernel" >&2 )) || true
393 @(test -f ../../arch/powerpc/include/uapi/asm/kvm.h && ( \
394 (diff -B ../arch/powerpc/include/uapi/asm/kvm.h ../../arch/powerpc/include/uapi/asm/kvm.h >/dev/null) \
395 || echo "Warning: tools/arch/powerpc/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
396 @(test -f ../../arch/s390/include/uapi/asm/kvm.h && ( \
397 (diff -B ../arch/s390/include/uapi/asm/kvm.h ../../arch/s390/include/uapi/asm/kvm.h >/dev/null) \
398 || echo "Warning: tools/arch/s390/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
399 @(test -f ../../arch/s390/include/uapi/asm/kvm_perf.h && ( \
400 (diff -B ../arch/s390/include/uapi/asm/kvm_perf.h ../../arch/s390/include/uapi/asm/kvm_perf.h >/dev/null) \
401 || echo "Warning: tools/arch/s390/include/uapi/asm/kvm_perf.h differs from kernel" >&2 )) || true
402 @(test -f ../../arch/s390/include/uapi/asm/sie.h && ( \
403 (diff -B ../arch/s390/include/uapi/asm/sie.h ../../arch/s390/include/uapi/asm/sie.h >/dev/null) \
404 || echo "Warning: tools/arch/s390/include/uapi/asm/sie.h differs from kernel" >&2 )) || true
405 @(test -f ../../arch/arm/include/uapi/asm/kvm.h && ( \
406 (diff -B ../arch/arm/include/uapi/asm/kvm.h ../../arch/arm/include/uapi/asm/kvm.h >/dev/null) \
407 || echo "Warning: tools/arch/arm/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
408 @(test -f ../../arch/arm64/include/uapi/asm/kvm.h && ( \
409 (diff -B ../arch/arm64/include/uapi/asm/kvm.h ../../arch/arm64/include/uapi/asm/kvm.h >/dev/null) \
410 || echo "Warning: tools/arch/arm64/include/uapi/asm/kvm.h differs from kernel" >&2 )) || true
348 $(Q)$(MAKE) $(build)=perf 411 $(Q)$(MAKE) $(build)=perf
349 412
350$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST) 413$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index ee6966812a5a..886dd2aaff0d 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -1,6 +1,7 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <sys/utsname.h> 2#include <sys/utsname.h>
3#include "common.h" 3#include "common.h"
4#include "../util/util.h"
4#include "../util/debug.h" 5#include "../util/debug.h"
5 6
6const char *const arm_triplets[] = { 7const char *const arm_triplets[] = {
diff --git a/tools/perf/arch/x86/tests/rdpmc.c b/tools/perf/arch/x86/tests/rdpmc.c
index 72193f19d6d7..500cf96db979 100644
--- a/tools/perf/arch/x86/tests/rdpmc.c
+++ b/tools/perf/arch/x86/tests/rdpmc.c
@@ -1,12 +1,16 @@
1#include <errno.h>
1#include <unistd.h> 2#include <unistd.h>
2#include <stdlib.h> 3#include <stdlib.h>
3#include <signal.h> 4#include <signal.h>
4#include <sys/mman.h> 5#include <sys/mman.h>
6#include <sys/types.h>
7#include <sys/wait.h>
5#include <linux/types.h> 8#include <linux/types.h>
6#include "perf.h" 9#include "perf.h"
7#include "debug.h" 10#include "debug.h"
8#include "tests/tests.h" 11#include "tests/tests.h"
9#include "cloexec.h" 12#include "cloexec.h"
13#include "util.h"
10#include "arch-tests.h" 14#include "arch-tests.h"
11 15
12static u64 rdpmc(unsigned int counter) 16static u64 rdpmc(unsigned int counter)
@@ -111,14 +115,14 @@ static int __test__rdpmc(void)
111 if (fd < 0) { 115 if (fd < 0) {
112 pr_err("Error: sys_perf_event_open() syscall returned " 116 pr_err("Error: sys_perf_event_open() syscall returned "
113 "with %d (%s)\n", fd, 117 "with %d (%s)\n", fd,
114 strerror_r(errno, sbuf, sizeof(sbuf))); 118 str_error_r(errno, sbuf, sizeof(sbuf)));
115 return -1; 119 return -1;
116 } 120 }
117 121
118 addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0); 122 addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
119 if (addr == (void *)(-1)) { 123 if (addr == (void *)(-1)) {
120 pr_err("Error: mmap() syscall returned with (%s)\n", 124 pr_err("Error: mmap() syscall returned with (%s)\n",
121 strerror_r(errno, sbuf, sizeof(sbuf))); 125 str_error_r(errno, sbuf, sizeof(sbuf)));
122 goto out_close; 126 goto out_close;
123 } 127 }
124 128
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index 0999ac536d86..8024cd5febd2 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -8,18 +8,23 @@
8 * many threads and futexes as possible. 8 * many threads and futexes as possible.
9 */ 9 */
10 10
11#include "../perf.h" 11/* For the CLR_() macros */
12#include "../util/util.h" 12#include <pthread.h>
13
14#include <errno.h>
15#include <signal.h>
16#include <stdlib.h>
17#include <linux/compiler.h>
18#include <linux/kernel.h>
19#include <sys/time.h>
20
13#include "../util/stat.h" 21#include "../util/stat.h"
14#include <subcmd/parse-options.h> 22#include <subcmd/parse-options.h>
15#include "../util/header.h"
16#include "bench.h" 23#include "bench.h"
17#include "futex.h" 24#include "futex.h"
18 25
19#include <err.h> 26#include <err.h>
20#include <stdlib.h>
21#include <sys/time.h> 27#include <sys/time.h>
22#include <pthread.h>
23 28
24static unsigned int nthreads = 0; 29static unsigned int nthreads = 0;
25static unsigned int nsecs = 10; 30static unsigned int nsecs = 10;
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index 6952db65508a..936d89d30483 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -2,18 +2,21 @@
2 * Copyright (C) 2015 Davidlohr Bueso. 2 * Copyright (C) 2015 Davidlohr Bueso.
3 */ 3 */
4 4
5#include "../perf.h" 5/* For the CLR_() macros */
6#include "../util/util.h" 6#include <pthread.h>
7
8#include <signal.h>
7#include "../util/stat.h" 9#include "../util/stat.h"
8#include <subcmd/parse-options.h> 10#include <subcmd/parse-options.h>
9#include "../util/header.h" 11#include <linux/compiler.h>
12#include <linux/kernel.h>
13#include <errno.h>
10#include "bench.h" 14#include "bench.h"
11#include "futex.h" 15#include "futex.h"
12 16
13#include <err.h> 17#include <err.h>
14#include <stdlib.h> 18#include <stdlib.h>
15#include <sys/time.h> 19#include <sys/time.h>
16#include <pthread.h>
17 20
18struct worker { 21struct worker {
19 int tid; 22 int tid;
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index 718238683013..f96e22ed9f87 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -8,18 +8,21 @@
8 * requeues without waking up any tasks -- thus mimicking a regular futex_wait. 8 * requeues without waking up any tasks -- thus mimicking a regular futex_wait.
9 */ 9 */
10 10
11#include "../perf.h" 11/* For the CLR_() macros */
12#include "../util/util.h" 12#include <pthread.h>
13
14#include <signal.h>
13#include "../util/stat.h" 15#include "../util/stat.h"
14#include <subcmd/parse-options.h> 16#include <subcmd/parse-options.h>
15#include "../util/header.h" 17#include <linux/compiler.h>
18#include <linux/kernel.h>
19#include <errno.h>
16#include "bench.h" 20#include "bench.h"
17#include "futex.h" 21#include "futex.h"
18 22
19#include <err.h> 23#include <err.h>
20#include <stdlib.h> 24#include <stdlib.h>
21#include <sys/time.h> 25#include <sys/time.h>
22#include <pthread.h>
23 26
24static u_int32_t futex1 = 0, futex2 = 0; 27static u_int32_t futex1 = 0, futex2 = 0;
25 28
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 91aaf2a1fa90..4a2ecd7438ca 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -7,18 +7,21 @@
7 * it can be used to measure futex_wake() changes. 7 * it can be used to measure futex_wake() changes.
8 */ 8 */
9 9
10#include "../perf.h" 10/* For the CLR_() macros */
11#include "../util/util.h" 11#include <pthread.h>
12
13#include <signal.h>
12#include "../util/stat.h" 14#include "../util/stat.h"
13#include <subcmd/parse-options.h> 15#include <subcmd/parse-options.h>
14#include "../util/header.h" 16#include <linux/compiler.h>
17#include <linux/kernel.h>
18#include <errno.h>
15#include "bench.h" 19#include "bench.h"
16#include "futex.h" 20#include "futex.h"
17 21
18#include <err.h> 22#include <err.h>
19#include <stdlib.h> 23#include <stdlib.h>
20#include <sys/time.h> 24#include <sys/time.h>
21#include <pthread.h>
22 25
23struct thread_data { 26struct thread_data {
24 pthread_t worker; 27 pthread_t worker;
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index f416bd705f66..87d8f4f292d9 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -8,18 +8,21 @@
8 * one or more tasks, and thus the waitqueue is never empty. 8 * one or more tasks, and thus the waitqueue is never empty.
9 */ 9 */
10 10
11#include "../perf.h" 11/* For the CLR_() macros */
12#include "../util/util.h" 12#include <pthread.h>
13
14#include <signal.h>
13#include "../util/stat.h" 15#include "../util/stat.h"
14#include <subcmd/parse-options.h> 16#include <subcmd/parse-options.h>
15#include "../util/header.h" 17#include <linux/compiler.h>
18#include <linux/kernel.h>
19#include <errno.h>
16#include "bench.h" 20#include "bench.h"
17#include "futex.h" 21#include "futex.h"
18 22
19#include <err.h> 23#include <err.h>
20#include <stdlib.h> 24#include <stdlib.h>
21#include <sys/time.h> 25#include <sys/time.h>
22#include <pthread.h>
23 26
24/* all threads will block on the same futex */ 27/* all threads will block on the same futex */
25static u_int32_t futex1 = 0; 28static u_int32_t futex1 = 0;
diff --git a/tools/perf/bench/mem-memcpy-x86-64-asm.S b/tools/perf/bench/mem-memcpy-x86-64-asm.S
index 5c3cce082cb8..f700369bb0f6 100644
--- a/tools/perf/bench/mem-memcpy-x86-64-asm.S
+++ b/tools/perf/bench/mem-memcpy-x86-64-asm.S
@@ -6,7 +6,7 @@
6#define globl p2align 4; .globl 6#define globl p2align 4; .globl
7#define _ASM_EXTABLE_FAULT(x, y) 7#define _ASM_EXTABLE_FAULT(x, y)
8 8
9#include "../../../arch/x86/lib/memcpy_64.S" 9#include "../../arch/x86/lib/memcpy_64.S"
10/* 10/*
11 * We need to provide note.GNU-stack section, saying that we want 11 * We need to provide note.GNU-stack section, saying that we want
12 * NOT executable stack. Otherwise the final linking will assume that 12 * NOT executable stack. Otherwise the final linking will assume that
diff --git a/tools/perf/bench/mem-memset-x86-64-asm.S b/tools/perf/bench/mem-memset-x86-64-asm.S
index de278784c866..58407aa24c1b 100644
--- a/tools/perf/bench/mem-memset-x86-64-asm.S
+++ b/tools/perf/bench/mem-memset-x86-64-asm.S
@@ -1,7 +1,7 @@
1#define memset MEMSET /* don't hide glibc's memset() */ 1#define memset MEMSET /* don't hide glibc's memset() */
2#define altinstr_replacement text 2#define altinstr_replacement text
3#define globl p2align 4; .globl 3#define globl p2align 4; .globl
4#include "../../../arch/x86/lib/memset_64.S" 4#include "../../arch/x86/lib/memset_64.S"
5 5
6/* 6/*
7 * We need to provide note.GNU-stack section, saying that we want 7 * We need to provide note.GNU-stack section, saying that we want
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 7500d959d7eb..f7f530081aa9 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -4,6 +4,9 @@
4 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance 4 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance
5 */ 5 */
6 6
7/* For the CLR_() macros */
8#include <pthread.h>
9
7#include "../perf.h" 10#include "../perf.h"
8#include "../builtin.h" 11#include "../builtin.h"
9#include "../util/util.h" 12#include "../util/util.h"
@@ -21,7 +24,6 @@
21#include <stdlib.h> 24#include <stdlib.h>
22#include <string.h> 25#include <string.h>
23#include <unistd.h> 26#include <unistd.h>
24#include <pthread.h>
25#include <sys/mman.h> 27#include <sys/mman.h>
26#include <sys/time.h> 28#include <sys/time.h>
27#include <sys/resource.h> 29#include <sys/resource.h>
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index b15e7683f38c..9c1034d81b4f 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -339,6 +339,9 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
339 "Show event group information together"), 339 "Show event group information together"),
340 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period, 340 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
341 "Show a column with the sum of periods"), 341 "Show a column with the sum of periods"),
342 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
343 "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
344 stdio__config_color, "always"),
342 OPT_END() 345 OPT_END()
343 }; 346 };
344 int ret = hists__init(); 347 int ret = hists__init();
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 76a4d03c7cd0..30e2b2cb2421 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -351,7 +351,7 @@ int cmd_buildid_cache(int argc, const char **argv,
351 continue; 351 continue;
352 } 352 }
353 pr_warning("Couldn't add %s: %s\n", 353 pr_warning("Couldn't add %s: %s\n",
354 pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); 354 pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
355 } 355 }
356 356
357 strlist__delete(list); 357 strlist__delete(list);
@@ -369,7 +369,7 @@ int cmd_buildid_cache(int argc, const char **argv,
369 continue; 369 continue;
370 } 370 }
371 pr_warning("Couldn't remove %s: %s\n", 371 pr_warning("Couldn't remove %s: %s\n",
372 pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); 372 pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
373 } 373 }
374 374
375 strlist__delete(list); 375 strlist__delete(list);
@@ -387,7 +387,7 @@ int cmd_buildid_cache(int argc, const char **argv,
387 continue; 387 continue;
388 } 388 }
389 pr_warning("Couldn't remove %s: %s\n", 389 pr_warning("Couldn't remove %s: %s\n",
390 pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); 390 pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
391 } 391 }
392 392
393 strlist__delete(list); 393 strlist__delete(list);
@@ -408,7 +408,7 @@ int cmd_buildid_cache(int argc, const char **argv,
408 continue; 408 continue;
409 } 409 }
410 pr_warning("Couldn't update %s: %s\n", 410 pr_warning("Couldn't update %s: %s\n",
411 pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); 411 pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
412 } 412 }
413 413
414 strlist__delete(list); 414 strlist__delete(list);
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 268ab732b8aa..3bdb2c78a21b 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -117,7 +117,7 @@ static void exec_woman_emacs(const char *path, const char *page)
117 free(man_page); 117 free(man_page);
118 } 118 }
119 warning("failed to exec '%s': %s", path, 119 warning("failed to exec '%s': %s", path,
120 strerror_r(errno, sbuf, sizeof(sbuf))); 120 str_error_r(errno, sbuf, sizeof(sbuf)));
121 } 121 }
122} 122}
123 123
@@ -150,7 +150,7 @@ static void exec_man_konqueror(const char *path, const char *page)
150 free(man_page); 150 free(man_page);
151 } 151 }
152 warning("failed to exec '%s': %s", path, 152 warning("failed to exec '%s': %s", path,
153 strerror_r(errno, sbuf, sizeof(sbuf))); 153 str_error_r(errno, sbuf, sizeof(sbuf)));
154 } 154 }
155} 155}
156 156
@@ -162,7 +162,7 @@ static void exec_man_man(const char *path, const char *page)
162 path = "man"; 162 path = "man";
163 execlp(path, "man", page, NULL); 163 execlp(path, "man", page, NULL);
164 warning("failed to exec '%s': %s", path, 164 warning("failed to exec '%s': %s", path,
165 strerror_r(errno, sbuf, sizeof(sbuf))); 165 str_error_r(errno, sbuf, sizeof(sbuf)));
166} 166}
167 167
168static void exec_man_cmd(const char *cmd, const char *page) 168static void exec_man_cmd(const char *cmd, const char *page)
@@ -175,7 +175,7 @@ static void exec_man_cmd(const char *cmd, const char *page)
175 free(shell_cmd); 175 free(shell_cmd);
176 } 176 }
177 warning("failed to exec '%s': %s", cmd, 177 warning("failed to exec '%s': %s", cmd,
178 strerror_r(errno, sbuf, sizeof(sbuf))); 178 str_error_r(errno, sbuf, sizeof(sbuf)));
179} 179}
180 180
181static void add_man_viewer(const char *name) 181static void add_man_viewer(const char *name)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index f4efef9d1eb3..5e2127e04f83 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1018,13 +1018,13 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
1018 err = perf_evlist__open(evlist); 1018 err = perf_evlist__open(evlist);
1019 if (err < 0) { 1019 if (err < 0) {
1020 printf("Couldn't create the events: %s\n", 1020 printf("Couldn't create the events: %s\n",
1021 strerror_r(errno, sbuf, sizeof(sbuf))); 1021 str_error_r(errno, sbuf, sizeof(sbuf)));
1022 goto out; 1022 goto out;
1023 } 1023 }
1024 1024
1025 if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) { 1025 if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages, false) < 0) {
1026 ui__error("Failed to mmap the events: %s\n", 1026 ui__error("Failed to mmap the events: %s\n",
1027 strerror_r(errno, sbuf, sizeof(sbuf))); 1027 str_error_r(errno, sbuf, sizeof(sbuf)));
1028 perf_evlist__close(evlist); 1028 perf_evlist__close(evlist);
1029 goto out; 1029 goto out;
1030 } 1030 }
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index a1a5cd1b8d60..c6d890ad2c1a 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -308,7 +308,7 @@ static void pr_err_with_code(const char *msg, int err)
308 308
309 pr_err("%s", msg); 309 pr_err("%s", msg);
310 pr_debug(" Reason: %s (Code: %d)", 310 pr_debug(" Reason: %s (Code: %d)",
311 strerror_r(-err, sbuf, sizeof(sbuf)), err); 311 str_error_r(-err, sbuf, sizeof(sbuf)), err);
312 pr_err("\n"); 312 pr_err("\n");
313} 313}
314 314
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index b2b3b600adf5..d9f5cc3a3667 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -361,7 +361,7 @@ static int record__mmap_evlist(struct record *rec,
361 return -errno; 361 return -errno;
362 } else { 362 } else {
363 pr_err("failed to mmap with %d (%s)\n", errno, 363 pr_err("failed to mmap with %d (%s)\n", errno,
364 strerror_r(errno, msg, sizeof(msg))); 364 str_error_r(errno, msg, sizeof(msg)));
365 if (errno) 365 if (errno)
366 return -errno; 366 return -errno;
367 else 367 else
@@ -407,7 +407,7 @@ try_again:
407 if (perf_evlist__apply_filters(evlist, &pos)) { 407 if (perf_evlist__apply_filters(evlist, &pos)) {
408 error("failed to set filter \"%s\" on event %s with %d (%s)\n", 408 error("failed to set filter \"%s\" on event %s with %d (%s)\n",
409 pos->filter, perf_evsel__name(pos), errno, 409 pos->filter, perf_evsel__name(pos), errno,
410 strerror_r(errno, msg, sizeof(msg))); 410 str_error_r(errno, msg, sizeof(msg)));
411 rc = -1; 411 rc = -1;
412 goto out; 412 goto out;
413 } 413 }
@@ -1003,7 +1003,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
1003 1003
1004 if (forks && workload_exec_errno) { 1004 if (forks && workload_exec_errno) {
1005 char msg[STRERR_BUFSIZE]; 1005 char msg[STRERR_BUFSIZE];
1006 const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg)); 1006 const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
1007 pr_err("Workload failed: %s\n", emsg); 1007 pr_err("Workload failed: %s\n", emsg);
1008 err = -1; 1008 err = -1;
1009 goto out_child; 1009 goto out_child;
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f6cb357986c6..949e5a15c960 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -817,6 +817,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
817 "Show raw trace event output (do not use print fmt or plugins)"), 817 "Show raw trace event output (do not use print fmt or plugins)"),
818 OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy, 818 OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
819 "Show entries in a hierarchy"), 819 "Show entries in a hierarchy"),
820 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
821 "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
822 stdio__config_color, "always"),
820 OPT_END() 823 OPT_END()
821 }; 824 };
822 struct perf_data_file file = { 825 struct perf_data_file file = {
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index afa057666c2a..0dfe8df2ab9b 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -494,7 +494,7 @@ force_again:
494 } 494 }
495 pr_err("Error: sys_perf_event_open() syscall returned " 495 pr_err("Error: sys_perf_event_open() syscall returned "
496 "with %d (%s)\n%s", fd, 496 "with %d (%s)\n%s", fd,
497 strerror_r(errno, sbuf, sizeof(sbuf)), info); 497 str_error_r(errno, sbuf, sizeof(sbuf)), info);
498 exit(EXIT_FAILURE); 498 exit(EXIT_FAILURE);
499 } 499 }
500 return fd; 500 return fd;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c367a43525e6..8c5a3bfdfdd7 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -596,7 +596,7 @@ try_again:
596 if (perf_evlist__apply_filters(evsel_list, &counter)) { 596 if (perf_evlist__apply_filters(evsel_list, &counter)) {
597 error("failed to set filter \"%s\" on event %s with %d (%s)\n", 597 error("failed to set filter \"%s\" on event %s with %d (%s)\n",
598 counter->filter, perf_evsel__name(counter), errno, 598 counter->filter, perf_evsel__name(counter), errno,
599 strerror_r(errno, msg, sizeof(msg))); 599 str_error_r(errno, msg, sizeof(msg)));
600 return -1; 600 return -1;
601 } 601 }
602 602
@@ -637,7 +637,7 @@ try_again:
637 wait(&status); 637 wait(&status);
638 638
639 if (workload_exec_errno) { 639 if (workload_exec_errno) {
640 const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg)); 640 const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
641 pr_err("Workload failed: %s\n", emsg); 641 pr_err("Workload failed: %s\n", emsg);
642 return -1; 642 return -1;
643 } 643 }
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 07fc7921980c..bd108683fcb8 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -907,7 +907,7 @@ try_again:
907 907
908 if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) { 908 if (perf_evlist__mmap(evlist, opts->mmap_pages, false) < 0) {
909 ui__error("Failed to mmap with %d (%s)\n", 909 ui__error("Failed to mmap with %d (%s)\n",
910 errno, strerror_r(errno, msg, sizeof(msg))); 910 errno, str_error_r(errno, msg, sizeof(msg)));
911 goto out_err; 911 goto out_err;
912 } 912 }
913 913
@@ -1028,7 +1028,7 @@ out_delete:
1028 1028
1029out_err_cpu_topo: { 1029out_err_cpu_topo: {
1030 char errbuf[BUFSIZ]; 1030 char errbuf[BUFSIZ];
1031 const char *err = strerror_r(-ret, errbuf, sizeof(errbuf)); 1031 const char *err = str_error_r(-ret, errbuf, sizeof(errbuf));
1032 1032
1033 ui__error("Could not read the CPU topology map: %s\n", err); 1033 ui__error("Could not read the CPU topology map: %s\n", err);
1034 goto out_delete; 1034 goto out_delete;
@@ -1295,7 +1295,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1295 1295
1296 if (perf_evlist__create_maps(top.evlist, target) < 0) { 1296 if (perf_evlist__create_maps(top.evlist, target) < 0) {
1297 ui__error("Couldn't create thread/CPU maps: %s\n", 1297 ui__error("Couldn't create thread/CPU maps: %s\n",
1298 errno == ENOENT ? "No such process" : strerror_r(errno, errbuf, sizeof(errbuf))); 1298 errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
1299 goto out_delete_evlist; 1299 goto out_delete_evlist;
1300 } 1300 }
1301 1301
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index cf90de811523..b8c6766301db 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -43,7 +43,6 @@
43#include <linux/err.h> 43#include <linux/err.h>
44#include <linux/filter.h> 44#include <linux/filter.h>
45#include <linux/audit.h> 45#include <linux/audit.h>
46#include <sys/ptrace.h>
47#include <linux/random.h> 46#include <linux/random.h>
48#include <linux/stringify.h> 47#include <linux/stringify.h>
49 48
@@ -334,6 +333,10 @@ static size_t syscall_arg__scnprintf_fd(char *bf, size_t size,
334 333
335#define SCA_FD syscall_arg__scnprintf_fd 334#define SCA_FD syscall_arg__scnprintf_fd
336 335
336#ifndef AT_FDCWD
337#define AT_FDCWD -100
338#endif
339
337static size_t syscall_arg__scnprintf_fd_at(char *bf, size_t size, 340static size_t syscall_arg__scnprintf_fd_at(char *bf, size_t size,
338 struct syscall_arg *arg) 341 struct syscall_arg *arg)
339{ 342{
@@ -1601,7 +1604,7 @@ signed_print:
1601 fprintf(trace->output, ") = %ld", ret); 1604 fprintf(trace->output, ") = %ld", ret);
1602 } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) { 1605 } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) {
1603 char bf[STRERR_BUFSIZE]; 1606 char bf[STRERR_BUFSIZE];
1604 const char *emsg = strerror_r(-ret, bf, sizeof(bf)), 1607 const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
1605 *e = audit_errno_to_name(-ret); 1608 *e = audit_errno_to_name(-ret);
1606 1609
1607 fprintf(trace->output, ") = -1 %s %s", e, emsg); 1610 fprintf(trace->output, ") = -1 %s %s", e, emsg);
@@ -2402,7 +2405,7 @@ out_error_apply_filters:
2402 fprintf(trace->output, 2405 fprintf(trace->output,
2403 "Failed to set filter \"%s\" on event %s with %d (%s)\n", 2406 "Failed to set filter \"%s\" on event %s with %d (%s)\n",
2404 evsel->filter, perf_evsel__name(evsel), errno, 2407 evsel->filter, perf_evsel__name(evsel), errno,
2405 strerror_r(errno, errbuf, sizeof(errbuf))); 2408 str_error_r(errno, errbuf, sizeof(errbuf)));
2406 goto out_delete_evlist; 2409 goto out_delete_evlist;
2407} 2410}
2408out_error_mem: 2411out_error_mem:
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index c7e269a7ca37..5ac428060779 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -115,7 +115,7 @@ endif
115FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS) 115FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
116FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf 116FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
117 117
118FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi 118FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(ARCH)/include/uapi -I$(srctree)/tools/include/uapi
119# include ARCH specific config 119# include ARCH specific config
120-include $(src-perf)/arch/$(ARCH)/Makefile 120-include $(src-perf)/arch/$(ARCH)/Makefile
121 121
@@ -206,11 +206,11 @@ endif
206 206
207CFLAGS += -I$(src-perf)/util/include 207CFLAGS += -I$(src-perf)/util/include
208CFLAGS += -I$(src-perf)/arch/$(ARCH)/include 208CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
209CFLAGS += -I$(srctree)/tools/include/uapi
209CFLAGS += -I$(srctree)/tools/include/ 210CFLAGS += -I$(srctree)/tools/include/
210CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi 211CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/uapi
211CFLAGS += -I$(srctree)/arch/$(ARCH)/include 212CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/
212CFLAGS += -I$(srctree)/include/uapi 213CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/
213CFLAGS += -I$(srctree)/include
214 214
215# $(obj-perf) for generated common-cmds.h 215# $(obj-perf) for generated common-cmds.h
216# $(obj-perf)/util for generated bison/flex headers 216# $(obj-perf)/util for generated bison/flex headers
@@ -309,6 +309,12 @@ ifndef NO_LIBELF
309 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT 309 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
310 endif 310 endif
311 311
312 ifeq ($(feature-libelf-gelf_getnote), 1)
313 CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
314 else
315 msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
316 endif
317
312 ifeq ($(feature-libelf-getshdrstrndx), 1) 318 ifeq ($(feature-libelf-getshdrstrndx), 1)
313 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT 319 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
314 endif 320 endif
diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 83a25cef82fd..5cee8a3d0455 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -11,29 +11,11 @@
11#if defined(__i386__) 11#if defined(__i386__)
12#define cpu_relax() asm volatile("rep; nop" ::: "memory"); 12#define cpu_relax() asm volatile("rep; nop" ::: "memory");
13#define CPUINFO_PROC {"model name"} 13#define CPUINFO_PROC {"model name"}
14#ifndef __NR_perf_event_open
15# define __NR_perf_event_open 336
16#endif
17#ifndef __NR_futex
18# define __NR_futex 240
19#endif
20#ifndef __NR_gettid
21# define __NR_gettid 224
22#endif
23#endif 14#endif
24 15
25#if defined(__x86_64__) 16#if defined(__x86_64__)
26#define cpu_relax() asm volatile("rep; nop" ::: "memory"); 17#define cpu_relax() asm volatile("rep; nop" ::: "memory");
27#define CPUINFO_PROC {"model name"} 18#define CPUINFO_PROC {"model name"}
28#ifndef __NR_perf_event_open
29# define __NR_perf_event_open 298
30#endif
31#ifndef __NR_futex
32# define __NR_futex 202
33#endif
34#ifndef __NR_gettid
35# define __NR_gettid 186
36#endif
37#endif 19#endif
38 20
39#ifdef __powerpc__ 21#ifdef __powerpc__
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 8f219223f305..4b2ff021434c 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -374,7 +374,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
374 /* Check for ENOSPC and EIO errors.. */ 374 /* Check for ENOSPC and EIO errors.. */
375 if (fflush(stdout)) { 375 if (fflush(stdout)) {
376 fprintf(stderr, "write failure on standard output: %s", 376 fprintf(stderr, "write failure on standard output: %s",
377 strerror_r(errno, sbuf, sizeof(sbuf))); 377 str_error_r(errno, sbuf, sizeof(sbuf)));
378 goto out; 378 goto out;
379 } 379 }
380 if (ferror(stdout)) { 380 if (ferror(stdout)) {
@@ -383,7 +383,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
383 } 383 }
384 if (fclose(stdout)) { 384 if (fclose(stdout)) {
385 fprintf(stderr, "close failed on standard output: %s", 385 fprintf(stderr, "close failed on standard output: %s",
386 strerror_r(errno, sbuf, sizeof(sbuf))); 386 str_error_r(errno, sbuf, sizeof(sbuf)));
387 goto out; 387 goto out;
388 } 388 }
389 status = 0; 389 status = 0;
@@ -497,6 +497,16 @@ void pthread__unblock_sigwinch(void)
497 pthread_sigmask(SIG_UNBLOCK, &set, NULL); 497 pthread_sigmask(SIG_UNBLOCK, &set, NULL);
498} 498}
499 499
500#ifdef _SC_LEVEL1_DCACHE_LINESIZE
501#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
502#else
503static void cache_line_size(int *cacheline_sizep)
504{
505 if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
506 perror("cannot determine cache line size");
507}
508#endif
509
500int main(int argc, const char **argv) 510int main(int argc, const char **argv)
501{ 511{
502 const char *cmd; 512 const char *cmd;
@@ -509,7 +519,7 @@ int main(int argc, const char **argv)
509 519
510 /* The page_size is placed in util object. */ 520 /* The page_size is placed in util object. */
511 page_size = sysconf(_SC_PAGE_SIZE); 521 page_size = sysconf(_SC_PAGE_SIZE);
512 cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); 522 cache_line_size(&cacheline_size);
513 523
514 if (sysctl__read_int("kernel/perf_event_max_stack", &value) == 0) 524 if (sysctl__read_int("kernel/perf_event_max_stack", &value) == 0)
515 sysctl_perf_event_max_stack = value; 525 sysctl_perf_event_max_stack = value;
@@ -615,7 +625,7 @@ int main(int argc, const char **argv)
615 } 625 }
616 626
617 fprintf(stderr, "Failed to run command '%s': %s\n", 627 fprintf(stderr, "Failed to run command '%s': %s\n",
618 cmd, strerror_r(errno, sbuf, sizeof(sbuf))); 628 cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
619out: 629out:
620 return 1; 630 return 1;
621} 631}
diff --git a/tools/perf/python/tracepoint.py b/tools/perf/python/tracepoint.py
new file mode 100755
index 000000000000..eb4dbed57de7
--- /dev/null
+++ b/tools/perf/python/tracepoint.py
@@ -0,0 +1,47 @@
1#! /usr/bin/python
2# -*- python -*-
3# -*- coding: utf-8 -*-
4
5import perf
6
7class tracepoint(perf.evsel):
8 def __init__(self, sys, name):
9 config = perf.tracepoint(sys, name)
10 perf.evsel.__init__(self,
11 type = perf.TYPE_TRACEPOINT,
12 config = config,
13 freq = 0, sample_period = 1, wakeup_events = 1,
14 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_RAW | perf.SAMPLE_TIME)
15
16def main():
17 tp = tracepoint("sched", "sched_switch")
18 cpus = perf.cpu_map()
19 threads = perf.thread_map(-1)
20
21 evlist = perf.evlist(cpus, threads)
22 evlist.add(tp)
23 evlist.open()
24 evlist.mmap()
25
26 while True:
27 evlist.poll(timeout = -1)
28 for cpu in cpus:
29 event = evlist.read_on_cpu(cpu)
30 if not event:
31 continue
32
33 if not isinstance(event, perf.sample_event):
34 continue
35
36 print "time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d" % (
37 event.sample_time,
38 event.prev_comm,
39 event.prev_pid,
40 event.prev_prio,
41 event.prev_state,
42 event.next_comm,
43 event.next_pid,
44 event.next_prio)
45
46if __name__ == '__main__':
47 main()
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index e70313fac5a5..f20ea4c0d0cb 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -60,7 +60,7 @@ static int do_test(struct perf_evlist *evlist, int mmap_pages,
60 err = perf_evlist__mmap(evlist, mmap_pages, true); 60 err = perf_evlist__mmap(evlist, mmap_pages, true);
61 if (err < 0) { 61 if (err < 0) {
62 pr_debug("perf_evlist__mmap: %s\n", 62 pr_debug("perf_evlist__mmap: %s\n",
63 strerror_r(errno, sbuf, sizeof(sbuf))); 63 str_error_r(errno, sbuf, sizeof(sbuf)));
64 return TEST_FAIL; 64 return TEST_FAIL;
65 } 65 }
66 66
@@ -124,7 +124,7 @@ int test__backward_ring_buffer(int subtest __maybe_unused)
124 err = perf_evlist__open(evlist); 124 err = perf_evlist__open(evlist);
125 if (err < 0) { 125 if (err < 0) {
126 pr_debug("perf_evlist__open: %s\n", 126 pr_debug("perf_evlist__open: %s\n",
127 strerror_r(errno, sbuf, sizeof(sbuf))); 127 str_error_r(errno, sbuf, sizeof(sbuf)));
128 goto out_delete_evlist; 128 goto out_delete_evlist;
129 } 129 }
130 130
diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c
index 0ec9c2c03164..e53bc91fa260 100644
--- a/tools/perf/tests/bpf-script-example.c
+++ b/tools/perf/tests/bpf-script-example.c
@@ -31,8 +31,8 @@ struct bpf_map_def SEC("maps") flip_table = {
31 .max_entries = 1, 31 .max_entries = 1,
32}; 32};
33 33
34SEC("func=sys_epoll_pwait") 34SEC("func=sys_epoll_wait")
35int bpf_func__sys_epoll_pwait(void *ctx) 35int bpf_func__sys_epoll_wait(void *ctx)
36{ 36{
37 int ind =0; 37 int ind =0;
38 int *flag = bpf_map_lookup_elem(&flip_table, &ind); 38 int *flag = bpf_map_lookup_elem(&flip_table, &ind);
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index f31eed31c1a9..fc54064b9186 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -13,13 +13,13 @@
13 13
14#ifdef HAVE_LIBBPF_SUPPORT 14#ifdef HAVE_LIBBPF_SUPPORT
15 15
16static int epoll_pwait_loop(void) 16static int epoll_wait_loop(void)
17{ 17{
18 int i; 18 int i;
19 19
20 /* Should fail NR_ITERS times */ 20 /* Should fail NR_ITERS times */
21 for (i = 0; i < NR_ITERS; i++) 21 for (i = 0; i < NR_ITERS; i++)
22 epoll_pwait(-(i + 1), NULL, 0, 0, NULL); 22 epoll_wait(-(i + 1), NULL, 0, 0);
23 return 0; 23 return 0;
24} 24}
25 25
@@ -61,7 +61,7 @@ static struct {
61 "[basic_bpf_test]", 61 "[basic_bpf_test]",
62 "fix 'perf test LLVM' first", 62 "fix 'perf test LLVM' first",
63 "load bpf object failed", 63 "load bpf object failed",
64 &epoll_pwait_loop, 64 &epoll_wait_loop,
65 (NR_ITERS + 1) / 2, 65 (NR_ITERS + 1) / 2,
66 }, 66 },
67#ifdef HAVE_BPF_PROLOGUE 67#ifdef HAVE_BPF_PROLOGUE
@@ -143,14 +143,14 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
143 err = perf_evlist__open(evlist); 143 err = perf_evlist__open(evlist);
144 if (err < 0) { 144 if (err < 0) {
145 pr_debug("perf_evlist__open: %s\n", 145 pr_debug("perf_evlist__open: %s\n",
146 strerror_r(errno, sbuf, sizeof(sbuf))); 146 str_error_r(errno, sbuf, sizeof(sbuf)));
147 goto out_delete_evlist; 147 goto out_delete_evlist;
148 } 148 }
149 149
150 err = perf_evlist__mmap(evlist, opts.mmap_pages, false); 150 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
151 if (err < 0) { 151 if (err < 0) {
152 pr_debug("perf_evlist__mmap: %s\n", 152 pr_debug("perf_evlist__mmap: %s\n",
153 strerror_r(errno, sbuf, sizeof(sbuf))); 153 str_error_r(errno, sbuf, sizeof(sbuf)));
154 goto out_delete_evlist; 154 goto out_delete_evlist;
155 } 155 }
156 156
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 07c14e9f6546..c23cbf733549 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -258,7 +258,7 @@ static int run_test(struct test *test, int subtest)
258 258
259 if (child < 0) { 259 if (child < 0) {
260 pr_err("failed to fork test: %s\n", 260 pr_err("failed to fork test: %s\n",
261 strerror_r(errno, sbuf, sizeof(sbuf))); 261 str_error_r(errno, sbuf, sizeof(sbuf)));
262 return -1; 262 return -1;
263 } 263 }
264 264
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
index c9ec5f83e42c..f168a85992d0 100644
--- a/tools/perf/tests/cpumap.c
+++ b/tools/perf/tests/cpumap.c
@@ -1,5 +1,12 @@
1#include "tests.h" 1#include "tests.h"
2#include <stdio.h>
2#include "cpumap.h" 3#include "cpumap.h"
4#include "event.h"
5#include <string.h>
6#include <linux/bitops.h>
7#include "debug.h"
8
9struct machine;
3 10
4static int process_event_mask(struct perf_tool *tool __maybe_unused, 11static int process_event_mask(struct perf_tool *tool __maybe_unused,
5 union perf_event *event, 12 union perf_event *event,
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index 9f5698ac81ae..19ef77bd6eb4 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -37,7 +37,7 @@ static int attach__enable_on_exec(struct perf_evlist *evlist)
37 err = perf_evlist__open(evlist); 37 err = perf_evlist__open(evlist);
38 if (err < 0) { 38 if (err < 0) {
39 pr_debug("perf_evlist__open: %s\n", 39 pr_debug("perf_evlist__open: %s\n",
40 strerror_r(errno, sbuf, sizeof(sbuf))); 40 str_error_r(errno, sbuf, sizeof(sbuf)));
41 return err; 41 return err;
42 } 42 }
43 43
diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c
index 59dbd0550c51..a2b5ff9bf83d 100644
--- a/tools/perf/tests/fdarray.c
+++ b/tools/perf/tests/fdarray.c
@@ -1,4 +1,5 @@
1#include <api/fd/array.h> 1#include <api/fd/array.h>
2#include <poll.h>
2#include "util/debug.h" 3#include "util/debug.h"
3#include "tests/tests.h" 4#include "tests/tests.h"
4 5
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index cff564fb4b66..b798a4bfd238 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -5,6 +5,7 @@
5#include "llvm.h" 5#include "llvm.h"
6#include "tests.h" 6#include "tests.h"
7#include "debug.h" 7#include "debug.h"
8#include "util.h"
8 9
9#ifdef HAVE_LIBBPF_SUPPORT 10#ifdef HAVE_LIBBPF_SUPPORT
10static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz) 11static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index aea33f5589c5..634bce9caebd 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -1,3 +1,6 @@
1/* For the CLR_() macros */
2#include <pthread.h>
3
1#include "evlist.h" 4#include "evlist.h"
2#include "evsel.h" 5#include "evsel.h"
3#include "thread_map.h" 6#include "thread_map.h"
@@ -49,7 +52,7 @@ int test__basic_mmap(int subtest __maybe_unused)
49 sched_setaffinity(0, sizeof(cpu_set), &cpu_set); 52 sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
50 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { 53 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
51 pr_debug("sched_setaffinity() failed on CPU %d: %s ", 54 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
52 cpus->map[0], strerror_r(errno, sbuf, sizeof(sbuf))); 55 cpus->map[0], str_error_r(errno, sbuf, sizeof(sbuf)));
53 goto out_free_cpus; 56 goto out_free_cpus;
54 } 57 }
55 58
@@ -79,7 +82,7 @@ int test__basic_mmap(int subtest __maybe_unused)
79 if (perf_evsel__open(evsels[i], cpus, threads) < 0) { 82 if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
80 pr_debug("failed to open counter: %s, " 83 pr_debug("failed to open counter: %s, "
81 "tweak /proc/sys/kernel/perf_event_paranoid?\n", 84 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
82 strerror_r(errno, sbuf, sizeof(sbuf))); 85 str_error_r(errno, sbuf, sizeof(sbuf)));
83 goto out_delete_evlist; 86 goto out_delete_evlist;
84 } 87 }
85 88
@@ -89,7 +92,7 @@ int test__basic_mmap(int subtest __maybe_unused)
89 92
90 if (perf_evlist__mmap(evlist, 128, true) < 0) { 93 if (perf_evlist__mmap(evlist, 128, true) < 0) {
91 pr_debug("failed to mmap events: %d (%s)\n", errno, 94 pr_debug("failed to mmap events: %d (%s)\n", errno,
92 strerror_r(errno, sbuf, sizeof(sbuf))); 95 str_error_r(errno, sbuf, sizeof(sbuf)));
93 goto out_delete_evlist; 96 goto out_delete_evlist;
94 } 97 }
95 98
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c
index ad1cb63139a7..c8d9592eb142 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -1,3 +1,6 @@
1/* For the CPU_* macros */
2#include <pthread.h>
3
1#include <api/fs/fs.h> 4#include <api/fs/fs.h>
2#include <linux/err.h> 5#include <linux/err.h>
3#include "evsel.h" 6#include "evsel.h"
@@ -41,7 +44,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused)
41 if (perf_evsel__open(evsel, cpus, threads) < 0) { 44 if (perf_evsel__open(evsel, cpus, threads) < 0) {
42 pr_debug("failed to open counter: %s, " 45 pr_debug("failed to open counter: %s, "
43 "tweak /proc/sys/kernel/perf_event_paranoid?\n", 46 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
44 strerror_r(errno, sbuf, sizeof(sbuf))); 47 str_error_r(errno, sbuf, sizeof(sbuf)));
45 goto out_evsel_delete; 48 goto out_evsel_delete;
46 } 49 }
47 50
@@ -62,7 +65,7 @@ int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused)
62 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { 65 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
63 pr_debug("sched_setaffinity() failed on CPU %d: %s ", 66 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
64 cpus->map[cpu], 67 cpus->map[cpu],
65 strerror_r(errno, sbuf, sizeof(sbuf))); 68 str_error_r(errno, sbuf, sizeof(sbuf)));
66 goto out_close_fd; 69 goto out_close_fd;
67 } 70 }
68 for (i = 0; i < ncalls; ++i) { 71 for (i = 0; i < ncalls; ++i) {
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 4344fe482c1d..f52239fed361 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -6,6 +6,13 @@
6#include "tests.h" 6#include "tests.h"
7#include "debug.h" 7#include "debug.h"
8 8
9#ifndef O_DIRECTORY
10#define O_DIRECTORY 00200000
11#endif
12#ifndef AT_FDCWD
13#define AT_FDCWD -100
14#endif
15
9int test__syscall_openat_tp_fields(int subtest __maybe_unused) 16int test__syscall_openat_tp_fields(int subtest __maybe_unused)
10{ 17{
11 struct record_opts opts = { 18 struct record_opts opts = {
@@ -51,14 +58,14 @@ int test__syscall_openat_tp_fields(int subtest __maybe_unused)
51 err = perf_evlist__open(evlist); 58 err = perf_evlist__open(evlist);
52 if (err < 0) { 59 if (err < 0) {
53 pr_debug("perf_evlist__open: %s\n", 60 pr_debug("perf_evlist__open: %s\n",
54 strerror_r(errno, sbuf, sizeof(sbuf))); 61 str_error_r(errno, sbuf, sizeof(sbuf)));
55 goto out_delete_evlist; 62 goto out_delete_evlist;
56 } 63 }
57 64
58 err = perf_evlist__mmap(evlist, UINT_MAX, false); 65 err = perf_evlist__mmap(evlist, UINT_MAX, false);
59 if (err < 0) { 66 if (err < 0) {
60 pr_debug("perf_evlist__mmap: %s\n", 67 pr_debug("perf_evlist__mmap: %s\n",
61 strerror_r(errno, sbuf, sizeof(sbuf))); 68 str_error_r(errno, sbuf, sizeof(sbuf)));
62 goto out_delete_evlist; 69 goto out_delete_evlist;
63 } 70 }
64 71
diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c
index 1184f9ba6499..d7414128d7fe 100644
--- a/tools/perf/tests/openat-syscall.c
+++ b/tools/perf/tests/openat-syscall.c
@@ -29,7 +29,7 @@ int test__openat_syscall_event(int subtest __maybe_unused)
29 if (perf_evsel__open_per_thread(evsel, threads) < 0) { 29 if (perf_evsel__open_per_thread(evsel, threads) < 0) {
30 pr_debug("failed to open counter: %s, " 30 pr_debug("failed to open counter: %s, "
31 "tweak /proc/sys/kernel/perf_event_paranoid?\n", 31 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
32 strerror_r(errno, sbuf, sizeof(sbuf))); 32 str_error_r(errno, sbuf, sizeof(sbuf)));
33 goto out_evsel_delete; 33 goto out_evsel_delete;
34 } 34 }
35 35
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index b836ee6a8d9b..8f2e1de6d0ea 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -1,3 +1,6 @@
1/* For the CLR_() macros */
2#include <pthread.h>
3
1#include <sched.h> 4#include <sched.h>
2#include "evlist.h" 5#include "evlist.h"
3#include "evsel.h" 6#include "evsel.h"
@@ -104,7 +107,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
104 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask); 107 err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
105 if (err < 0) { 108 if (err < 0) {
106 pr_debug("sched__get_first_possible_cpu: %s\n", 109 pr_debug("sched__get_first_possible_cpu: %s\n",
107 strerror_r(errno, sbuf, sizeof(sbuf))); 110 str_error_r(errno, sbuf, sizeof(sbuf)));
108 goto out_delete_evlist; 111 goto out_delete_evlist;
109 } 112 }
110 113
@@ -115,7 +118,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
115 */ 118 */
116 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) { 119 if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
117 pr_debug("sched_setaffinity: %s\n", 120 pr_debug("sched_setaffinity: %s\n",
118 strerror_r(errno, sbuf, sizeof(sbuf))); 121 str_error_r(errno, sbuf, sizeof(sbuf)));
119 goto out_delete_evlist; 122 goto out_delete_evlist;
120 } 123 }
121 124
@@ -126,7 +129,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
126 err = perf_evlist__open(evlist); 129 err = perf_evlist__open(evlist);
127 if (err < 0) { 130 if (err < 0) {
128 pr_debug("perf_evlist__open: %s\n", 131 pr_debug("perf_evlist__open: %s\n",
129 strerror_r(errno, sbuf, sizeof(sbuf))); 132 str_error_r(errno, sbuf, sizeof(sbuf)));
130 goto out_delete_evlist; 133 goto out_delete_evlist;
131 } 134 }
132 135
@@ -138,7 +141,7 @@ int test__PERF_RECORD(int subtest __maybe_unused)
138 err = perf_evlist__mmap(evlist, opts.mmap_pages, false); 141 err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
139 if (err < 0) { 142 if (err < 0) {
140 pr_debug("perf_evlist__mmap: %s\n", 143 pr_debug("perf_evlist__mmap: %s\n",
141 strerror_r(errno, sbuf, sizeof(sbuf))); 144 str_error_r(errno, sbuf, sizeof(sbuf)));
142 goto out_delete_evlist; 145 goto out_delete_evlist;
143 } 146 }
144 147
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 36e8ce1550e3..4c9fd046d57b 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -70,7 +70,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
70 70
71 err = -errno; 71 err = -errno;
72 pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n", 72 pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n",
73 strerror_r(errno, sbuf, sizeof(sbuf)), 73 str_error_r(errno, sbuf, sizeof(sbuf)),
74 knob, (u64)attr.sample_freq); 74 knob, (u64)attr.sample_freq);
75 goto out_delete_evlist; 75 goto out_delete_evlist;
76 } 76 }
@@ -78,7 +78,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
78 err = perf_evlist__mmap(evlist, 128, true); 78 err = perf_evlist__mmap(evlist, 128, true);
79 if (err < 0) { 79 if (err < 0) {
80 pr_debug("failed to mmap event: %d (%s)\n", errno, 80 pr_debug("failed to mmap event: %d (%s)\n", errno,
81 strerror_r(errno, sbuf, sizeof(sbuf))); 81 str_error_r(errno, sbuf, sizeof(sbuf)));
82 goto out_delete_evlist; 82 goto out_delete_evlist;
83 } 83 }
84 84
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 2dfff7ac8ef3..01a5ba2788c6 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -91,13 +91,13 @@ int test__task_exit(int subtest __maybe_unused)
91 err = perf_evlist__open(evlist); 91 err = perf_evlist__open(evlist);
92 if (err < 0) { 92 if (err < 0) {
93 pr_debug("Couldn't open the evlist: %s\n", 93 pr_debug("Couldn't open the evlist: %s\n",
94 strerror_r(-err, sbuf, sizeof(sbuf))); 94 str_error_r(-err, sbuf, sizeof(sbuf)));
95 goto out_delete_evlist; 95 goto out_delete_evlist;
96 } 96 }
97 97
98 if (perf_evlist__mmap(evlist, 128, true) < 0) { 98 if (perf_evlist__mmap(evlist, 128, true) < 0) {
99 pr_debug("failed to mmap events: %d (%s)\n", errno, 99 pr_debug("failed to mmap events: %d (%s)\n", errno,
100 strerror_r(errno, sbuf, sizeof(sbuf))); 100 str_error_r(errno, sbuf, sizeof(sbuf)));
101 goto out_delete_evlist; 101 goto out_delete_evlist;
102 } 102 }
103 103
diff --git a/tools/perf/trace/beauty/flock.c b/tools/perf/trace/beauty/flock.c
index 021bb48c6336..74613703a14e 100644
--- a/tools/perf/trace/beauty/flock.c
+++ b/tools/perf/trace/beauty/flock.c
@@ -1,3 +1,20 @@
1#include <fcntl.h>
2
3#ifndef LOCK_MAND
4#define LOCK_MAND 32
5#endif
6
7#ifndef LOCK_READ
8#define LOCK_READ 64
9#endif
10
11#ifndef LOCK_WRITE
12#define LOCK_WRITE 128
13#endif
14
15#ifndef LOCK_RW
16#define LOCK_RW 192
17#endif
1 18
2static size_t syscall_arg__scnprintf_flock(char *bf, size_t size, 19static size_t syscall_arg__scnprintf_flock(char *bf, size_t size,
3 struct syscall_arg *arg) 20 struct syscall_arg *arg)
diff --git a/tools/perf/trace/beauty/futex_op.c b/tools/perf/trace/beauty/futex_op.c
index e2476211f22d..bfd3359b09b6 100644
--- a/tools/perf/trace/beauty/futex_op.c
+++ b/tools/perf/trace/beauty/futex_op.c
@@ -1,5 +1,21 @@
1#include <linux/futex.h> 1#include <linux/futex.h>
2 2
3#ifndef FUTEX_WAIT_BITSET
4#define FUTEX_WAIT_BITSET 9
5#endif
6#ifndef FUTEX_WAKE_BITSET
7#define FUTEX_WAKE_BITSET 10
8#endif
9#ifndef FUTEX_WAIT_REQUEUE_PI
10#define FUTEX_WAIT_REQUEUE_PI 11
11#endif
12#ifndef FUTEX_CMP_REQUEUE_PI
13#define FUTEX_CMP_REQUEUE_PI 12
14#endif
15#ifndef FUTEX_CLOCK_REALTIME
16#define FUTEX_CLOCK_REALTIME 256
17#endif
18
3static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg) 19static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg)
4{ 20{
5 enum syscall_futex_args { 21 enum syscall_futex_args {
diff --git a/tools/perf/trace/beauty/mmap.c b/tools/perf/trace/beauty/mmap.c
index 3444a4d5382d..d0a3a8e402e7 100644
--- a/tools/perf/trace/beauty/mmap.c
+++ b/tools/perf/trace/beauty/mmap.c
@@ -1,5 +1,9 @@
1#include <sys/mman.h> 1#include <sys/mman.h>
2 2
3#ifndef PROT_SEM
4#define PROT_SEM 0x8
5#endif
6
3static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, 7static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
4 struct syscall_arg *arg) 8 struct syscall_arg *arg)
5{ 9{
@@ -16,9 +20,7 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
16 P_MMAP_PROT(EXEC); 20 P_MMAP_PROT(EXEC);
17 P_MMAP_PROT(READ); 21 P_MMAP_PROT(READ);
18 P_MMAP_PROT(WRITE); 22 P_MMAP_PROT(WRITE);
19#ifdef PROT_SEM
20 P_MMAP_PROT(SEM); 23 P_MMAP_PROT(SEM);
21#endif
22 P_MMAP_PROT(GROWSDOWN); 24 P_MMAP_PROT(GROWSDOWN);
23 P_MMAP_PROT(GROWSUP); 25 P_MMAP_PROT(GROWSUP);
24#undef P_MMAP_PROT 26#undef P_MMAP_PROT
@@ -31,10 +33,31 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
31 33
32#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot 34#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot
33 35
36#ifndef MAP_FIXED
37#define MAP_FIXED 0x10
38#endif
39
40#ifndef MAP_ANONYMOUS
41#define MAP_ANONYMOUS 0x20
42#endif
43
44#ifndef MAP_32BIT
45#define MAP_32BIT 0x40
46#endif
47
34#ifndef MAP_STACK 48#ifndef MAP_STACK
35# define MAP_STACK 0x20000 49#define MAP_STACK 0x20000
36#endif 50#endif
37 51
52#ifndef MAP_HUGETLB
53#define MAP_HUGETLB 0x40000
54#endif
55
56#ifndef MAP_UNINITIALIZED
57#define MAP_UNINITIALIZED 0x4000000
58#endif
59
60
38static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, 61static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
39 struct syscall_arg *arg) 62 struct syscall_arg *arg)
40{ 63{
@@ -48,26 +71,20 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
48 71
49 P_MMAP_FLAG(SHARED); 72 P_MMAP_FLAG(SHARED);
50 P_MMAP_FLAG(PRIVATE); 73 P_MMAP_FLAG(PRIVATE);
51#ifdef MAP_32BIT
52 P_MMAP_FLAG(32BIT); 74 P_MMAP_FLAG(32BIT);
53#endif
54 P_MMAP_FLAG(ANONYMOUS); 75 P_MMAP_FLAG(ANONYMOUS);
55 P_MMAP_FLAG(DENYWRITE); 76 P_MMAP_FLAG(DENYWRITE);
56 P_MMAP_FLAG(EXECUTABLE); 77 P_MMAP_FLAG(EXECUTABLE);
57 P_MMAP_FLAG(FILE); 78 P_MMAP_FLAG(FILE);
58 P_MMAP_FLAG(FIXED); 79 P_MMAP_FLAG(FIXED);
59 P_MMAP_FLAG(GROWSDOWN); 80 P_MMAP_FLAG(GROWSDOWN);
60#ifdef MAP_HUGETLB
61 P_MMAP_FLAG(HUGETLB); 81 P_MMAP_FLAG(HUGETLB);
62#endif
63 P_MMAP_FLAG(LOCKED); 82 P_MMAP_FLAG(LOCKED);
64 P_MMAP_FLAG(NONBLOCK); 83 P_MMAP_FLAG(NONBLOCK);
65 P_MMAP_FLAG(NORESERVE); 84 P_MMAP_FLAG(NORESERVE);
66 P_MMAP_FLAG(POPULATE); 85 P_MMAP_FLAG(POPULATE);
67 P_MMAP_FLAG(STACK); 86 P_MMAP_FLAG(STACK);
68#ifdef MAP_UNINITIALIZED
69 P_MMAP_FLAG(UNINITIALIZED); 87 P_MMAP_FLAG(UNINITIALIZED);
70#endif
71#undef P_MMAP_FLAG 88#undef P_MMAP_FLAG
72 89
73 if (flags) 90 if (flags)
@@ -78,6 +95,13 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
78 95
79#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags 96#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags
80 97
98#ifndef MREMAP_MAYMOVE
99#define MREMAP_MAYMOVE 1
100#endif
101#ifndef MREMAP_FIXED
102#define MREMAP_FIXED 2
103#endif
104
81static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, 105static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
82 struct syscall_arg *arg) 106 struct syscall_arg *arg)
83{ 107{
@@ -90,9 +114,7 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
90 } 114 }
91 115
92 P_MREMAP_FLAG(MAYMOVE); 116 P_MREMAP_FLAG(MAYMOVE);
93#ifdef MREMAP_FIXED
94 P_MREMAP_FLAG(FIXED); 117 P_MREMAP_FLAG(FIXED);
95#endif
96#undef P_MREMAP_FLAG 118#undef P_MREMAP_FLAG
97 119
98 if (flags) 120 if (flags)
@@ -107,6 +129,10 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
107#define MADV_HWPOISON 100 129#define MADV_HWPOISON 100
108#endif 130#endif
109 131
132#ifndef MADV_SOFT_OFFLINE
133#define MADV_SOFT_OFFLINE 101
134#endif
135
110#ifndef MADV_MERGEABLE 136#ifndef MADV_MERGEABLE
111#define MADV_MERGEABLE 12 137#define MADV_MERGEABLE 12
112#endif 138#endif
@@ -115,6 +141,23 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
115#define MADV_UNMERGEABLE 13 141#define MADV_UNMERGEABLE 13
116#endif 142#endif
117 143
144#ifndef MADV_HUGEPAGE
145#define MADV_HUGEPAGE 14
146#endif
147
148#ifndef MADV_NOHUGEPAGE
149#define MADV_NOHUGEPAGE 15
150#endif
151
152#ifndef MADV_DONTDUMP
153#define MADV_DONTDUMP 16
154#endif
155
156#ifndef MADV_DODUMP
157#define MADV_DODUMP 17
158#endif
159
160
118static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, 161static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
119 struct syscall_arg *arg) 162 struct syscall_arg *arg)
120{ 163{
@@ -131,24 +174,14 @@ static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
131 P_MADV_BHV(DONTFORK); 174 P_MADV_BHV(DONTFORK);
132 P_MADV_BHV(DOFORK); 175 P_MADV_BHV(DOFORK);
133 P_MADV_BHV(HWPOISON); 176 P_MADV_BHV(HWPOISON);
134#ifdef MADV_SOFT_OFFLINE
135 P_MADV_BHV(SOFT_OFFLINE); 177 P_MADV_BHV(SOFT_OFFLINE);
136#endif
137 P_MADV_BHV(MERGEABLE); 178 P_MADV_BHV(MERGEABLE);
138 P_MADV_BHV(UNMERGEABLE); 179 P_MADV_BHV(UNMERGEABLE);
139#ifdef MADV_HUGEPAGE
140 P_MADV_BHV(HUGEPAGE); 180 P_MADV_BHV(HUGEPAGE);
141#endif
142#ifdef MADV_NOHUGEPAGE
143 P_MADV_BHV(NOHUGEPAGE); 181 P_MADV_BHV(NOHUGEPAGE);
144#endif
145#ifdef MADV_DONTDUMP
146 P_MADV_BHV(DONTDUMP); 182 P_MADV_BHV(DONTDUMP);
147#endif
148#ifdef MADV_DODUMP
149 P_MADV_BHV(DODUMP); 183 P_MADV_BHV(DODUMP);
150#endif 184#undef P_MADV_BHV
151#undef P_MADV_PHV
152 default: break; 185 default: break;
153 } 186 }
154 187
diff --git a/tools/perf/trace/beauty/msg_flags.c b/tools/perf/trace/beauty/msg_flags.c
index 07fa8a0acad6..1106c8960cc4 100644
--- a/tools/perf/trace/beauty/msg_flags.c
+++ b/tools/perf/trace/beauty/msg_flags.c
@@ -33,7 +33,6 @@ static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,
33 P_MSG_FLAG(OOB); 33 P_MSG_FLAG(OOB);
34 P_MSG_FLAG(PEEK); 34 P_MSG_FLAG(PEEK);
35 P_MSG_FLAG(DONTROUTE); 35 P_MSG_FLAG(DONTROUTE);
36 P_MSG_FLAG(TRYHARD);
37 P_MSG_FLAG(CTRUNC); 36 P_MSG_FLAG(CTRUNC);
38 P_MSG_FLAG(PROBE); 37 P_MSG_FLAG(PROBE);
39 P_MSG_FLAG(TRUNC); 38 P_MSG_FLAG(TRUNC);
diff --git a/tools/perf/trace/beauty/open_flags.c b/tools/perf/trace/beauty/open_flags.c
index 0f3679e0cdcf..f55a4597fc38 100644
--- a/tools/perf/trace/beauty/open_flags.c
+++ b/tools/perf/trace/beauty/open_flags.c
@@ -1,3 +1,18 @@
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <fcntl.h>
4
5#ifndef O_DIRECT
6#define O_DIRECT 00040000
7#endif
8
9#ifndef O_DIRECTORY
10#define O_DIRECTORY 00200000
11#endif
12
13#ifndef O_NOATIME
14#define O_NOATIME 01000000
15#endif
1 16
2static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, 17static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size,
3 struct syscall_arg *arg) 18 struct syscall_arg *arg)
diff --git a/tools/perf/trace/beauty/seccomp.c b/tools/perf/trace/beauty/seccomp.c
index 213c5a7e3e92..356441bce27d 100644
--- a/tools/perf/trace/beauty/seccomp.c
+++ b/tools/perf/trace/beauty/seccomp.c
@@ -1,5 +1,3 @@
1#include <linux/seccomp.h>
2
3#ifndef SECCOMP_SET_MODE_STRICT 1#ifndef SECCOMP_SET_MODE_STRICT
4#define SECCOMP_SET_MODE_STRICT 0 2#define SECCOMP_SET_MODE_STRICT 0
5#endif 3#endif
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e08b8f7b6d3f..13d414384739 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2029,7 +2029,7 @@ static int hist_browser__dump(struct hist_browser *browser)
2029 fp = fopen(filename, "w"); 2029 fp = fopen(filename, "w");
2030 if (fp == NULL) { 2030 if (fp == NULL) {
2031 char bf[64]; 2031 char bf[64];
2032 const char *err = strerror_r(errno, bf, sizeof(bf)); 2032 const char *err = str_error_r(errno, bf, sizeof(bf));
2033 ui_helpline__fpush("Couldn't write to %s: %s", filename, err); 2033 ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
2034 return -1; 2034 return -1;
2035 } 2035 }
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index 52e7fc48af9f..00b91921edb1 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -1,4 +1,5 @@
1#include "../util.h" 1#include "../util.h"
2#include "../../util/util.h"
2#include "../../util/debug.h" 3#include "../../util/debug.h"
3#include "gtk.h" 4#include "gtk.h"
4 5
diff --git a/tools/perf/ui/helpline.c b/tools/perf/ui/helpline.c
index 700fb3cfa1c7..5b74a7eba210 100644
--- a/tools/perf/ui/helpline.c
+++ b/tools/perf/ui/helpline.c
@@ -5,6 +5,7 @@
5#include "../debug.h" 5#include "../debug.h"
6#include "helpline.h" 6#include "helpline.h"
7#include "ui.h" 7#include "ui.h"
8#include "../util.h"
8 9
9char ui_helpline__current[512]; 10char ui_helpline__current[512];
10 11
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index ba51fa8a1176..1f6b0994f4f4 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -60,6 +60,13 @@ static inline int setup_gtk_browser(void) { return -1; }
60static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {} 60static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {}
61#endif 61#endif
62 62
63int stdio__config_color(const struct option *opt __maybe_unused,
64 const char *mode, int unset __maybe_unused)
65{
66 perf_use_color_default = perf_config_colorbool("color.ui", mode, -1);
67 return 0;
68}
69
63void setup_browser(bool fallback_to_pager) 70void setup_browser(bool fallback_to_pager)
64{ 71{
65 if (use_browser < 2 && (!isatty(1) || dump_trace)) 72 if (use_browser < 2 && (!isatty(1) || dump_trace))
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index 7dfeba0a91f3..4ea2ba861fc2 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -1,3 +1,4 @@
1#include <errno.h>
1#include <signal.h> 2#include <signal.h>
2#include <stdbool.h> 3#include <stdbool.h>
3#ifdef HAVE_BACKTRACE_SUPPORT 4#ifdef HAVE_BACKTRACE_SUPPORT
@@ -6,6 +7,7 @@
6 7
7#include "../../util/cache.h" 8#include "../../util/cache.h"
8#include "../../util/debug.h" 9#include "../../util/debug.h"
10#include "../../util/util.h"
9#include "../browser.h" 11#include "../browser.h"
10#include "../helpline.h" 12#include "../helpline.h"
11#include "../ui.h" 13#include "../ui.h"
diff --git a/tools/perf/ui/ui.h b/tools/perf/ui/ui.h
index ab88383f8be8..4b6fb6c7a542 100644
--- a/tools/perf/ui/ui.h
+++ b/tools/perf/ui/ui.h
@@ -26,4 +26,8 @@ static inline void ui__exit(bool wait_for_ok __maybe_unused) {}
26 26
27void ui__refresh_dimensions(bool force); 27void ui__refresh_dimensions(bool force);
28 28
29struct option;
30
31int stdio__config_color(const struct option *opt, const char *mode, int unset);
32
29#endif /* _PERF_UI_H_ */ 33#endif /* _PERF_UI_H_ */
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index fced8336e5fd..2fa7d8b69873 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -70,6 +70,7 @@ libperf-y += stat.o
70libperf-y += stat-shadow.o 70libperf-y += stat-shadow.o
71libperf-y += record.o 71libperf-y += record.o
72libperf-y += srcline.o 72libperf-y += srcline.o
73libperf-y += str_error_r.o
73libperf-y += data.o 74libperf-y += data.o
74libperf-y += tsc.o 75libperf-y += tsc.o
75libperf-y += cloexec.o 76libperf-y += cloexec.o
@@ -84,6 +85,7 @@ libperf-y += parse-regs-options.o
84libperf-y += term.o 85libperf-y += term.o
85libperf-y += help-unknown-cmd.o 86libperf-y += help-unknown-cmd.o
86libperf-y += mem-events.o 87libperf-y += mem-events.o
88libperf-y += vsprintf.o
87 89
88libperf-$(CONFIG_LIBBPF) += bpf-loader.o 90libperf-$(CONFIG_LIBBPF) += bpf-loader.o
89libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o 91libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
@@ -111,6 +113,7 @@ libperf-y += scripting-engines/
111libperf-$(CONFIG_ZLIB) += zlib.o 113libperf-$(CONFIG_ZLIB) += zlib.o
112libperf-$(CONFIG_LZMA) += lzma.o 114libperf-$(CONFIG_LZMA) += lzma.o
113libperf-y += demangle-java.o 115libperf-y += demangle-java.o
116libperf-y += demangle-rust.o
114 117
115ifdef CONFIG_JITDUMP 118ifdef CONFIG_JITDUMP
116libperf-$(CONFIG_LIBELF) += jitdump.o 119libperf-$(CONFIG_LIBELF) += jitdump.o
@@ -173,6 +176,14 @@ $(OUTPUT)util/libstring.o: ../lib/string.c FORCE
173 $(call rule_mkdir) 176 $(call rule_mkdir)
174 $(call if_changed_dep,cc_o_c) 177 $(call if_changed_dep,cc_o_c)
175 178
179$(OUTPUT)util/str_error_r.o: ../lib/str_error_r.c FORCE
180 $(call rule_mkdir)
181 $(call if_changed_dep,cc_o_c)
182
176$(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE 183$(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
177 $(call rule_mkdir) 184 $(call rule_mkdir)
178 $(call if_changed_dep,cc_o_c) 185 $(call if_changed_dep,cc_o_c)
186
187$(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE
188 $(call rule_mkdir)
189 $(call if_changed_dep,cc_o_c)
diff --git a/tools/perf/util/alias.c b/tools/perf/util/alias.c
index 6c80f830358b..6455471d9cd1 100644
--- a/tools/perf/util/alias.c
+++ b/tools/perf/util/alias.c
@@ -1,4 +1,5 @@
1#include "cache.h" 1#include "cache.h"
2#include "util.h"
2#include "config.h" 3#include "config.h"
3 4
4static const char *alias_key; 5static const char *alias_key;
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index dcc8845881ae..8445e89621fe 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1589,7 +1589,7 @@ bpf_loader_strerror(int err, char *buf, size_t size)
1589 snprintf(buf, size, "Unknown bpf loader error %d", err); 1589 snprintf(buf, size, "Unknown bpf loader error %d", err);
1590 else 1590 else
1591 snprintf(buf, size, "%s", 1591 snprintf(buf, size, "%s",
1592 strerror_r(err, sbuf, sizeof(sbuf))); 1592 str_error_r(err, sbuf, sizeof(sbuf)));
1593 1593
1594 buf[size - 1] = '\0'; 1594 buf[size - 1] = '\0';
1595 return -1; 1595 return -1;
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index e1a16408da9c..1e504e40dac8 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -533,7 +533,7 @@ int build_id_cache__list_build_ids(const char *pathname,
533 return ret; 533 return ret;
534} 534}
535 535
536#ifdef HAVE_LIBELF_SUPPORT 536#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_GELF_GETNOTE_SUPPORT)
537static int build_id_cache__add_sdt_cache(const char *sbuild_id, 537static int build_id_cache__add_sdt_cache(const char *sbuild_id,
538 const char *realname) 538 const char *realname)
539{ 539{
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 9f90e36b56fb..512c0c83fbc6 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -1,11 +1,8 @@
1#ifndef __PERF_CACHE_H 1#ifndef __PERF_CACHE_H
2#define __PERF_CACHE_H 2#define __PERF_CACHE_H
3 3
4#include <stdbool.h>
5#include "util.h"
6#include "strbuf.h" 4#include "strbuf.h"
7#include <subcmd/pager.h> 5#include <subcmd/pager.h>
8#include "../perf.h"
9#include "../ui/ui.h" 6#include "../ui/ui.h"
10 7
11#include <linux/string.h> 8#include <linux/string.h>
diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 2babddaa2481..f0dcd0ee0afa 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -4,18 +4,24 @@
4#include "cloexec.h" 4#include "cloexec.h"
5#include "asm/bug.h" 5#include "asm/bug.h"
6#include "debug.h" 6#include "debug.h"
7#include <unistd.h>
8#include <asm/unistd.h>
9#include <sys/syscall.h>
7 10
8static unsigned long flag = PERF_FLAG_FD_CLOEXEC; 11static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
9 12
10#ifdef __GLIBC_PREREQ
11#if !__GLIBC_PREREQ(2, 6)
12int __weak sched_getcpu(void) 13int __weak sched_getcpu(void)
13{ 14{
15#ifdef __NR_getcpu
16 unsigned cpu;
17 int err = syscall(__NR_getcpu, &cpu, NULL, NULL);
18 if (!err)
19 return cpu;
20#else
14 errno = ENOSYS; 21 errno = ENOSYS;
22#endif
15 return -1; 23 return -1;
16} 24}
17#endif
18#endif
19 25
20static int perf_flag_probe(void) 26static int perf_flag_probe(void)
21{ 27{
@@ -58,7 +64,7 @@ static int perf_flag_probe(void)
58 64
59 WARN_ONCE(err != EINVAL && err != EBUSY, 65 WARN_ONCE(err != EINVAL && err != EBUSY,
60 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", 66 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
61 err, strerror_r(err, sbuf, sizeof(sbuf))); 67 err, str_error_r(err, sbuf, sizeof(sbuf)));
62 68
63 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */ 69 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
64 while (1) { 70 while (1) {
@@ -76,7 +82,7 @@ static int perf_flag_probe(void)
76 82
77 if (WARN_ONCE(fd < 0 && err != EBUSY, 83 if (WARN_ONCE(fd < 0 && err != EBUSY,
78 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", 84 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
79 err, strerror_r(err, sbuf, sizeof(sbuf)))) 85 err, str_error_r(err, sbuf, sizeof(sbuf))))
80 return -1; 86 return -1;
81 87
82 return 0; 88 return 0;
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c
index 1210ba555d07..dbbf89b050a5 100644
--- a/tools/perf/util/color.c
+++ b/tools/perf/util/color.c
@@ -1,8 +1,11 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include "cache.h" 2#include "cache.h"
3#include "config.h" 3#include "config.h"
4#include <stdlib.h>
5#include <stdio.h>
4#include "color.h" 6#include "color.h"
5#include <math.h> 7#include <math.h>
8#include <unistd.h>
6 9
7int perf_use_color_default = -1; 10int perf_use_color_default = -1;
8 11
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index be83516155ee..60bfc9ca1e22 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -57,7 +57,7 @@ static int open_file_read(struct perf_data_file *file)
57 int err = errno; 57 int err = errno;
58 58
59 pr_err("failed to open %s: %s", file->path, 59 pr_err("failed to open %s: %s", file->path,
60 strerror_r(err, sbuf, sizeof(sbuf))); 60 str_error_r(err, sbuf, sizeof(sbuf)));
61 if (err == ENOENT && !strcmp(file->path, "perf.data")) 61 if (err == ENOENT && !strcmp(file->path, "perf.data"))
62 pr_err(" (try 'perf record' first)"); 62 pr_err(" (try 'perf record' first)");
63 pr_err("\n"); 63 pr_err("\n");
@@ -99,7 +99,7 @@ static int open_file_write(struct perf_data_file *file)
99 99
100 if (fd < 0) 100 if (fd < 0)
101 pr_err("failed to open %s : %s\n", file->path, 101 pr_err("failed to open %s : %s\n", file->path,
102 strerror_r(errno, sbuf, sizeof(sbuf))); 102 str_error_r(errno, sbuf, sizeof(sbuf)));
103 103
104 return fd; 104 return fd;
105} 105}
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 14bafda79eda..d242adc3d5a2 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -38,7 +38,7 @@ extern int debug_data_convert;
38#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) 38#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
39#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) 39#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
40 40
41#define STRERR_BUFSIZE 128 /* For the buffer size of strerror_r */ 41#define STRERR_BUFSIZE 128 /* For the buffer size of str_error_r */
42 42
43int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 43int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
44void trace_event(union perf_event *event); 44void trace_event(union perf_event *event);
diff --git a/tools/perf/util/demangle-rust.c b/tools/perf/util/demangle-rust.c
new file mode 100644
index 000000000000..f9dafa888c06
--- /dev/null
+++ b/tools/perf/util/demangle-rust.c
@@ -0,0 +1,269 @@
1#include <string.h>
2#include "util.h"
3#include "debug.h"
4
5#include "demangle-rust.h"
6
7/*
8 * Mangled Rust symbols look like this:
9 *
10 * _$LT$std..sys..fd..FileDesc$u20$as$u20$core..ops..Drop$GT$::drop::hc68340e1baa4987a
11 *
12 * The original symbol is:
13 *
14 * <std::sys::fd::FileDesc as core::ops::Drop>::drop
15 *
16 * The last component of the path is a 64-bit hash in lowercase hex, prefixed
17 * with "h". Rust does not have a global namespace between crates, an illusion
18 * which Rust maintains by using the hash to distinguish things that would
19 * otherwise have the same symbol.
20 *
21 * Any path component not starting with a XID_Start character is prefixed with
22 * "_".
23 *
24 * The following escape sequences are used:
25 *
26 * "," => $C$
27 * "@" => $SP$
28 * "*" => $BP$
29 * "&" => $RF$
30 * "<" => $LT$
31 * ">" => $GT$
32 * "(" => $LP$
33 * ")" => $RP$
34 * " " => $u20$
35 * "'" => $u27$
36 * "[" => $u5b$
37 * "]" => $u5d$
38 * "~" => $u7e$
39 *
40 * A double ".." means "::" and a single "." means "-".
41 *
42 * The only characters allowed in the mangled symbol are a-zA-Z0-9 and _.:$
43 */
44
45static const char *hash_prefix = "::h";
46static const size_t hash_prefix_len = 3;
47static const size_t hash_len = 16;
48
49static bool is_prefixed_hash(const char *start);
50static bool looks_like_rust(const char *sym, size_t len);
51static bool unescape(const char **in, char **out, const char *seq, char value);
52
53/*
54 * INPUT:
55 * sym: symbol that has been through BFD-demangling
56 *
57 * This function looks for the following indicators:
58 *
59 * 1. The hash must consist of "h" followed by 16 lowercase hex digits.
60 *
61 * 2. As a sanity check, the hash must use between 5 and 15 of the 16 possible
62 * hex digits. This is true of 99.9998% of hashes so once in your life you
63 * may see a false negative. The point is to notice path components that
64 * could be Rust hashes but are probably not, like "haaaaaaaaaaaaaaaa". In
65 * this case a false positive (non-Rust symbol has an important path
66 * component removed because it looks like a Rust hash) is worse than a
67 * false negative (the rare Rust symbol is not demangled) so this sets the
68 * balance in favor of false negatives.
69 *
70 * 3. There must be no characters other than a-zA-Z0-9 and _.:$
71 *
72 * 4. There must be no unrecognized $-sign sequences.
73 *
74 * 5. There must be no sequence of three or more dots in a row ("...").
75 */
76bool
77rust_is_mangled(const char *sym)
78{
79 size_t len, len_without_hash;
80
81 if (!sym)
82 return false;
83
84 len = strlen(sym);
85 if (len <= hash_prefix_len + hash_len)
86 /* Not long enough to contain "::h" + hash + something else */
87 return false;
88
89 len_without_hash = len - (hash_prefix_len + hash_len);
90 if (!is_prefixed_hash(sym + len_without_hash))
91 return false;
92
93 return looks_like_rust(sym, len_without_hash);
94}
95
96/*
97 * A hash is the prefix "::h" followed by 16 lowercase hex digits. The hex
98 * digits must comprise between 5 and 15 (inclusive) distinct digits.
99 */
100static bool is_prefixed_hash(const char *str)
101{
102 const char *end;
103 bool seen[16];
104 size_t i;
105 int count;
106
107 if (strncmp(str, hash_prefix, hash_prefix_len))
108 return false;
109 str += hash_prefix_len;
110
111 memset(seen, false, sizeof(seen));
112 for (end = str + hash_len; str < end; str++)
113 if (*str >= '0' && *str <= '9')
114 seen[*str - '0'] = true;
115 else if (*str >= 'a' && *str <= 'f')
116 seen[*str - 'a' + 10] = true;
117 else
118 return false;
119
120 /* Count how many distinct digits seen */
121 count = 0;
122 for (i = 0; i < 16; i++)
123 if (seen[i])
124 count++;
125
126 return count >= 5 && count <= 15;
127}
128
129static bool looks_like_rust(const char *str, size_t len)
130{
131 const char *end = str + len;
132
133 while (str < end)
134 switch (*str) {
135 case '$':
136 if (!strncmp(str, "$C$", 3))
137 str += 3;
138 else if (!strncmp(str, "$SP$", 4)
139 || !strncmp(str, "$BP$", 4)
140 || !strncmp(str, "$RF$", 4)
141 || !strncmp(str, "$LT$", 4)
142 || !strncmp(str, "$GT$", 4)
143 || !strncmp(str, "$LP$", 4)
144 || !strncmp(str, "$RP$", 4))
145 str += 4;
146 else if (!strncmp(str, "$u20$", 5)
147 || !strncmp(str, "$u27$", 5)
148 || !strncmp(str, "$u5b$", 5)
149 || !strncmp(str, "$u5d$", 5)
150 || !strncmp(str, "$u7e$", 5))
151 str += 5;
152 else
153 return false;
154 break;
155 case '.':
156 /* Do not allow three or more consecutive dots */
157 if (!strncmp(str, "...", 3))
158 return false;
159 /* Fall through */
160 case 'a' ... 'z':
161 case 'A' ... 'Z':
162 case '0' ... '9':
163 case '_':
164 case ':':
165 str++;
166 break;
167 default:
168 return false;
169 }
170
171 return true;
172}
173
174/*
175 * INPUT:
176 * sym: symbol for which rust_is_mangled(sym) returns true
177 *
178 * The input is demangled in-place because the mangled name is always longer
179 * than the demangled one.
180 */
181void
182rust_demangle_sym(char *sym)
183{
184 const char *in;
185 char *out;
186 const char *end;
187
188 if (!sym)
189 return;
190
191 in = sym;
192 out = sym;
193 end = sym + strlen(sym) - (hash_prefix_len + hash_len);
194
195 while (in < end)
196 switch (*in) {
197 case '$':
198 if (!(unescape(&in, &out, "$C$", ',')
199 || unescape(&in, &out, "$SP$", '@')
200 || unescape(&in, &out, "$BP$", '*')
201 || unescape(&in, &out, "$RF$", '&')
202 || unescape(&in, &out, "$LT$", '<')
203 || unescape(&in, &out, "$GT$", '>')
204 || unescape(&in, &out, "$LP$", '(')
205 || unescape(&in, &out, "$RP$", ')')
206 || unescape(&in, &out, "$u20$", ' ')
207 || unescape(&in, &out, "$u27$", '\'')
208 || unescape(&in, &out, "$u5b$", '[')
209 || unescape(&in, &out, "$u5d$", ']')
210 || unescape(&in, &out, "$u7e$", '~'))) {
211 pr_err("demangle-rust: unexpected escape sequence");
212 goto done;
213 }
214 break;
215 case '_':
216 /*
217 * If this is the start of a path component and the next
218 * character is an escape sequence, ignore the
219 * underscore. The mangler inserts an underscore to make
220 * sure the path component begins with a XID_Start
221 * character.
222 */
223 if ((in == sym || in[-1] == ':') && in[1] == '$')
224 in++;
225 else
226 *out++ = *in++;
227 break;
228 case '.':
229 if (in[1] == '.') {
230 /* ".." becomes "::" */
231 *out++ = ':';
232 *out++ = ':';
233 in += 2;
234 } else {
235 /* "." becomes "-" */
236 *out++ = '-';
237 in++;
238 }
239 break;
240 case 'a' ... 'z':
241 case 'A' ... 'Z':
242 case '0' ... '9':
243 case ':':
244 *out++ = *in++;
245 break;
246 default:
247 pr_err("demangle-rust: unexpected character '%c' in symbol\n",
248 *in);
249 goto done;
250 }
251
252done:
253 *out = '\0';
254}
255
256static bool unescape(const char **in, char **out, const char *seq, char value)
257{
258 size_t len = strlen(seq);
259
260 if (strncmp(*in, seq, len))
261 return false;
262
263 **out = value;
264
265 *in += len;
266 *out += 1;
267
268 return true;
269}
diff --git a/tools/perf/util/demangle-rust.h b/tools/perf/util/demangle-rust.h
new file mode 100644
index 000000000000..7b41ead7e0dd
--- /dev/null
+++ b/tools/perf/util/demangle-rust.h
@@ -0,0 +1,7 @@
1#ifndef __PERF_DEMANGLE_RUST
2#define __PERF_DEMANGLE_RUST 1
3
4bool rust_is_mangled(const char *str);
5void rust_demangle_sym(char *str);
6
7#endif /* __PERF_DEMANGLE_RUST */
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index e1de6cc4863e..774f6ec884d5 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -335,7 +335,7 @@ static int do_open(char *name)
335 return fd; 335 return fd;
336 336
337 pr_debug("dso open failed: %s\n", 337 pr_debug("dso open failed: %s\n",
338 strerror_r(errno, sbuf, sizeof(sbuf))); 338 str_error_r(errno, sbuf, sizeof(sbuf)));
339 if (!dso__data_open_cnt || errno != EMFILE) 339 if (!dso__data_open_cnt || errno != EMFILE)
340 break; 340 break;
341 341
@@ -786,7 +786,7 @@ static int data_file_size(struct dso *dso, struct machine *machine)
786 if (fstat(dso->data.fd, &st) < 0) { 786 if (fstat(dso->data.fd, &st) < 0) {
787 ret = -errno; 787 ret = -errno;
788 pr_err("dso cache fstat failed: %s\n", 788 pr_err("dso cache fstat failed: %s\n",
789 strerror_r(errno, sbuf, sizeof(sbuf))); 789 str_error_r(errno, sbuf, sizeof(sbuf)));
790 dso->data.status = DSO_DATA_STATUS_ERROR; 790 dso->data.status = DSO_DATA_STATUS_ERROR;
791 goto out; 791 goto out;
792 } 792 }
@@ -1366,7 +1366,7 @@ int dso__strerror_load(struct dso *dso, char *buf, size_t buflen)
1366 BUG_ON(buflen == 0); 1366 BUG_ON(buflen == 0);
1367 1367
1368 if (errnum >= 0) { 1368 if (errnum >= 0) {
1369 const char *err = strerror_r(errnum, buf, buflen); 1369 const char *err = str_error_r(errnum, buf, buflen);
1370 1370
1371 if (err != buf) 1371 if (err != buf)
1372 scnprintf(buf, buflen, "%s", err); 1372 scnprintf(buf, buflen, "%s", err);
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index a571f24895ca..ecc4bbd3f82e 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -4,6 +4,7 @@
4#include <linux/atomic.h> 4#include <linux/atomic.h>
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/rbtree.h> 6#include <linux/rbtree.h>
7#include <sys/types.h>
7#include <stdbool.h> 8#include <stdbool.h>
8#include <pthread.h> 9#include <pthread.h>
9#include <linux/types.h> 10#include <linux/types.h>
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 8d363d5e65a2..b32464b353aa 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -8,6 +8,7 @@
8#include "map.h" 8#include "map.h"
9#include "build-id.h" 9#include "build-id.h"
10#include "perf_regs.h" 10#include "perf_regs.h"
11#include <asm/perf_regs.h>
11 12
12struct mmap_event { 13struct mmap_event {
13 struct perf_event_header header; 14 struct perf_event_header header;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 113507716044..862e69c2690d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -651,8 +651,8 @@ static int perf_evlist__event2id(struct perf_evlist *evlist,
651 return 0; 651 return 0;
652} 652}
653 653
654static struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist, 654struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
655 union perf_event *event) 655 union perf_event *event)
656{ 656{
657 struct perf_evsel *first = perf_evlist__first(evlist); 657 struct perf_evsel *first = perf_evlist__first(evlist);
658 struct hlist_head *head; 658 struct hlist_head *head;
@@ -1790,7 +1790,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist,
1790 int err, char *buf, size_t size) 1790 int err, char *buf, size_t size)
1791{ 1791{
1792 int printed, value; 1792 int printed, value;
1793 char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf)); 1793 char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
1794 1794
1795 switch (err) { 1795 switch (err) {
1796 case EACCES: 1796 case EACCES:
@@ -1842,7 +1842,7 @@ out_default:
1842 1842
1843int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size) 1843int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
1844{ 1844{
1845 char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf)); 1845 char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
1846 int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0; 1846 int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
1847 1847
1848 switch (err) { 1848 switch (err) {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 872912b392c9..afd087761a47 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -323,4 +323,7 @@ void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr);
323 323
324struct perf_evsel * 324struct perf_evsel *
325perf_evlist__find_evsel_by_str(struct perf_evlist *evlist, const char *str); 325perf_evlist__find_evsel_by_str(struct perf_evlist *evlist, const char *str);
326
327struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
328 union perf_event *event);
326#endif /* __PERF_EVLIST_H */ 329#endif /* __PERF_EVLIST_H */
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 0fea724e735c..ba0f59fa3d5d 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -200,6 +200,24 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel,
200 evsel->attr.read_format |= PERF_FORMAT_ID; 200 evsel->attr.read_format |= PERF_FORMAT_ID;
201} 201}
202 202
203/**
204 * perf_evsel__is_function_event - Return whether given evsel is a function
205 * trace event
206 *
207 * @evsel - evsel selector to be tested
208 *
209 * Return %true if event is function trace event
210 */
211bool perf_evsel__is_function_event(struct perf_evsel *evsel)
212{
213#define FUNCTION_EVENT "ftrace:function"
214
215 return evsel->name &&
216 !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
217
218#undef FUNCTION_EVENT
219}
220
203void perf_evsel__init(struct perf_evsel *evsel, 221void perf_evsel__init(struct perf_evsel *evsel,
204 struct perf_event_attr *attr, int idx) 222 struct perf_event_attr *attr, int idx)
205{ 223{
@@ -2419,7 +2437,7 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
2419 "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n" 2437 "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
2420 "/bin/dmesg may provide additional information.\n" 2438 "/bin/dmesg may provide additional information.\n"
2421 "No CONFIG_PERF_EVENTS=y kernel support configured?", 2439 "No CONFIG_PERF_EVENTS=y kernel support configured?",
2422 err, strerror_r(err, sbuf, sizeof(sbuf)), 2440 err, str_error_r(err, sbuf, sizeof(sbuf)),
2423 perf_evsel__name(evsel)); 2441 perf_evsel__name(evsel));
2424} 2442}
2425 2443
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 86fed7a2932b..d73391e8740e 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -355,23 +355,7 @@ static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
355 return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1; 355 return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
356} 356}
357 357
358/** 358bool perf_evsel__is_function_event(struct perf_evsel *evsel);
359 * perf_evsel__is_function_event - Return whether given evsel is a function
360 * trace event
361 *
362 * @evsel - evsel selector to be tested
363 *
364 * Return %true if event is function trace event
365 */
366static inline bool perf_evsel__is_function_event(struct perf_evsel *evsel)
367{
368#define FUNCTION_EVENT "ftrace:function"
369
370 return evsel->name &&
371 !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
372
373#undef FUNCTION_EVENT
374}
375 359
376static inline bool perf_evsel__is_bpf_output(struct perf_evsel *evsel) 360static inline bool perf_evsel__is_bpf_output(struct perf_evsel *evsel)
377{ 361{
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index 776e28562345..2821f8d77e52 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -1,5 +1,6 @@
1#include "cache.h" 1#include "cache.h"
2#include "config.h" 2#include "config.h"
3#include <stdio.h>
3#include <subcmd/help.h> 4#include <subcmd/help.h>
4#include "../builtin.h" 5#include "../builtin.h"
5#include "levenshtein.h" 6#include "levenshtein.h"
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index e1fcc8d7c01a..a18d142cdca3 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -352,86 +352,114 @@ void hists__delete_entries(struct hists *hists)
352 * histogram, sorted on item, collects periods 352 * histogram, sorted on item, collects periods
353 */ 353 */
354 354
355static struct hist_entry *hist_entry__new(struct hist_entry *template, 355static int hist_entry__init(struct hist_entry *he,
356 bool sample_self) 356 struct hist_entry *template,
357{ 357 bool sample_self)
358 size_t callchain_size = 0; 358{
359 struct hist_entry *he; 359 *he = *template;
360
361 if (symbol_conf.cumulate_callchain) {
362 he->stat_acc = malloc(sizeof(he->stat));
363 if (he->stat_acc == NULL)
364 return -ENOMEM;
365 memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
366 if (!sample_self)
367 memset(&he->stat, 0, sizeof(he->stat));
368 }
360 369
361 if (symbol_conf.use_callchain) 370 map__get(he->ms.map);
362 callchain_size = sizeof(struct callchain_root); 371
372 if (he->branch_info) {
373 /*
374 * This branch info is (a part of) allocated from
375 * sample__resolve_bstack() and will be freed after
376 * adding new entries. So we need to save a copy.
377 */
378 he->branch_info = malloc(sizeof(*he->branch_info));
379 if (he->branch_info == NULL) {
380 map__zput(he->ms.map);
381 free(he->stat_acc);
382 return -ENOMEM;
383 }
384
385 memcpy(he->branch_info, template->branch_info,
386 sizeof(*he->branch_info));
387
388 map__get(he->branch_info->from.map);
389 map__get(he->branch_info->to.map);
390 }
391
392 if (he->mem_info) {
393 map__get(he->mem_info->iaddr.map);
394 map__get(he->mem_info->daddr.map);
395 }
363 396
364 he = zalloc(sizeof(*he) + callchain_size); 397 if (symbol_conf.use_callchain)
398 callchain_init(he->callchain);
365 399
366 if (he != NULL) { 400 if (he->raw_data) {
367 *he = *template; 401 he->raw_data = memdup(he->raw_data, he->raw_size);
368 402
369 if (symbol_conf.cumulate_callchain) { 403 if (he->raw_data == NULL) {
370 he->stat_acc = malloc(sizeof(he->stat)); 404 map__put(he->ms.map);
371 if (he->stat_acc == NULL) { 405 if (he->branch_info) {
372 free(he); 406 map__put(he->branch_info->from.map);
373 return NULL; 407 map__put(he->branch_info->to.map);
408 free(he->branch_info);
374 } 409 }
375 memcpy(he->stat_acc, &he->stat, sizeof(he->stat)); 410 if (he->mem_info) {
376 if (!sample_self) 411 map__put(he->mem_info->iaddr.map);
377 memset(&he->stat, 0, sizeof(he->stat)); 412 map__put(he->mem_info->daddr.map);
413 }
414 free(he->stat_acc);
415 return -ENOMEM;
378 } 416 }
417 }
418 INIT_LIST_HEAD(&he->pairs.node);
419 thread__get(he->thread);
379 420
380 map__get(he->ms.map); 421 if (!symbol_conf.report_hierarchy)
422 he->leaf = true;
381 423
382 if (he->branch_info) { 424 return 0;
383 /* 425}
384 * This branch info is (a part of) allocated from
385 * sample__resolve_bstack() and will be freed after
386 * adding new entries. So we need to save a copy.
387 */
388 he->branch_info = malloc(sizeof(*he->branch_info));
389 if (he->branch_info == NULL) {
390 map__zput(he->ms.map);
391 free(he->stat_acc);
392 free(he);
393 return NULL;
394 }
395 426
396 memcpy(he->branch_info, template->branch_info, 427static void *hist_entry__zalloc(size_t size)
397 sizeof(*he->branch_info)); 428{
429 return zalloc(size + sizeof(struct hist_entry));
430}
398 431
399 map__get(he->branch_info->from.map); 432static void hist_entry__free(void *ptr)
400 map__get(he->branch_info->to.map); 433{
401 } 434 free(ptr);
435}
402 436
403 if (he->mem_info) { 437static struct hist_entry_ops default_ops = {
404 map__get(he->mem_info->iaddr.map); 438 .new = hist_entry__zalloc,
405 map__get(he->mem_info->daddr.map); 439 .free = hist_entry__free,
406 } 440};
407 441
408 if (symbol_conf.use_callchain) 442static struct hist_entry *hist_entry__new(struct hist_entry *template,
409 callchain_init(he->callchain); 443 bool sample_self)
444{
445 struct hist_entry_ops *ops = template->ops;
446 size_t callchain_size = 0;
447 struct hist_entry *he;
448 int err = 0;
410 449
411 if (he->raw_data) { 450 if (!ops)
412 he->raw_data = memdup(he->raw_data, he->raw_size); 451 ops = template->ops = &default_ops;
413 452
414 if (he->raw_data == NULL) { 453 if (symbol_conf.use_callchain)
415 map__put(he->ms.map); 454 callchain_size = sizeof(struct callchain_root);
416 if (he->branch_info) {
417 map__put(he->branch_info->from.map);
418 map__put(he->branch_info->to.map);
419 free(he->branch_info);
420 }
421 if (he->mem_info) {
422 map__put(he->mem_info->iaddr.map);
423 map__put(he->mem_info->daddr.map);
424 }
425 free(he->stat_acc);
426 free(he);
427 return NULL;
428 }
429 }
430 INIT_LIST_HEAD(&he->pairs.node);
431 thread__get(he->thread);
432 455
433 if (!symbol_conf.report_hierarchy) 456 he = ops->new(callchain_size);
434 he->leaf = true; 457 if (he) {
458 err = hist_entry__init(he, template, sample_self);
459 if (err) {
460 ops->free(he);
461 he = NULL;
462 }
435 } 463 }
436 464
437 return he; 465 return he;
@@ -531,13 +559,15 @@ out:
531 return he; 559 return he;
532} 560}
533 561
534struct hist_entry *hists__add_entry(struct hists *hists, 562static struct hist_entry*
535 struct addr_location *al, 563__hists__add_entry(struct hists *hists,
536 struct symbol *sym_parent, 564 struct addr_location *al,
537 struct branch_info *bi, 565 struct symbol *sym_parent,
538 struct mem_info *mi, 566 struct branch_info *bi,
539 struct perf_sample *sample, 567 struct mem_info *mi,
540 bool sample_self) 568 struct perf_sample *sample,
569 bool sample_self,
570 struct hist_entry_ops *ops)
541{ 571{
542 struct hist_entry entry = { 572 struct hist_entry entry = {
543 .thread = al->thread, 573 .thread = al->thread,
@@ -564,11 +594,37 @@ struct hist_entry *hists__add_entry(struct hists *hists,
564 .transaction = sample->transaction, 594 .transaction = sample->transaction,
565 .raw_data = sample->raw_data, 595 .raw_data = sample->raw_data,
566 .raw_size = sample->raw_size, 596 .raw_size = sample->raw_size,
597 .ops = ops,
567 }; 598 };
568 599
569 return hists__findnew_entry(hists, &entry, al, sample_self); 600 return hists__findnew_entry(hists, &entry, al, sample_self);
570} 601}
571 602
603struct hist_entry *hists__add_entry(struct hists *hists,
604 struct addr_location *al,
605 struct symbol *sym_parent,
606 struct branch_info *bi,
607 struct mem_info *mi,
608 struct perf_sample *sample,
609 bool sample_self)
610{
611 return __hists__add_entry(hists, al, sym_parent, bi, mi,
612 sample, sample_self, NULL);
613}
614
615struct hist_entry *hists__add_entry_ops(struct hists *hists,
616 struct hist_entry_ops *ops,
617 struct addr_location *al,
618 struct symbol *sym_parent,
619 struct branch_info *bi,
620 struct mem_info *mi,
621 struct perf_sample *sample,
622 bool sample_self)
623{
624 return __hists__add_entry(hists, al, sym_parent, bi, mi,
625 sample, sample_self, ops);
626}
627
572static int 628static int
573iter_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, 629iter_next_nop_entry(struct hist_entry_iter *iter __maybe_unused,
574 struct addr_location *al __maybe_unused) 630 struct addr_location *al __maybe_unused)
@@ -1043,6 +1099,8 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
1043 1099
1044void hist_entry__delete(struct hist_entry *he) 1100void hist_entry__delete(struct hist_entry *he)
1045{ 1101{
1102 struct hist_entry_ops *ops = he->ops;
1103
1046 thread__zput(he->thread); 1104 thread__zput(he->thread);
1047 map__zput(he->ms.map); 1105 map__zput(he->ms.map);
1048 1106
@@ -1067,7 +1125,7 @@ void hist_entry__delete(struct hist_entry *he)
1067 free_callchain(he->callchain); 1125 free_callchain(he->callchain);
1068 free(he->trace_output); 1126 free(he->trace_output);
1069 free(he->raw_data); 1127 free(he->raw_data);
1070 free(he); 1128 ops->free(he);
1071} 1129}
1072 1130
1073/* 1131/*
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 0a03e08be503..49aa4fac148f 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -10,6 +10,7 @@
10#include "ui/progress.h" 10#include "ui/progress.h"
11 11
12struct hist_entry; 12struct hist_entry;
13struct hist_entry_ops;
13struct addr_location; 14struct addr_location;
14struct symbol; 15struct symbol;
15 16
@@ -127,6 +128,16 @@ struct hist_entry *hists__add_entry(struct hists *hists,
127 struct mem_info *mi, 128 struct mem_info *mi,
128 struct perf_sample *sample, 129 struct perf_sample *sample,
129 bool sample_self); 130 bool sample_self);
131
132struct hist_entry *hists__add_entry_ops(struct hists *hists,
133 struct hist_entry_ops *ops,
134 struct addr_location *al,
135 struct symbol *sym_parent,
136 struct branch_info *bi,
137 struct mem_info *mi,
138 struct perf_sample *sample,
139 bool sample_self);
140
130int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, 141int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
131 int max_stack_depth, void *arg); 142 int max_stack_depth, void *arg);
132 143
diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
deleted file mode 100644
index 3a3a0f16456a..000000000000
--- a/tools/perf/util/include/asm/alternative-asm.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef _PERF_ASM_ALTERNATIVE_ASM_H
2#define _PERF_ASM_ALTERNATIVE_ASM_H
3
4/* Just disable it so we can build arch/x86/lib/memcpy_64.S for perf bench: */
5
6#define altinstruction_entry #
7#define ALTERNATIVE_2 #
8
9#endif
diff --git a/tools/perf/util/include/asm/unistd_32.h b/tools/perf/util/include/asm/unistd_32.h
deleted file mode 100644
index 8b137891791f..000000000000
--- a/tools/perf/util/include/asm/unistd_32.h
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/tools/perf/util/include/asm/unistd_64.h b/tools/perf/util/include/asm/unistd_64.h
deleted file mode 100644
index 8b137891791f..000000000000
--- a/tools/perf/util/include/asm/unistd_64.h
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/tools/perf/util/intel-pt-decoder/Build b/tools/perf/util/intel-pt-decoder/Build
index 0611d619a42e..9b742ea8bfe8 100644
--- a/tools/perf/util/intel-pt-decoder/Build
+++ b/tools/perf/util/intel-pt-decoder/Build
@@ -7,8 +7,11 @@ $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tables_script) $(inat_table
7 $(call rule_mkdir) 7 $(call rule_mkdir)
8 @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ || rm -f $@ 8 @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ || rm -f $@
9 9
10# Busybox's diff doesn't have -I, avoid warning in the case
11
10$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-decoder/intel-pt-insn-decoder.c util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c 12$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-decoder/intel-pt-insn-decoder.c util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c
11 @(test -d ../../kernel -a -d ../../tools -a -d ../perf && (( \ 13 @(diff -I 2>&1 | grep -q 'option requires an argument' && \
14 test -d ../../kernel -a -d ../../tools -a -d ../perf && (( \
12 diff -B -I'^#include' util/intel-pt-decoder/insn.c ../../arch/x86/lib/insn.c >/dev/null && \ 15 diff -B -I'^#include' util/intel-pt-decoder/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
13 diff -B -I'^#include' util/intel-pt-decoder/inat.c ../../arch/x86/lib/inat.c >/dev/null && \ 16 diff -B -I'^#include' util/intel-pt-decoder/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
14 diff -B util/intel-pt-decoder/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \ 17 diff -B util/intel-pt-decoder/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
diff --git a/tools/perf/util/levenshtein.c b/tools/perf/util/levenshtein.c
index e521d1516df6..f616e4f65b67 100644
--- a/tools/perf/util/levenshtein.c
+++ b/tools/perf/util/levenshtein.c
@@ -1,5 +1,7 @@
1#include "cache.h"
2#include "levenshtein.h" 1#include "levenshtein.h"
2#include <errno.h>
3#include <stdlib.h>
4#include <string.h>
3 5
4/* 6/*
5 * This function implements the Damerau-Levenshtein algorithm to 7 * This function implements the Damerau-Levenshtein algorithm to
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 40b6f7269cb4..bf7216b8731d 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -3,12 +3,14 @@
3 * Copyright (C) 2015, Huawei Inc. 3 * Copyright (C) 2015, Huawei Inc.
4 */ 4 */
5 5
6#include <errno.h>
6#include <limits.h> 7#include <limits.h>
7#include <stdio.h> 8#include <stdio.h>
8#include <stdlib.h> 9#include <stdlib.h>
9#include "debug.h" 10#include "debug.h"
10#include "llvm-utils.h" 11#include "llvm-utils.h"
11#include "config.h" 12#include "config.h"
13#include "util.h"
12 14
13#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 15#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
14 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ 16 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
@@ -106,7 +108,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
106 file = popen(cmd, "r"); 108 file = popen(cmd, "r");
107 if (!file) { 109 if (!file) {
108 pr_err("ERROR: unable to popen cmd: %s\n", 110 pr_err("ERROR: unable to popen cmd: %s\n",
109 strerror_r(errno, serr, sizeof(serr))); 111 str_error_r(errno, serr, sizeof(serr)));
110 return -EINVAL; 112 return -EINVAL;
111 } 113 }
112 114
@@ -140,7 +142,7 @@ read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
140 142
141 if (ferror(file)) { 143 if (ferror(file)) {
142 pr_err("ERROR: error occurred when reading from pipe: %s\n", 144 pr_err("ERROR: error occurred when reading from pipe: %s\n",
143 strerror_r(errno, serr, sizeof(serr))); 145 str_error_r(errno, serr, sizeof(serr)));
144 err = -EIO; 146 err = -EIO;
145 goto errout; 147 goto errout;
146 } 148 }
@@ -382,7 +384,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
382 if (path[0] != '-' && realpath(path, abspath) == NULL) { 384 if (path[0] != '-' && realpath(path, abspath) == NULL) {
383 err = errno; 385 err = errno;
384 pr_err("ERROR: problems with path %s: %s\n", 386 pr_err("ERROR: problems with path %s: %s\n",
385 path, strerror_r(err, serr, sizeof(serr))); 387 path, str_error_r(err, serr, sizeof(serr)));
386 return -err; 388 return -err;
387 } 389 }
388 390
@@ -410,7 +412,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
410 if (nr_cpus_avail <= 0) { 412 if (nr_cpus_avail <= 0) {
411 pr_err( 413 pr_err(
412"WARNING:\tunable to get available CPUs in this system: %s\n" 414"WARNING:\tunable to get available CPUs in this system: %s\n"
413" \tUse 128 instead.\n", strerror_r(errno, serr, sizeof(serr))); 415" \tUse 128 instead.\n", str_error_r(errno, serr, sizeof(serr)));
414 nr_cpus_avail = 128; 416 nr_cpus_avail = 128;
415 } 417 }
416 snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d", 418 snprintf(nr_cpus_avail_str, sizeof(nr_cpus_avail_str), "%d",
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index cff8bf0f87e8..7c7630be5a89 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -11,6 +11,8 @@
11 * which is what it's designed for. 11 * which is what it's designed for.
12 */ 12 */
13#include "cache.h" 13#include "cache.h"
14#include "util.h"
15#include <limits.h>
14 16
15static char bad_path[] = "/bad-path/"; 17static char bad_path[] = "/bad-path/";
16/* 18/*
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 0201f661ccb8..2b222a7955c9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -468,7 +468,7 @@ static struct debuginfo *open_debuginfo(const char *module, bool silent)
468 err = kernel_get_module_dso(module, &dso); 468 err = kernel_get_module_dso(module, &dso);
469 if (err < 0) { 469 if (err < 0) {
470 if (!dso || dso->load_errno == 0) { 470 if (!dso || dso->load_errno == 0) {
471 if (!strerror_r(-err, reason, STRERR_BUFSIZE)) 471 if (!str_error_r(-err, reason, STRERR_BUFSIZE))
472 strcpy(reason, "(unknown)"); 472 strcpy(reason, "(unknown)");
473 } else 473 } else
474 dso__strerror_load(dso, reason, STRERR_BUFSIZE); 474 dso__strerror_load(dso, reason, STRERR_BUFSIZE);
@@ -806,7 +806,7 @@ static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
806error: 806error:
807 if (ferror(fp)) { 807 if (ferror(fp)) {
808 pr_warning("File read error: %s\n", 808 pr_warning("File read error: %s\n",
809 strerror_r(errno, sbuf, sizeof(sbuf))); 809 str_error_r(errno, sbuf, sizeof(sbuf)));
810 return -1; 810 return -1;
811 } 811 }
812 return 0; 812 return 0;
@@ -886,7 +886,7 @@ static int __show_line_range(struct line_range *lr, const char *module,
886 fp = fopen(lr->path, "r"); 886 fp = fopen(lr->path, "r");
887 if (fp == NULL) { 887 if (fp == NULL) {
888 pr_warning("Failed to open %s: %s\n", lr->path, 888 pr_warning("Failed to open %s: %s\n", lr->path,
889 strerror_r(errno, sbuf, sizeof(sbuf))); 889 str_error_r(errno, sbuf, sizeof(sbuf)));
890 return -errno; 890 return -errno;
891 } 891 }
892 /* Skip to starting line number */ 892 /* Skip to starting line number */
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 5b563b2e8b1d..e705a742ee1e 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -50,7 +50,7 @@ static void print_open_warning(int err, bool uprobe)
50 else 50 else
51 pr_warning("Failed to open %cprobe_events: %s\n", 51 pr_warning("Failed to open %cprobe_events: %s\n",
52 uprobe ? 'u' : 'k', 52 uprobe ? 'u' : 'k',
53 strerror_r(-err, sbuf, sizeof(sbuf))); 53 str_error_r(-err, sbuf, sizeof(sbuf)));
54} 54}
55 55
56static void print_both_open_warning(int kerr, int uerr) 56static void print_both_open_warning(int kerr, int uerr)
@@ -64,9 +64,9 @@ static void print_both_open_warning(int kerr, int uerr)
64 else { 64 else {
65 char sbuf[STRERR_BUFSIZE]; 65 char sbuf[STRERR_BUFSIZE];
66 pr_warning("Failed to open kprobe events: %s.\n", 66 pr_warning("Failed to open kprobe events: %s.\n",
67 strerror_r(-kerr, sbuf, sizeof(sbuf))); 67 str_error_r(-kerr, sbuf, sizeof(sbuf)));
68 pr_warning("Failed to open uprobe events: %s.\n", 68 pr_warning("Failed to open uprobe events: %s.\n",
69 strerror_r(-uerr, sbuf, sizeof(sbuf))); 69 str_error_r(-uerr, sbuf, sizeof(sbuf)));
70 } 70 }
71} 71}
72 72
@@ -224,7 +224,7 @@ int probe_file__add_event(int fd, struct probe_trace_event *tev)
224 if (write(fd, buf, strlen(buf)) < (int)strlen(buf)) { 224 if (write(fd, buf, strlen(buf)) < (int)strlen(buf)) {
225 ret = -errno; 225 ret = -errno;
226 pr_warning("Failed to write event: %s\n", 226 pr_warning("Failed to write event: %s\n",
227 strerror_r(errno, sbuf, sizeof(sbuf))); 227 str_error_r(errno, sbuf, sizeof(sbuf)));
228 } 228 }
229 } 229 }
230 free(buf); 230 free(buf);
@@ -262,7 +262,7 @@ static int __del_trace_probe_event(int fd, struct str_node *ent)
262 return 0; 262 return 0;
263error: 263error:
264 pr_warning("Failed to delete event: %s\n", 264 pr_warning("Failed to delete event: %s\n",
265 strerror_r(-ret, buf, sizeof(buf))); 265 str_error_r(-ret, buf, sizeof(buf)));
266 return ret; 266 return ret;
267} 267}
268 268
@@ -624,6 +624,7 @@ out_err:
624 return ret; 624 return ret;
625} 625}
626 626
627#ifdef HAVE_GELF_GETNOTE_SUPPORT
627static unsigned long long sdt_note__get_addr(struct sdt_note *note) 628static unsigned long long sdt_note__get_addr(struct sdt_note *note)
628{ 629{
629 return note->bit32 ? (unsigned long long)note->addr.a32[0] 630 return note->bit32 ? (unsigned long long)note->addr.a32[0]
@@ -682,6 +683,7 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
682 cleanup_sdt_note_list(&sdtlist); 683 cleanup_sdt_note_list(&sdtlist);
683 return ret; 684 return ret;
684} 685}
686#endif
685 687
686static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd) 688static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
687{ 689{
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 1259839dbf6d..f2d9ff064e2d 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -381,7 +381,7 @@ formatted:
381 if (ret >= 16) 381 if (ret >= 16)
382 ret = -E2BIG; 382 ret = -E2BIG;
383 pr_warning("Failed to convert variable type: %s\n", 383 pr_warning("Failed to convert variable type: %s\n",
384 strerror_r(-ret, sbuf, sizeof(sbuf))); 384 str_error_r(-ret, sbuf, sizeof(sbuf)));
385 return ret; 385 return ret;
386 } 386 }
387 tvar->type = strdup(buf); 387 tvar->type = strdup(buf);
@@ -809,7 +809,7 @@ static int find_lazy_match_lines(struct intlist *list,
809 fp = fopen(fname, "r"); 809 fp = fopen(fname, "r");
810 if (!fp) { 810 if (!fp) {
811 pr_warning("Failed to open %s: %s\n", fname, 811 pr_warning("Failed to open %s: %s\n", fname,
812 strerror_r(errno, sbuf, sizeof(sbuf))); 812 str_error_r(errno, sbuf, sizeof(sbuf)));
813 return -errno; 813 return -errno;
814 } 814 }
815 815
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 36c6862119e3..5065ec98049c 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -13,6 +13,8 @@ util/cpumap.c
13../lib/bitmap.c 13../lib/bitmap.c
14../lib/find_bit.c 14../lib/find_bit.c
15../lib/hweight.c 15../lib/hweight.c
16../lib/str_error_r.c
17../lib/vsprintf.c
16util/thread_map.c 18util/thread_map.c
17util/util.c 19util/util.c
18util/xyarray.c 20util/xyarray.c
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 65c6c73d28fe..d32f97033718 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -2,6 +2,7 @@
2#include <structmember.h> 2#include <structmember.h>
3#include <inttypes.h> 3#include <inttypes.h>
4#include <poll.h> 4#include <poll.h>
5#include <linux/err.h>
5#include "evlist.h" 6#include "evlist.h"
6#include "evsel.h" 7#include "evsel.h"
7#include "event.h" 8#include "event.h"
@@ -47,6 +48,7 @@ PyMODINIT_FUNC initperf(void);
47 48
48struct pyrf_event { 49struct pyrf_event {
49 PyObject_HEAD 50 PyObject_HEAD
51 struct perf_evsel *evsel;
50 struct perf_sample sample; 52 struct perf_sample sample;
51 union perf_event event; 53 union perf_event event;
52}; 54};
@@ -288,6 +290,97 @@ static PyObject *pyrf_sample_event__repr(struct pyrf_event *pevent)
288 return ret; 290 return ret;
289} 291}
290 292
293static bool is_tracepoint(struct pyrf_event *pevent)
294{
295 return pevent->evsel->attr.type == PERF_TYPE_TRACEPOINT;
296}
297
298static int is_printable_array(char *p, unsigned int len)
299{
300 unsigned int i;
301
302 for (i = 0; i < len; i++) {
303 if (!isprint(p[i]) && !isspace(p[i]))
304 return 0;
305 }
306
307 return 1;
308}
309
310static PyObject*
311tracepoint_field(struct pyrf_event *pe, struct format_field *field)
312{
313 struct pevent *pevent = field->event->pevent;
314 void *data = pe->sample.raw_data;
315 PyObject *ret = NULL;
316 unsigned long long val;
317 unsigned int offset, len;
318
319 if (field->flags & FIELD_IS_ARRAY) {
320 offset = field->offset;
321 len = field->size;
322 if (field->flags & FIELD_IS_DYNAMIC) {
323 val = pevent_read_number(pevent, data + offset, len);
324 offset = val;
325 len = offset >> 16;
326 offset &= 0xffff;
327 }
328 if (field->flags & FIELD_IS_STRING &&
329 is_printable_array(data + offset, len)) {
330 ret = PyString_FromString((char *)data + offset);
331 } else {
332 ret = PyByteArray_FromStringAndSize((const char *) data + offset, len);
333 field->flags &= ~FIELD_IS_STRING;
334 }
335 } else {
336 val = pevent_read_number(pevent, data + field->offset,
337 field->size);
338 if (field->flags & FIELD_IS_POINTER)
339 ret = PyLong_FromUnsignedLong((unsigned long) val);
340 else if (field->flags & FIELD_IS_SIGNED)
341 ret = PyLong_FromLong((long) val);
342 else
343 ret = PyLong_FromUnsignedLong((unsigned long) val);
344 }
345
346 return ret;
347}
348
349static PyObject*
350get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
351{
352 const char *str = PyString_AsString(PyObject_Str(attr_name));
353 struct perf_evsel *evsel = pevent->evsel;
354 struct format_field *field;
355
356 if (!evsel->tp_format) {
357 struct event_format *tp_format;
358
359 tp_format = trace_event__tp_format_id(evsel->attr.config);
360 if (!tp_format)
361 return NULL;
362
363 evsel->tp_format = tp_format;
364 }
365
366 field = pevent_find_any_field(evsel->tp_format, str);
367 if (!field)
368 return NULL;
369
370 return tracepoint_field(pevent, field);
371}
372
373static PyObject*
374pyrf_sample_event__getattro(struct pyrf_event *pevent, PyObject *attr_name)
375{
376 PyObject *obj = NULL;
377
378 if (is_tracepoint(pevent))
379 obj = get_tracepoint_field(pevent, attr_name);
380
381 return obj ?: PyObject_GenericGetAttr((PyObject *) pevent, attr_name);
382}
383
291static PyTypeObject pyrf_sample_event__type = { 384static PyTypeObject pyrf_sample_event__type = {
292 PyVarObject_HEAD_INIT(NULL, 0) 385 PyVarObject_HEAD_INIT(NULL, 0)
293 .tp_name = "perf.sample_event", 386 .tp_name = "perf.sample_event",
@@ -296,6 +389,7 @@ static PyTypeObject pyrf_sample_event__type = {
296 .tp_doc = pyrf_sample_event__doc, 389 .tp_doc = pyrf_sample_event__doc,
297 .tp_members = pyrf_sample_event__members, 390 .tp_members = pyrf_sample_event__members,
298 .tp_repr = (reprfunc)pyrf_sample_event__repr, 391 .tp_repr = (reprfunc)pyrf_sample_event__repr,
392 .tp_getattro = (getattrofunc) pyrf_sample_event__getattro,
299}; 393};
300 394
301static char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object."); 395static char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object.");
@@ -653,6 +747,7 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel,
653 attr.precise_ip = precise_ip; 747 attr.precise_ip = precise_ip;
654 attr.mmap_data = mmap_data; 748 attr.mmap_data = mmap_data;
655 attr.sample_id_all = sample_id_all; 749 attr.sample_id_all = sample_id_all;
750 attr.size = sizeof(attr);
656 751
657 perf_evsel__init(&pevsel->evsel, &attr, idx); 752 perf_evsel__init(&pevsel->evsel, &attr, idx);
658 return 0; 753 return 0;
@@ -863,13 +958,22 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
863 if (event != NULL) { 958 if (event != NULL) {
864 PyObject *pyevent = pyrf_event__new(event); 959 PyObject *pyevent = pyrf_event__new(event);
865 struct pyrf_event *pevent = (struct pyrf_event *)pyevent; 960 struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
866 961 struct perf_evsel *evsel;
867 perf_evlist__mmap_consume(evlist, cpu);
868 962
869 if (pyevent == NULL) 963 if (pyevent == NULL)
870 return PyErr_NoMemory(); 964 return PyErr_NoMemory();
871 965
872 err = perf_evlist__parse_sample(evlist, event, &pevent->sample); 966 evsel = perf_evlist__event2evsel(evlist, event);
967 if (!evsel)
968 return Py_None;
969
970 pevent->evsel = evsel;
971
972 err = perf_evsel__parse_sample(evsel, event, &pevent->sample);
973
974 /* Consume the even only after we parsed it out. */
975 perf_evlist__mmap_consume(evlist, cpu);
976
873 if (err) 977 if (err)
874 return PyErr_Format(PyExc_OSError, 978 return PyErr_Format(PyExc_OSError,
875 "perf: can't parse sample, err=%d", err); 979 "perf: can't parse sample, err=%d", err);
@@ -1073,7 +1177,32 @@ static struct {
1073 { .name = NULL, }, 1177 { .name = NULL, },
1074}; 1178};
1075 1179
1180static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel,
1181 PyObject *args, PyObject *kwargs)
1182{
1183 struct event_format *tp_format;
1184 static char *kwlist[] = { "sys", "name", NULL };
1185 char *sys = NULL;
1186 char *name = NULL;
1187
1188 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss", kwlist,
1189 &sys, &name))
1190 return NULL;
1191
1192 tp_format = trace_event__tp_format(sys, name);
1193 if (IS_ERR(tp_format))
1194 return PyInt_FromLong(-1);
1195
1196 return PyInt_FromLong(tp_format->id);
1197}
1198
1076static PyMethodDef perf__methods[] = { 1199static PyMethodDef perf__methods[] = {
1200 {
1201 .ml_name = "tracepoint",
1202 .ml_meth = (PyCFunction) pyrf__tracepoint,
1203 .ml_flags = METH_VARARGS | METH_KEYWORDS,
1204 .ml_doc = PyDoc_STR("Get tracepoint config.")
1205 },
1077 { .ml_name = NULL, } 1206 { .ml_name = NULL, }
1078}; 1207};
1079 1208
@@ -1100,6 +1229,33 @@ PyMODINIT_FUNC initperf(void)
1100 Py_INCREF(&pyrf_evsel__type); 1229 Py_INCREF(&pyrf_evsel__type);
1101 PyModule_AddObject(module, "evsel", (PyObject*)&pyrf_evsel__type); 1230 PyModule_AddObject(module, "evsel", (PyObject*)&pyrf_evsel__type);
1102 1231
1232 Py_INCREF(&pyrf_mmap_event__type);
1233 PyModule_AddObject(module, "mmap_event", (PyObject *)&pyrf_mmap_event__type);
1234
1235 Py_INCREF(&pyrf_lost_event__type);
1236 PyModule_AddObject(module, "lost_event", (PyObject *)&pyrf_lost_event__type);
1237
1238 Py_INCREF(&pyrf_comm_event__type);
1239 PyModule_AddObject(module, "comm_event", (PyObject *)&pyrf_comm_event__type);
1240
1241 Py_INCREF(&pyrf_task_event__type);
1242 PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type);
1243
1244 Py_INCREF(&pyrf_throttle_event__type);
1245 PyModule_AddObject(module, "throttle_event", (PyObject *)&pyrf_throttle_event__type);
1246
1247 Py_INCREF(&pyrf_task_event__type);
1248 PyModule_AddObject(module, "task_event", (PyObject *)&pyrf_task_event__type);
1249
1250 Py_INCREF(&pyrf_read_event__type);
1251 PyModule_AddObject(module, "read_event", (PyObject *)&pyrf_read_event__type);
1252
1253 Py_INCREF(&pyrf_sample_event__type);
1254 PyModule_AddObject(module, "sample_event", (PyObject *)&pyrf_sample_event__type);
1255
1256 Py_INCREF(&pyrf_context_switch_event__type);
1257 PyModule_AddObject(module, "switch_event", (PyObject *)&pyrf_context_switch_event__type);
1258
1103 Py_INCREF(&pyrf_thread_map__type); 1259 Py_INCREF(&pyrf_thread_map__type);
1104 PyModule_AddObject(module, "thread_map", (PyObject*)&pyrf_thread_map__type); 1260 PyModule_AddObject(module, "thread_map", (PyObject*)&pyrf_thread_map__type);
1105 1261
diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c
index c6d4ee2de752..639d1da2f978 100644
--- a/tools/perf/util/quote.c
+++ b/tools/perf/util/quote.c
@@ -1,5 +1,7 @@
1#include "cache.h" 1#include <stdlib.h>
2#include "strbuf.h"
2#include "quote.h" 3#include "quote.h"
4#include "util.h"
3 5
4/* Help to copy the thing properly quoted for the shell safety. 6/* Help to copy the thing properly quoted for the shell safety.
5 * any single quote is replaced with '\'', any exclamation point 7 * any single quote is replaced with '\'', any exclamation point
diff --git a/tools/perf/util/quote.h b/tools/perf/util/quote.h
index e1ec19146fb0..055ca45bed99 100644
--- a/tools/perf/util/quote.h
+++ b/tools/perf/util/quote.h
@@ -2,7 +2,6 @@
2#define __PERF_QUOTE_H 2#define __PERF_QUOTE_H
3 3
4#include <stddef.h> 4#include <stddef.h>
5#include <stdio.h>
6 5
7/* Help to copy the thing properly quoted for the shell safety. 6/* Help to copy the thing properly quoted for the shell safety.
8 * any single quote is replaced with '\'', any exclamation point 7 * any single quote is replaced with '\'', any exclamation point
@@ -24,6 +23,8 @@
24 * sq_quote() in a real application. 23 * sq_quote() in a real application.
25 */ 24 */
26 25
26struct strbuf;
27
27int sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen); 28int sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
28 29
29#endif /* __PERF_QUOTE_H */ 30#endif /* __PERF_QUOTE_H */
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index ff134700bf30..6ac6b7a33f42 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -273,7 +273,7 @@ static PyObject *get_field_numeric_entry(struct event_format *event,
273 struct format_field *field, void *data) 273 struct format_field *field, void *data)
274{ 274{
275 bool is_array = field->flags & FIELD_IS_ARRAY; 275 bool is_array = field->flags & FIELD_IS_ARRAY;
276 PyObject *obj, *list = NULL; 276 PyObject *obj = NULL, *list = NULL;
277 unsigned long long val; 277 unsigned long long val;
278 unsigned int item_size, n_items, i; 278 unsigned int item_size, n_items, i;
279 279
@@ -392,7 +392,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
392 struct addr_location *al) 392 struct addr_location *al)
393{ 393{
394 struct event_format *event = evsel->tp_format; 394 struct event_format *event = evsel->tp_format;
395 PyObject *handler, *context, *t, *obj, *callchain; 395 PyObject *handler, *context, *t, *obj = NULL, *callchain;
396 PyObject *dict = NULL; 396 PyObject *dict = NULL;
397 static char handler_name[256]; 397 static char handler_name[256];
398 struct format_field *field; 398 struct format_field *field;
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index ebb59cacd092..7ca37ea17395 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -67,6 +67,11 @@ struct hist_entry_diff {
67 }; 67 };
68}; 68};
69 69
70struct hist_entry_ops {
71 void *(*new)(size_t size);
72 void (*free)(void *ptr);
73};
74
70/** 75/**
71 * struct hist_entry - histogram entry 76 * struct hist_entry - histogram entry
72 * 77 *
@@ -125,6 +130,7 @@ struct hist_entry {
125 void *trace_output; 130 void *trace_output;
126 struct perf_hpp_list *hpp_list; 131 struct perf_hpp_list *hpp_list;
127 struct hist_entry *parent_he; 132 struct hist_entry *parent_he;
133 struct hist_entry_ops *ops;
128 union { 134 union {
129 /* this is for hierarchical entry structure */ 135 /* this is for hierarchical entry structure */
130 struct { 136 struct {
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index f95f682aa2b2..817593908d47 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -1,5 +1,5 @@
1#include "debug.h" 1#include "debug.h"
2#include "cache.h" 2#include "util.h"
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4 4
5int prefixcmp(const char *str, const char *prefix) 5int prefixcmp(const char *str, const char *prefix)
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h
index 54b409297d4a..b268a6648a5d 100644
--- a/tools/perf/util/strbuf.h
+++ b/tools/perf/util/strbuf.h
@@ -40,6 +40,9 @@
40 40
41#include <assert.h> 41#include <assert.h>
42#include <stdarg.h> 42#include <stdarg.h>
43#include <stddef.h>
44#include <string.h>
45#include <sys/types.h>
43 46
44extern char strbuf_slopbuf[]; 47extern char strbuf_slopbuf[];
45struct strbuf { 48struct strbuf {
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 6f15b92cbf70..a34321e9b44d 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -7,6 +7,7 @@
7 7
8#include "symbol.h" 8#include "symbol.h"
9#include "demangle-java.h" 9#include "demangle-java.h"
10#include "demangle-rust.h"
10#include "machine.h" 11#include "machine.h"
11#include "vdso.h" 12#include "vdso.h"
12#include <symbol/kallsyms.h> 13#include <symbol/kallsyms.h>
@@ -16,6 +17,7 @@
16#define EM_AARCH64 183 /* ARM 64 bit */ 17#define EM_AARCH64 183 /* ARM 64 bit */
17#endif 18#endif
18 19
20typedef Elf64_Nhdr GElf_Nhdr;
19 21
20#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT 22#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
21extern char *cplus_demangle(const char *, int); 23extern char *cplus_demangle(const char *, int);
@@ -1080,6 +1082,13 @@ new_symbol:
1080 demangled = bfd_demangle(NULL, elf_name, demangle_flags); 1082 demangled = bfd_demangle(NULL, elf_name, demangle_flags);
1081 if (demangled == NULL) 1083 if (demangled == NULL)
1082 demangled = java_demangle_sym(elf_name, JAVA_DEMANGLE_NORET); 1084 demangled = java_demangle_sym(elf_name, JAVA_DEMANGLE_NORET);
1085 else if (rust_is_mangled(demangled))
1086 /*
1087 * Input to Rust demangling is the BFD-demangled
1088 * name which it Rust-demangles in place.
1089 */
1090 rust_demangle_sym(demangled);
1091
1083 if (demangled != NULL) 1092 if (demangled != NULL)
1084 elf_name = demangled; 1093 elf_name = demangled;
1085 } 1094 }
@@ -1789,6 +1798,7 @@ void kcore_extract__delete(struct kcore_extract *kce)
1789 unlink(kce->extract_filename); 1798 unlink(kce->extract_filename);
1790} 1799}
1791 1800
1801#ifdef HAVE_GELF_GETNOTE_SUPPORT
1792/** 1802/**
1793 * populate_sdt_note : Parse raw data and identify SDT note 1803 * populate_sdt_note : Parse raw data and identify SDT note
1794 * @elf: elf of the opened file 1804 * @elf: elf of the opened file
@@ -2040,6 +2050,7 @@ int sdt_notes__get_count(struct list_head *start)
2040 count++; 2050 count++;
2041 return count; 2051 return count;
2042} 2052}
2053#endif
2043 2054
2044void symbol__elf_init(void) 2055void symbol__elf_init(void)
2045{ 2056{
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index a53603b27e52..8cdcf4641c51 100644
--- a/tools/perf/util/target.c
+++ b/tools/perf/util/target.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include "target.h" 9#include "target.h"
10#include "util.h"
10#include "debug.h" 11#include "debug.h"
11 12
12#include <pwd.h> 13#include <pwd.h>
@@ -121,7 +122,7 @@ int target__strerror(struct target *target, int errnum,
121 BUG_ON(buflen == 0); 122 BUG_ON(buflen == 0);
122 123
123 if (errnum >= 0) { 124 if (errnum >= 0) {
124 const char *err = strerror_r(errnum, buf, buflen); 125 const char *err = str_error_r(errnum, buf, buflen);
125 126
126 if (err != buf) 127 if (err != buf)
127 scnprintf(buf, buflen, "%s", err); 128 scnprintf(buf, buflen, "%s", err);
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
index 8ae051e0ec79..c330780674fc 100644
--- a/tools/perf/util/trace-event.c
+++ b/tools/perf/util/trace-event.c
@@ -105,3 +105,11 @@ trace_event__tp_format(const char *sys, const char *name)
105 105
106 return tp_format(sys, name); 106 return tp_format(sys, name);
107} 107}
108
109struct event_format *trace_event__tp_format_id(int id)
110{
111 if (!tevent_initialized && trace_event__init2())
112 return ERR_PTR(-ENOMEM);
113
114 return pevent_find_event(tevent.pevent, id);
115}
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index bce5b1dac268..b0af9c81bb0d 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -23,6 +23,8 @@ int trace_event__register_resolver(struct machine *machine,
23struct event_format* 23struct event_format*
24trace_event__tp_format(const char *sys, const char *name); 24trace_event__tp_format(const char *sys, const char *name);
25 25
26struct event_format *trace_event__tp_format_id(int id);
27
26int bigendian(void); 28int bigendian(void);
27 29
28void event_format__fprintf(struct event_format *event, 30void event_format__fprintf(struct event_format *event,
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 1e8c3167b9fb..6178cab82374 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -72,7 +72,6 @@
72#include <sys/ioctl.h> 72#include <sys/ioctl.h>
73#include <inttypes.h> 73#include <inttypes.h>
74#include <linux/kernel.h> 74#include <linux/kernel.h>
75#include <linux/magic.h>
76#include <linux/types.h> 75#include <linux/types.h>
77#include <sys/ttydefaults.h> 76#include <sys/ttydefaults.h>
78#include <api/fs/tracing_path.h> 77#include <api/fs/tracing_path.h>
@@ -360,4 +359,9 @@ typedef void (*print_binary_t)(enum binary_printer_ops,
360void print_binary(unsigned char *data, size_t len, 359void print_binary(unsigned char *data, size_t len,
361 size_t bytes_per_line, print_binary_t printer, 360 size_t bytes_per_line, print_binary_t printer,
362 void *extra); 361 void *extra);
362
363#ifndef __GLIBC__
364extern int sched_getcpu(void);
365#endif
366
363#endif /* GIT_COMPAT_UTIL_H */ 367#endif /* GIT_COMPAT_UTIL_H */