aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-02 19:15:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-02 19:15:23 -0400
commitf0bb4c0ab064a8aeeffbda1cee380151a594eaab (patch)
tree14d55a89c5db455aa10ff9a96ca14c474a9c4d55 /tools
parenta4883ef6af5e513a1e8c2ab9aab721604aa3a4f5 (diff)
parent983433b5812c5cf33a9008fa38c6f9b407fedb76 (diff)
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "Kernel improvements: - watchdog driver improvements by Li Zefan - Power7 CPI stack events related improvements by Sukadev Bhattiprolu - event multiplexing via hrtimers and other improvements by Stephane Eranian - kernel stack use optimization by Andrew Hunter - AMD IOMMU uncore PMU support by Suravee Suthikulpanit - NMI handling rate-limits by Dave Hansen - various hw_breakpoint fixes by Oleg Nesterov - hw_breakpoint overflow period sampling and related signal handling fixes by Jiri Olsa - Intel Haswell PMU support by Andi Kleen Tooling improvements: - Reset SIGTERM handler in workload child process, fix from David Ahern. - Makefile reorganization, prep work for Kconfig patches, from Jiri Olsa. - Add automated make test suite, from Jiri Olsa. - Add --percent-limit option to 'top' and 'report', from Namhyung Kim. - Sorting improvements, from Namhyung Kim. - Expand definition of sysfs format attribute, from Michael Ellerman. Tooling fixes: - 'perf tests' fixes from Jiri Olsa. - Make Power7 CPI stack events available in sysfs, from Sukadev Bhattiprolu. - Handle death by SIGTERM in 'perf record', fix from David Ahern. - Fix printing of perf_event_paranoid message, from David Ahern. - Handle realloc failures in 'perf kvm', from David Ahern. - Fix divide by 0 in variance, from David Ahern. - Save parent pid in thread struct, from David Ahern. - Handle JITed code in shared memory, from Andi Kleen. - Fixes for 'perf diff', from Jiri Olsa. - Remove some unused struct members, from Jiri Olsa. - Add missing liblk.a dependency for python/perf.so, fix from Jiri Olsa. - Respect CROSS_COMPILE in liblk.a, from Rabin Vincent. - No need to do locking when adding hists in perf report, only 'top' needs that, from Namhyung Kim. - Fix alignment of symbol column in in the hists browser (top, report) when -v is given, from NAmhyung Kim. - Fix 'perf top' -E option behavior, from Namhyung Kim. - Fix bug in isupper() and islower(), from Sukadev Bhattiprolu. - Fix compile errors in bp_signal 'perf test', from Sukadev Bhattiprolu. ... and more things" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (102 commits) perf/x86: Disable PEBS-LL in intel_pmu_pebs_disable() perf/x86: Fix shared register mutual exclusion enforcement perf/x86/intel: Support full width counting x86: Add NMI duration tracepoints perf: Drop sample rate when sampling is too slow x86: Warn when NMI handlers take large amounts of time hw_breakpoint: Introduce "struct bp_cpuinfo" hw_breakpoint: Simplify *register_wide_hw_breakpoint() hw_breakpoint: Introduce cpumask_of_bp() hw_breakpoint: Simplify the "weight" usage in toggle_bp_slot() paths hw_breakpoint: Simplify list/idx mess in toggle_bp_slot() paths perf/x86/intel: Add mem-loads/stores support for Haswell perf/x86/intel: Support Haswell/v4 LBR format perf/x86/intel: Move NMI clearing to end of PMI handler perf/x86/intel: Add Haswell PEBS support perf/x86/intel: Add simple Haswell PMU support perf/x86/intel: Add Haswell PEBS record support perf/x86/intel: Fix sparse warning perf/x86/amd: AMD IOMMU Performance Counter PERF uncore PMU implementation perf/x86/amd: Add IOMMU Performance Counter resource management ...
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/lk/Makefile3
-rw-r--r--tools/perf/Documentation/perf-archive.txt2
-rw-r--r--tools/perf/Documentation/perf-report.txt4
-rw-r--r--tools/perf/Documentation/perf-top.txt4
-rw-r--r--tools/perf/Makefile630
-rw-r--r--tools/perf/builtin-diff.c19
-rw-r--r--tools/perf/builtin-kvm.c3
-rw-r--r--tools/perf/builtin-record.c2
-rw-r--r--tools/perf/builtin-report.c102
-rw-r--r--tools/perf/builtin-top.c74
-rw-r--r--tools/perf/config/Makefile477
-rw-r--r--tools/perf/tests/attr/base-record4
-rw-r--r--tools/perf/tests/attr/base-stat4
-rw-r--r--tools/perf/tests/attr/test-record-data5
-rw-r--r--tools/perf/tests/bp_signal.c6
-rw-r--r--tools/perf/tests/bp_signal_overflow.c6
-rw-r--r--tools/perf/tests/builtin-test.c2
-rw-r--r--tools/perf/tests/make138
-rw-r--r--tools/perf/ui/browsers/hists.c106
-rw-r--r--tools/perf/ui/gtk/hists.c13
-rw-r--r--tools/perf/ui/stdio/hist.c7
-rw-r--r--tools/perf/util/evlist.c2
-rw-r--r--tools/perf/util/evsel.c2
-rw-r--r--tools/perf/util/header.c2
-rw-r--r--tools/perf/util/header.h1
-rw-r--r--tools/perf/util/hist.c96
-rw-r--r--tools/perf/util/hist.h16
-rw-r--r--tools/perf/util/map.c1
-rw-r--r--tools/perf/util/session.h1
-rw-r--r--tools/perf/util/setup.py5
-rw-r--r--tools/perf/util/sort.c128
-rw-r--r--tools/perf/util/sort.h36
-rw-r--r--tools/perf/util/stat.c2
-rw-r--r--tools/perf/util/thread.c4
-rw-r--r--tools/perf/util/thread.h1
-rw-r--r--tools/perf/util/top.c23
-rw-r--r--tools/perf/util/top.h2
-rw-r--r--tools/perf/util/util.h4
38 files changed, 1164 insertions, 773 deletions
diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
index 926cbf3efc7f..2c5a19733357 100644
--- a/tools/lib/lk/Makefile
+++ b/tools/lib/lk/Makefile
@@ -1,5 +1,8 @@
1include ../../scripts/Makefile.include 1include ../../scripts/Makefile.include
2 2
3CC = $(CROSS_COMPILE)gcc
4AR = $(CROSS_COMPILE)ar
5
3# guard against environment variables 6# guard against environment variables
4LIB_H= 7LIB_H=
5LIB_OBJS= 8LIB_OBJS=
diff --git a/tools/perf/Documentation/perf-archive.txt b/tools/perf/Documentation/perf-archive.txt
index fae174dc7d01..5032a142853e 100644
--- a/tools/perf/Documentation/perf-archive.txt
+++ b/tools/perf/Documentation/perf-archive.txt
@@ -13,7 +13,7 @@ SYNOPSIS
13DESCRIPTION 13DESCRIPTION
14----------- 14-----------
15This command runs runs perf-buildid-list --with-hits, and collects the files 15This command runs runs perf-buildid-list --with-hits, and collects the files
16with the buildids found so that analisys of perf.data contents can be possible 16with the buildids found so that analysis of perf.data contents can be possible
17on another machine. 17on another machine.
18 18
19 19
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 7d5f4f38aa52..66dab7410c1d 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -210,6 +210,10 @@ OPTIONS
210 Demangle symbol names to human readable form. It's enabled by default, 210 Demangle symbol names to human readable form. It's enabled by default,
211 disable with --no-demangle. 211 disable with --no-demangle.
212 212
213--percent-limit::
214 Do not show entries which have an overhead under that percent.
215 (Default: 0).
216
213SEE ALSO 217SEE ALSO
214-------- 218--------
215linkperf:perf-stat[1], linkperf:perf-annotate[1] 219linkperf:perf-stat[1], linkperf:perf-annotate[1]
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index 9f1a2fe54757..7fdd1909e376 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -155,6 +155,10 @@ Default is to monitor all CPUS.
155 155
156 Default: fractal,0.5,callee. 156 Default: fractal,0.5,callee.
157 157
158--percent-limit::
159 Do not show entries which have an overhead under that percent.
160 (Default: 0).
161
158INTERACTIVE PROMPTING KEYS 162INTERACTIVE PROMPTING KEYS
159-------------------------- 163--------------------------
160 164
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index b0f164b133d9..203cb0eecff2 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -51,189 +51,63 @@ include config/utilities.mak
51# Define NO_BACKTRACE if you do not want stack backtrace debug feature 51# Define NO_BACKTRACE if you do not want stack backtrace debug feature
52# 52#
53# Define NO_LIBNUMA if you do not want numa perf benchmark 53# Define NO_LIBNUMA if you do not want numa perf benchmark
54#
55# Define NO_LIBAUDIT if you do not want libaudit support
56#
57# Define NO_LIBBIONIC if you do not want bionic support
54 58
55$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE 59ifeq ($(srctree),)
56 @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) 60srctree := $(patsubst %/,%,$(dir $(shell pwd)))
57 61srctree := $(patsubst %/,%,$(dir $(srctree)))
58uname_M := $(shell uname -m 2>/dev/null || echo not) 62#$(info Determined 'srctree' to be $(srctree))
59
60ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
61 -e s/arm.*/arm/ -e s/sa110/arm/ \
62 -e s/s390x/s390/ -e s/parisc64/parisc/ \
63 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
64 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
65NO_PERF_REGS := 1
66
67CC = $(CROSS_COMPILE)gcc
68AR = $(CROSS_COMPILE)ar
69
70# Additional ARCH settings for x86
71ifeq ($(ARCH),i386)
72 override ARCH := x86
73 NO_PERF_REGS := 0
74 LIBUNWIND_LIBS = -lunwind -lunwind-x86
75endif
76ifeq ($(ARCH),x86_64)
77 override ARCH := x86
78 IS_X86_64 := 0
79 ifeq (, $(findstring m32,$(EXTRA_CFLAGS)))
80 IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
81 endif
82 ifeq (${IS_X86_64}, 1)
83 RAW_ARCH := x86_64
84 ARCH_CFLAGS := -DARCH_X86_64
85 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
86 endif
87 NO_PERF_REGS := 0
88 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
89endif
90
91# Treat warnings as errors unless directed not to
92ifneq ($(WERROR),0)
93 CFLAGS_WERROR := -Werror
94endif
95
96ifeq ("$(origin DEBUG)", "command line")
97 PERF_DEBUG = $(DEBUG)
98endif
99ifndef PERF_DEBUG
100 CFLAGS_OPTIMIZE = -O6
101endif 63endif
102 64
103ifdef PARSER_DEBUG 65ifneq ($(objtree),)
104 PARSER_DEBUG_BISON := -t 66#$(info Determined 'objtree' to be $(objtree))
105 PARSER_DEBUG_FLEX := -d
106 PARSER_DEBUG_CFLAGS := -DPARSER_DEBUG
107endif 67endif
108 68
109ifdef NO_NEWT 69ifneq ($(OUTPUT),)
110 NO_SLANG=1 70#$(info Determined 'OUTPUT' to be $(OUTPUT))
111endif 71endif
112 72
113CFLAGS = -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) $(PARSER_DEBUG_CFLAGS) 73$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
114EXTLIBS = -lpthread -lrt -lelf -lm 74 @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
115ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
116ALL_LDFLAGS = $(LDFLAGS)
117STRIP ?= strip
118
119# Among the variables below, these:
120# perfexecdir
121# template_dir
122# mandir
123# infodir
124# htmldir
125# ETC_PERFCONFIG (but not sysconfdir)
126# can be specified as a relative path some/where/else;
127# this is interpreted as relative to $(prefix) and "perf" at
128# runtime figures out where they are based on the path to the executable.
129# This can help installing the suite in a relocatable way.
130
131# Make the path relative to DESTDIR, not to prefix
132ifndef DESTDIR
133prefix = $(HOME)
134endif
135bindir_relative = bin
136bindir = $(prefix)/$(bindir_relative)
137mandir = share/man
138infodir = share/info
139perfexecdir = libexec/perf-core
140sharedir = $(prefix)/share
141template_dir = share/perf-core/templates
142htmldir = share/doc/perf-doc
143ifeq ($(prefix),/usr)
144sysconfdir = /etc
145ETC_PERFCONFIG = $(sysconfdir)/perfconfig
146else
147sysconfdir = $(prefix)/etc
148ETC_PERFCONFIG = etc/perfconfig
149endif
150lib = lib
151 75
152export prefix bindir sharedir sysconfdir 76CC = $(CROSS_COMPILE)gcc
77AR = $(CROSS_COMPILE)ar
153 78
154RM = rm -f 79RM = rm -f
155MKDIR = mkdir 80MKDIR = mkdir
156FIND = find 81FIND = find
157INSTALL = install 82INSTALL = install
158FLEX = flex 83FLEX = flex
159BISON= bison 84BISON = bison
160 85STRIP = strip
161# sparse is architecture-neutral, which means that we need to tell it
162# explicitly what architecture to check for. Fix this up for yours..
163SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
164
165ifneq ($(MAKECMDGOALS),clean)
166ifneq ($(MAKECMDGOALS),tags)
167-include config/feature-tests.mak
168
169ifeq ($(call get-executable,$(FLEX)),)
170 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
171endif
172
173ifeq ($(call get-executable,$(BISON)),)
174 dummy := $(error Error: $(BISON) is missing on this system, please install it)
175endif
176 86
177ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y) 87LK_DIR = $(srctree)/tools/lib/lk/
178 CFLAGS := $(CFLAGS) -fstack-protector-all 88TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
179endif
180 89
181ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wstack-protector,-Wstack-protector),y) 90# include config/Makefile by default and rule out
182 CFLAGS := $(CFLAGS) -Wstack-protector 91# non-config cases
183endif 92config := 1
184 93
185ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-Wvolatile-register-var),y) 94NON_CONFIG_TARGETS := clean TAGS tags cscope help
186 CFLAGS := $(CFLAGS) -Wvolatile-register-var
187endif
188 95
189ifndef PERF_DEBUG 96ifdef MAKECMDGOALS
190 ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y) 97ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
191 CFLAGS := $(CFLAGS) -D_FORTIFY_SOURCE=2 98 config := 0
192 endif
193endif 99endif
194
195### --- END CONFIGURATION SECTION ---
196
197ifeq ($(srctree),)
198srctree := $(patsubst %/,%,$(dir $(shell pwd)))
199srctree := $(patsubst %/,%,$(dir $(srctree)))
200#$(info Determined 'srctree' to be $(srctree))
201endif 100endif
202 101
203ifneq ($(objtree),) 102ifeq ($(config),1)
204#$(info Determined 'objtree' to be $(objtree)) 103include config/Makefile
205endif 104endif
206 105
207ifneq ($(OUTPUT),) 106export prefix bindir sharedir sysconfdir
208#$(info Determined 'OUTPUT' to be $(OUTPUT))
209endif
210 107
211BASIC_CFLAGS = \ 108# sparse is architecture-neutral, which means that we need to tell it
212 -Iutil/include \ 109# explicitly what architecture to check for. Fix this up for yours..
213 -Iarch/$(ARCH)/include \ 110SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
214 $(if $(objtree),-I$(objtree)/arch/$(ARCH)/include/generated/uapi) \
215 -I$(srctree)/arch/$(ARCH)/include/uapi \
216 -I$(srctree)/arch/$(ARCH)/include \
217 $(if $(objtree),-I$(objtree)/include/generated/uapi) \
218 -I$(srctree)/include/uapi \
219 -I$(srctree)/include \
220 -I$(OUTPUT)util \
221 -Iutil \
222 -I. \
223 -I$(TRACE_EVENT_DIR) \
224 -I../lib/ \
225 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
226
227BASIC_LDFLAGS =
228
229ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
230 BIONIC := 1
231 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
232 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
233 BASIC_CFLAGS += -I.
234endif
235endif # MAKECMDGOALS != tags
236endif # MAKECMDGOALS != clean
237 111
238# Guard against environment variables 112# Guard against environment variables
239BUILTIN_OBJS = 113BUILTIN_OBJS =
@@ -247,20 +121,17 @@ SCRIPT_SH += perf-archive.sh
247grep-libs = $(filter -l%,$(1)) 121grep-libs = $(filter -l%,$(1))
248strip-libs = $(filter-out -l%,$(1)) 122strip-libs = $(filter-out -l%,$(1))
249 123
250LK_DIR = ../lib/lk/
251TRACE_EVENT_DIR = ../lib/traceevent/
252
253LK_PATH=$(LK_DIR) 124LK_PATH=$(LK_DIR)
254 125
255ifneq ($(OUTPUT),) 126ifneq ($(OUTPUT),)
256 TE_PATH=$(OUTPUT) 127 TE_PATH=$(OUTPUT)
257ifneq ($(subdir),) 128ifneq ($(subdir),)
258 LK_PATH=$(OUTPUT)$(LK_DIR) 129 LK_PATH=$(OUTPUT)$(LK_DIR)
259else 130else
260 LK_PATH=$(OUTPUT) 131 LK_PATH=$(OUTPUT)
261endif 132endif
262else 133else
263 TE_PATH=$(TRACE_EVENT_DIR) 134 TE_PATH=$(TRACE_EVENT_DIR)
264endif 135endif
265 136
266LIBTRACEEVENT = $(TE_PATH)libtraceevent.a 137LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -278,10 +149,10 @@ export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP
278python-clean := rm -rf $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so 149python-clean := rm -rf $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so
279 150
280PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources) 151PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
281PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) 152PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) $(LIBLK)
282 153
283$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) 154$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
284 $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ 155 $(QUIET_GEN)CFLAGS='$(CFLAGS)' $(PYTHON_WORD) util/setup.py \
285 --quiet build_ext; \ 156 --quiet build_ext; \
286 mkdir -p $(OUTPUT)python && \ 157 mkdir -p $(OUTPUT)python && \
287 cp $(PYTHON_EXTBUILD_LIB)perf.so $(OUTPUT)python/ 158 cp $(PYTHON_EXTBUILD_LIB)perf.so $(OUTPUT)python/
@@ -296,8 +167,6 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
296# 167#
297PROGRAMS += $(OUTPUT)perf 168PROGRAMS += $(OUTPUT)perf
298 169
299LANG_BINDINGS =
300
301# what 'all' will build and 'install' will install, in perfexecdir 170# what 'all' will build and 'install' will install, in perfexecdir
302ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) 171ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
303 172
@@ -306,10 +175,10 @@ OTHER_PROGRAMS = $(OUTPUT)perf
306 175
307# Set paths to tools early so that they can be used for version tests. 176# Set paths to tools early so that they can be used for version tests.
308ifndef SHELL_PATH 177ifndef SHELL_PATH
309 SHELL_PATH = /bin/sh 178 SHELL_PATH = /bin/sh
310endif 179endif
311ifndef PERL_PATH 180ifndef PERL_PATH
312 PERL_PATH = /usr/bin/perl 181 PERL_PATH = /usr/bin/perl
313endif 182endif
314 183
315export PERL_PATH 184export PERL_PATH
@@ -557,79 +426,14 @@ BUILTIN_OBJS += $(OUTPUT)builtin-mem.o
557 426
558PERFLIBS = $(LIB_FILE) $(LIBLK) $(LIBTRACEEVENT) 427PERFLIBS = $(LIB_FILE) $(LIBLK) $(LIBTRACEEVENT)
559 428
560#
561# Platform specific tweaks
562#
563ifneq ($(MAKECMDGOALS),clean)
564ifneq ($(MAKECMDGOALS),tags)
565
566# We choose to avoid "if .. else if .. else .. endif endif" 429# We choose to avoid "if .. else if .. else .. endif endif"
567# because maintaining the nesting to match is a pain. If 430# because maintaining the nesting to match is a pain. If
568# we had "elif" things would have been much nicer... 431# we had "elif" things would have been much nicer...
569 432
570ifdef NO_LIBELF
571 NO_DWARF := 1
572 NO_DEMANGLE := 1
573 NO_LIBUNWIND := 1
574else
575FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
576ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF),libelf),y)
577 FLAGS_GLIBC=$(ALL_CFLAGS) $(ALL_LDFLAGS)
578 ifeq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC),glibc),y)
579 LIBC_SUPPORT := 1
580 endif
581 ifeq ($(BIONIC),1)
582 LIBC_SUPPORT := 1
583 endif
584 ifeq ($(LIBC_SUPPORT),1)
585 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
586
587 NO_LIBELF := 1
588 NO_DWARF := 1
589 NO_DEMANGLE := 1
590 else
591 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
592 endif
593else
594 # for linking with debug library, run like:
595 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
596 ifdef LIBDW_DIR
597 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
598 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
599 endif
600
601 FLAGS_DWARF=$(ALL_CFLAGS) $(LIBDW_CFLAGS) -ldw -lelf $(LIBDW_LDFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
602 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF),libdw),y)
603 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
604 NO_DWARF := 1
605 endif # Dwarf support
606endif # SOURCE_LIBELF
607endif # NO_LIBELF
608
609# There's only x86 (both 32 and 64) support for CFI unwind so far
610ifneq ($(ARCH),x86)
611 NO_LIBUNWIND := 1
612endif
613
614ifndef NO_LIBUNWIND
615# for linking with debug library, run like:
616# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
617ifdef LIBUNWIND_DIR
618 LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
619 LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
620endif
621
622FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(ALL_CFLAGS) $(LIBUNWIND_LDFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
623ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND),libunwind),y)
624 msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
625 NO_LIBUNWIND := 1
626endif # Libunwind support
627endif # NO_LIBUNWIND
628
629-include arch/$(ARCH)/Makefile 433-include arch/$(ARCH)/Makefile
630 434
631ifneq ($(OUTPUT),) 435ifneq ($(OUTPUT),)
632 BASIC_CFLAGS += -I$(OUTPUT) 436 CFLAGS += -I$(OUTPUT)
633endif 437endif
634 438
635ifdef NO_LIBELF 439ifdef NO_LIBELF
@@ -647,281 +451,74 @@ BUILTIN_OBJS := $(filter-out $(OUTPUT)builtin-probe.o,$(BUILTIN_OBJS))
647LIB_OBJS += $(OUTPUT)util/symbol-minimal.o 451LIB_OBJS += $(OUTPUT)util/symbol-minimal.o
648 452
649else # NO_LIBELF 453else # NO_LIBELF
650BASIC_CFLAGS += -DLIBELF_SUPPORT
651
652FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
653ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
654 BASIC_CFLAGS += -DLIBELF_MMAP
655endif
656
657ifndef NO_DWARF 454ifndef NO_DWARF
658ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined) 455 LIB_OBJS += $(OUTPUT)util/probe-finder.o
659 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled); 456 LIB_OBJS += $(OUTPUT)util/dwarf-aux.o
660else
661 BASIC_CFLAGS := -DDWARF_SUPPORT $(LIBDW_CFLAGS) $(BASIC_CFLAGS)
662 BASIC_LDFLAGS := $(LIBDW_LDFLAGS) $(BASIC_LDFLAGS)
663 EXTLIBS += -lelf -ldw
664 LIB_OBJS += $(OUTPUT)util/probe-finder.o
665 LIB_OBJS += $(OUTPUT)util/dwarf-aux.o
666endif # PERF_HAVE_DWARF_REGS
667endif # NO_DWARF 457endif # NO_DWARF
668endif # NO_LIBELF 458endif # NO_LIBELF
669 459
670ifndef NO_LIBUNWIND 460ifndef NO_LIBUNWIND
671 BASIC_CFLAGS += -DLIBUNWIND_SUPPORT 461 LIB_OBJS += $(OUTPUT)util/unwind.o
672 EXTLIBS += $(LIBUNWIND_LIBS)
673 BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS)
674 BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS)
675 LIB_OBJS += $(OUTPUT)util/unwind.o
676endif 462endif
677 463
678ifndef NO_LIBAUDIT 464ifndef NO_LIBAUDIT
679 FLAGS_LIBAUDIT = $(ALL_CFLAGS) $(ALL_LDFLAGS) -laudit 465 BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
680 ifneq ($(call try-cc,$(SOURCE_LIBAUDIT),$(FLAGS_LIBAUDIT),libaudit),y)
681 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
682 else
683 BASIC_CFLAGS += -DLIBAUDIT_SUPPORT
684 BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
685 EXTLIBS += -laudit
686 endif
687endif 466endif
688 467
689ifndef NO_SLANG 468ifndef NO_SLANG
690 FLAGS_SLANG=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -I/usr/include/slang -lslang 469 LIB_OBJS += $(OUTPUT)ui/browser.o
691 ifneq ($(call try-cc,$(SOURCE_SLANG),$(FLAGS_SLANG),libslang),y) 470 LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o
692 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev); 471 LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
693 else 472 LIB_OBJS += $(OUTPUT)ui/browsers/map.o
694 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 473 LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
695 BASIC_CFLAGS += -I/usr/include/slang 474 LIB_OBJS += $(OUTPUT)ui/tui/setup.o
696 BASIC_CFLAGS += -DSLANG_SUPPORT 475 LIB_OBJS += $(OUTPUT)ui/tui/util.o
697 EXTLIBS += -lslang 476 LIB_OBJS += $(OUTPUT)ui/tui/helpline.o
698 LIB_OBJS += $(OUTPUT)ui/browser.o 477 LIB_OBJS += $(OUTPUT)ui/tui/progress.o
699 LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o 478 LIB_H += ui/browser.h
700 LIB_OBJS += $(OUTPUT)ui/browsers/hists.o 479 LIB_H += ui/browsers/map.h
701 LIB_OBJS += $(OUTPUT)ui/browsers/map.o 480 LIB_H += ui/keysyms.h
702 LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o 481 LIB_H += ui/libslang.h
703 LIB_OBJS += $(OUTPUT)ui/tui/setup.o
704 LIB_OBJS += $(OUTPUT)ui/tui/util.o
705 LIB_OBJS += $(OUTPUT)ui/tui/helpline.o
706 LIB_OBJS += $(OUTPUT)ui/tui/progress.o
707 LIB_H += ui/browser.h
708 LIB_H += ui/browsers/map.h
709 LIB_H += ui/keysyms.h
710 LIB_H += ui/libslang.h
711 endif
712endif 482endif
713 483
714ifndef NO_GTK2 484ifndef NO_GTK2
715 FLAGS_GTK2=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null) 485 LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
716 ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2),gtk2),y) 486 LIB_OBJS += $(OUTPUT)ui/gtk/hists.o
717 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev); 487 LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
718 else 488 LIB_OBJS += $(OUTPUT)ui/gtk/util.o
719 ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2),-DHAVE_GTK_INFO_BAR),y) 489 LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
720 BASIC_CFLAGS += -DHAVE_GTK_INFO_BAR 490 LIB_OBJS += $(OUTPUT)ui/gtk/progress.o
721 endif 491 LIB_OBJS += $(OUTPUT)ui/gtk/annotate.o
722 BASIC_CFLAGS += -DGTK2_SUPPORT
723 BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
724 EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
725 LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
726 LIB_OBJS += $(OUTPUT)ui/gtk/hists.o
727 LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
728 LIB_OBJS += $(OUTPUT)ui/gtk/util.o
729 LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
730 LIB_OBJS += $(OUTPUT)ui/gtk/progress.o
731 LIB_OBJS += $(OUTPUT)ui/gtk/annotate.o
732 endif
733endif 492endif
734 493
735ifdef NO_LIBPERL 494ifndef NO_LIBPERL
736 BASIC_CFLAGS += -DNO_LIBPERL 495 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
737else 496 LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
738 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
739 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
740 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
741 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
742 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
743
744 ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED),perl),y)
745 BASIC_CFLAGS += -DNO_LIBPERL
746 else
747 ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
748 EXTLIBS += $(PERL_EMBED_LIBADD)
749 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
750 LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
751 endif
752endif 497endif
753 498
754disable-python = $(eval $(disable-python_code)) 499ifndef NO_LIBPYTHON
755define disable-python_code 500 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
756 BASIC_CFLAGS += -DNO_LIBPYTHON 501 LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
757 $(if $(1),$(warning No $(1) was found))
758 $(warning Python support will not be built)
759endef
760
761override PYTHON := \
762 $(call get-executable-or-default,PYTHON,python)
763
764ifndef PYTHON
765 $(call disable-python,python interpreter)
766else
767
768 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
769
770 ifdef NO_LIBPYTHON
771 $(call disable-python)
772 else
773
774 override PYTHON_CONFIG := \
775 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
776
777 ifndef PYTHON_CONFIG
778 $(call disable-python,python-config tool)
779 else
780
781 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
782
783 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
784 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
785 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
786 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
787 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
788
789 ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED),python),y)
790 $(call disable-python,Python.h (for Python 2.x))
791 else
792
793 ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED),python version),y)
794 $(warning Python 3 is not yet supported; please set)
795 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
796 $(warning If you also have Python 2 installed, then)
797 $(warning try something like:)
798 $(warning $(and ,))
799 $(warning $(and ,) make PYTHON=python2)
800 $(warning $(and ,))
801 $(warning Otherwise, disable Python support entirely:)
802 $(warning $(and ,))
803 $(warning $(and ,) make NO_LIBPYTHON=1)
804 $(warning $(and ,))
805 $(error $(and ,))
806 else
807 ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
808 EXTLIBS += $(PYTHON_EMBED_LIBADD)
809 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
810 LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
811 LANG_BINDINGS += $(OUTPUT)python/perf.so
812 endif
813
814 endif
815 endif
816 endif
817endif
818
819ifdef NO_DEMANGLE
820 BASIC_CFLAGS += -DNO_DEMANGLE
821else
822 ifdef HAVE_CPLUS_DEMANGLE
823 EXTLIBS += -liberty
824 BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
825 else
826 FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
827 has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
828 ifeq ($(has_bfd),y)
829 EXTLIBS += -lbfd
830 else
831 FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
832 has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
833 ifeq ($(has_bfd_iberty),y)
834 EXTLIBS += -lbfd -liberty
835 else
836 FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
837 has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
838 ifeq ($(has_bfd_iberty_z),y)
839 EXTLIBS += -lbfd -liberty -lz
840 else
841 FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty
842 has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
843 ifeq ($(has_cplus_demangle),y)
844 EXTLIBS += -liberty
845 BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
846 else
847 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
848 BASIC_CFLAGS += -DNO_DEMANGLE
849 endif
850 endif
851 endif
852 endif
853 endif
854endif 502endif
855 503
856ifeq ($(NO_PERF_REGS),0) 504ifeq ($(NO_PERF_REGS),0)
857 ifeq ($(ARCH),x86) 505 ifeq ($(ARCH),x86)
858 LIB_H += arch/x86/include/perf_regs.h 506 LIB_H += arch/x86/include/perf_regs.h
859 endif 507 endif
860 BASIC_CFLAGS += -DHAVE_PERF_REGS
861endif
862
863ifndef NO_STRLCPY
864 ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY),y)
865 BASIC_CFLAGS += -DHAVE_STRLCPY
866 endif
867endif
868
869ifndef NO_ON_EXIT
870 ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT),y)
871 BASIC_CFLAGS += -DHAVE_ON_EXIT
872 endif
873endif
874
875ifndef NO_BACKTRACE
876 ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DBACKTRACE_SUPPORT),y)
877 BASIC_CFLAGS += -DBACKTRACE_SUPPORT
878 endif
879endif 508endif
880 509
881ifndef NO_LIBNUMA 510ifndef NO_LIBNUMA
882 FLAGS_LIBNUMA = $(ALL_CFLAGS) $(ALL_LDFLAGS) -lnuma 511 BUILTIN_OBJS += $(OUTPUT)bench/numa.o
883 ifneq ($(call try-cc,$(SOURCE_LIBNUMA),$(FLAGS_LIBNUMA),libnuma),y)
884 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
885 else
886 BASIC_CFLAGS += -DLIBNUMA_SUPPORT
887 BUILTIN_OBJS += $(OUTPUT)bench/numa.o
888 EXTLIBS += -lnuma
889 endif
890endif 512endif
891 513
892ifdef ASCIIDOC8 514ifdef ASCIIDOC8
893 export ASCIIDOC8 515 export ASCIIDOC8
894endif 516endif
895 517
896endif # MAKECMDGOALS != tags
897endif # MAKECMDGOALS != clean
898
899# Shell quote (do not use $(call) to accommodate ancient setups);
900
901ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
902
903DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
904bindir_SQ = $(subst ','\'',$(bindir))
905bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
906mandir_SQ = $(subst ','\'',$(mandir))
907infodir_SQ = $(subst ','\'',$(infodir))
908perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
909template_dir_SQ = $(subst ','\'',$(template_dir))
910htmldir_SQ = $(subst ','\'',$(htmldir))
911prefix_SQ = $(subst ','\'',$(prefix))
912sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
913
914SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
915
916LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group 518LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
917 519
918ALL_CFLAGS += $(BASIC_CFLAGS)
919ALL_CFLAGS += $(ARCH_CFLAGS)
920ALL_LDFLAGS += $(BASIC_LDFLAGS)
921
922export INSTALL SHELL_PATH 520export INSTALL SHELL_PATH
923 521
924
925### Build rules 522### Build rules
926 523
927SHELL = $(SHELL_PATH) 524SHELL = $(SHELL_PATH)
@@ -939,20 +536,20 @@ strip: $(PROGRAMS) $(OUTPUT)perf
939$(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 536$(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
940 $(QUIET_CC)$(CC) -include $(OUTPUT)PERF-VERSION-FILE \ 537 $(QUIET_CC)$(CC) -include $(OUTPUT)PERF-VERSION-FILE \
941 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ 538 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
942 $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@ 539 $(CFLAGS) -c $(filter %.c,$^) -o $@
943 540
944$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) 541$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
945 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \ 542 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(OUTPUT)perf.o \
946 $(BUILTIN_OBJS) $(LIBS) -o $@ 543 $(BUILTIN_OBJS) $(LIBS) -o $@
947 544
948$(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 545$(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
949 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 546 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
950 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ 547 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
951 '-DPERF_MAN_PATH="$(mandir_SQ)"' \ 548 '-DPERF_MAN_PATH="$(mandir_SQ)"' \
952 '-DPERF_INFO_PATH="$(infodir_SQ)"' $< 549 '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
953 550
954$(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 551$(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
955 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 552 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
956 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ 553 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
957 '-DPERF_MAN_PATH="$(mandir_SQ)"' \ 554 '-DPERF_MAN_PATH="$(mandir_SQ)"' \
958 '-DPERF_INFO_PATH="$(infodir_SQ)"' $< 555 '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
@@ -977,77 +574,77 @@ $(OUTPUT)perf.o perf.spec \
977# over the general rule for .o 574# over the general rule for .o
978 575
979$(OUTPUT)util/%-flex.o: $(OUTPUT)util/%-flex.c $(OUTPUT)PERF-CFLAGS 576$(OUTPUT)util/%-flex.o: $(OUTPUT)util/%-flex.c $(OUTPUT)PERF-CFLAGS
980 $(QUIET_CC)$(CC) -o $@ -c -Iutil/ $(ALL_CFLAGS) -w $< 577 $(QUIET_CC)$(CC) -o $@ -c -Iutil/ $(CFLAGS) -w $<
981 578
982$(OUTPUT)util/%-bison.o: $(OUTPUT)util/%-bison.c $(OUTPUT)PERF-CFLAGS 579$(OUTPUT)util/%-bison.o: $(OUTPUT)util/%-bison.c $(OUTPUT)PERF-CFLAGS
983 $(QUIET_CC)$(CC) -o $@ -c -Iutil/ $(ALL_CFLAGS) -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w $< 580 $(QUIET_CC)$(CC) -o $@ -c -Iutil/ $(CFLAGS) -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w $<
984 581
985$(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS 582$(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
986 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< 583 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
987$(OUTPUT)%.i: %.c $(OUTPUT)PERF-CFLAGS 584$(OUTPUT)%.i: %.c $(OUTPUT)PERF-CFLAGS
988 $(QUIET_CC)$(CC) -o $@ -E $(ALL_CFLAGS) $< 585 $(QUIET_CC)$(CC) -o $@ -E $(CFLAGS) $<
989$(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS 586$(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
990 $(QUIET_CC)$(CC) -o $@ -S $(ALL_CFLAGS) $< 587 $(QUIET_CC)$(CC) -o $@ -S $(CFLAGS) $<
991$(OUTPUT)%.o: %.S 588$(OUTPUT)%.o: %.S
992 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< 589 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
993$(OUTPUT)%.s: %.S 590$(OUTPUT)%.s: %.S
994 $(QUIET_CC)$(CC) -o $@ -E $(ALL_CFLAGS) $< 591 $(QUIET_CC)$(CC) -o $@ -E $(CFLAGS) $<
995 592
996$(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS 593$(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
997 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 594 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
998 '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \ 595 '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \
999 '-DPREFIX="$(prefix_SQ)"' \ 596 '-DPREFIX="$(prefix_SQ)"' \
1000 $< 597 $<
1001 598
1002$(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS 599$(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS
1003 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 600 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
1004 '-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \ 601 '-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \
1005 $< 602 $<
1006 603
1007$(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS 604$(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS
1008 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 605 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
1009 -DPYTHONPATH='"$(OUTPUT)python"' \ 606 -DPYTHONPATH='"$(OUTPUT)python"' \
1010 -DPYTHON='"$(PYTHON_WORD)"' \ 607 -DPYTHON='"$(PYTHON_WORD)"' \
1011 $< 608 $<
1012 609
1013$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS 610$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
1014 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 611 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
1015 612
1016$(OUTPUT)ui/browser.o: ui/browser.c $(OUTPUT)PERF-CFLAGS 613$(OUTPUT)ui/browser.o: ui/browser.c $(OUTPUT)PERF-CFLAGS
1017 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 614 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $<
1018 615
1019$(OUTPUT)ui/browsers/annotate.o: ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS 616$(OUTPUT)ui/browsers/annotate.o: ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS
1020 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 617 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $<
1021 618
1022$(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS 619$(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS
1023 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 620 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $<
1024 621
1025$(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS 622$(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
1026 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 623 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $<
1027 624
1028$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS 625$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS
1029 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 626 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $<
1030 627
1031$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS 628$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
1032 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 629 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
1033 630
1034$(OUTPUT)util/parse-events.o: util/parse-events.c $(OUTPUT)PERF-CFLAGS 631$(OUTPUT)util/parse-events.o: util/parse-events.c $(OUTPUT)PERF-CFLAGS
1035 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-redundant-decls $< 632 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-redundant-decls $<
1036 633
1037$(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS 634$(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
1038 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< 635 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
1039 636
1040$(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS 637$(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
1041 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< 638 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
1042 639
1043$(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS 640$(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS
1044 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< 641 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
1045 642
1046$(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS 643$(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
1047 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< 644 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
1048 645
1049$(OUTPUT)perf-%: %.o $(PERFLIBS) 646$(OUTPUT)perf-%: %.o $(PERFLIBS)
1050 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) 647 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)
1051 648
1052$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) 649$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
1053$(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h) 650$(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
@@ -1134,7 +731,7 @@ cscope:
1134 $(FIND) . -name '*.[hcS]' -print | xargs cscope -b 731 $(FIND) . -name '*.[hcS]' -print | xargs cscope -b
1135 732
1136### Detect prefix changes 733### Detect prefix changes
1137TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ 734TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):\
1138 $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ) 735 $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
1139 736
1140$(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS 737$(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS
@@ -1155,7 +752,7 @@ check: $(OUTPUT)common-cmds.h
1155 then \ 752 then \
1156 for i in *.c */*.c; \ 753 for i in *.c */*.c; \
1157 do \ 754 do \
1158 sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; \ 755 sparse $(CFLAGS) $(SPARSE_FLAGS) $$i || exit; \
1159 done; \ 756 done; \
1160 else \ 757 else \
1161 exit 1; \ 758 exit 1; \
@@ -1163,13 +760,6 @@ check: $(OUTPUT)common-cmds.h
1163 760
1164### Installation rules 761### Installation rules
1165 762
1166ifneq ($(filter /%,$(firstword $(perfexecdir))),)
1167perfexec_instdir = $(perfexecdir)
1168else
1169perfexec_instdir = $(prefix)/$(perfexecdir)
1170endif
1171perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
1172
1173install-bin: all 763install-bin: all
1174 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' 764 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
1175 $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)' 765 $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 2d0462d89a97..da8f8eb383a0 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -323,13 +323,20 @@ static void hists__baseline_only(struct hists *hists)
323 323
324static void hists__precompute(struct hists *hists) 324static void hists__precompute(struct hists *hists)
325{ 325{
326 struct rb_node *next = rb_first(&hists->entries); 326 struct rb_root *root;
327 struct rb_node *next;
328
329 if (sort__need_collapse)
330 root = &hists->entries_collapsed;
331 else
332 root = hists->entries_in;
327 333
334 next = rb_first(root);
328 while (next != NULL) { 335 while (next != NULL) {
329 struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node); 336 struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in);
330 struct hist_entry *pair = hist_entry__next_pair(he); 337 struct hist_entry *pair = hist_entry__next_pair(he);
331 338
332 next = rb_next(&he->rb_node); 339 next = rb_next(&he->rb_node_in);
333 if (!pair) 340 if (!pair)
334 continue; 341 continue;
335 342
@@ -457,7 +464,7 @@ static void hists__process(struct hists *old, struct hists *new)
457 hists__output_resort(new); 464 hists__output_resort(new);
458 } 465 }
459 466
460 hists__fprintf(new, true, 0, 0, stdout); 467 hists__fprintf(new, true, 0, 0, 0, stdout);
461} 468}
462 469
463static int __cmd_diff(void) 470static int __cmd_diff(void)
@@ -611,9 +618,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
611 618
612 setup_pager(); 619 setup_pager();
613 620
614 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso", NULL); 621 sort__setup_elide(NULL);
615 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", NULL);
616 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", NULL);
617 622
618 return __cmd_diff(); 623 return __cmd_diff();
619} 624}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 533501e2b07c..24b78aecc928 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -328,6 +328,7 @@ static int kvm_events_hash_fn(u64 key)
328static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) 328static bool kvm_event_expand(struct kvm_event *event, int vcpu_id)
329{ 329{
330 int old_max_vcpu = event->max_vcpu; 330 int old_max_vcpu = event->max_vcpu;
331 void *prev;
331 332
332 if (vcpu_id < event->max_vcpu) 333 if (vcpu_id < event->max_vcpu)
333 return true; 334 return true;
@@ -335,9 +336,11 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id)
335 while (event->max_vcpu <= vcpu_id) 336 while (event->max_vcpu <= vcpu_id)
336 event->max_vcpu += DEFAULT_VCPU_NUM; 337 event->max_vcpu += DEFAULT_VCPU_NUM;
337 338
339 prev = event->vcpu;
338 event->vcpu = realloc(event->vcpu, 340 event->vcpu = realloc(event->vcpu,
339 event->max_vcpu * sizeof(*event->vcpu)); 341 event->max_vcpu * sizeof(*event->vcpu));
340 if (!event->vcpu) { 342 if (!event->vcpu) {
343 free(prev);
341 pr_err("Not enough memory\n"); 344 pr_err("Not enough memory\n");
342 return false; 345 return false;
343 } 346 }
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index cdf58ecc04b1..fff985cf3852 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -198,7 +198,6 @@ static void perf_record__sig_exit(int exit_status __maybe_unused, void *arg)
198 return; 198 return;
199 199
200 signal(signr, SIG_DFL); 200 signal(signr, SIG_DFL);
201 kill(getpid(), signr);
202} 201}
203 202
204static bool perf_evlist__equal(struct perf_evlist *evlist, 203static bool perf_evlist__equal(struct perf_evlist *evlist,
@@ -404,6 +403,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
404 signal(SIGCHLD, sig_handler); 403 signal(SIGCHLD, sig_handler);
405 signal(SIGINT, sig_handler); 404 signal(SIGINT, sig_handler);
406 signal(SIGUSR1, sig_handler); 405 signal(SIGUSR1, sig_handler);
406 signal(SIGTERM, sig_handler);
407 407
408 if (!output_name) { 408 if (!output_name) {
409 if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode)) 409 if (!fstat(STDOUT_FILENO, &st) && S_ISFIFO(st.st_mode))
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index bd0ca81eeaca..ca98d34cd58b 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -52,6 +52,7 @@ struct perf_report {
52 symbol_filter_t annotate_init; 52 symbol_filter_t annotate_init;
53 const char *cpu_list; 53 const char *cpu_list;
54 const char *symbol_filter_str; 54 const char *symbol_filter_str;
55 float min_percent;
55 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 56 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
56}; 57};
57 58
@@ -61,6 +62,11 @@ static int perf_report_config(const char *var, const char *value, void *cb)
61 symbol_conf.event_group = perf_config_bool(var, value); 62 symbol_conf.event_group = perf_config_bool(var, value);
62 return 0; 63 return 0;
63 } 64 }
65 if (!strcmp(var, "report.percent-limit")) {
66 struct perf_report *rep = cb;
67 rep->min_percent = strtof(value, NULL);
68 return 0;
69 }
64 70
65 return perf_default_config(var, value, cb); 71 return perf_default_config(var, value, cb);
66} 72}
@@ -187,6 +193,9 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
187 for (i = 0; i < sample->branch_stack->nr; i++) { 193 for (i = 0; i < sample->branch_stack->nr; i++) {
188 if (rep->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) 194 if (rep->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym))
189 continue; 195 continue;
196
197 err = -ENOMEM;
198
190 /* 199 /*
191 * The report shows the percentage of total branches captured 200 * The report shows the percentage of total branches captured
192 * and not events sampled. Thus we use a pseudo period of 1. 201 * and not events sampled. Thus we use a pseudo period of 1.
@@ -195,7 +204,6 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
195 &bi[i], 1, 1); 204 &bi[i], 1, 1);
196 if (he) { 205 if (he) {
197 struct annotation *notes; 206 struct annotation *notes;
198 err = -ENOMEM;
199 bx = he->branch_info; 207 bx = he->branch_info;
200 if (bx->from.sym && use_browser == 1 && sort__has_sym) { 208 if (bx->from.sym && use_browser == 1 && sort__has_sym) {
201 notes = symbol__annotation(bx->from.sym); 209 notes = symbol__annotation(bx->from.sym);
@@ -226,11 +234,12 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
226 } 234 }
227 evsel->hists.stats.total_period += 1; 235 evsel->hists.stats.total_period += 1;
228 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 236 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
229 err = 0;
230 } else 237 } else
231 return -ENOMEM; 238 goto out;
232 } 239 }
240 err = 0;
233out: 241out:
242 free(bi);
234 return err; 243 return err;
235} 244}
236 245
@@ -294,6 +303,7 @@ static int process_sample_event(struct perf_tool *tool,
294{ 303{
295 struct perf_report *rep = container_of(tool, struct perf_report, tool); 304 struct perf_report *rep = container_of(tool, struct perf_report, tool);
296 struct addr_location al; 305 struct addr_location al;
306 int ret;
297 307
298 if (perf_event__preprocess_sample(event, machine, &al, sample, 308 if (perf_event__preprocess_sample(event, machine, &al, sample,
299 rep->annotate_init) < 0) { 309 rep->annotate_init) < 0) {
@@ -308,28 +318,25 @@ static int process_sample_event(struct perf_tool *tool,
308 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) 318 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
309 return 0; 319 return 0;
310 320
311 if (sort__branch_mode == 1) { 321 if (sort__mode == SORT_MODE__BRANCH) {
312 if (perf_report__add_branch_hist_entry(tool, &al, sample, 322 ret = perf_report__add_branch_hist_entry(tool, &al, sample,
313 evsel, machine)) { 323 evsel, machine);
324 if (ret < 0)
314 pr_debug("problem adding lbr entry, skipping event\n"); 325 pr_debug("problem adding lbr entry, skipping event\n");
315 return -1;
316 }
317 } else if (rep->mem_mode == 1) { 326 } else if (rep->mem_mode == 1) {
318 if (perf_report__add_mem_hist_entry(tool, &al, sample, 327 ret = perf_report__add_mem_hist_entry(tool, &al, sample,
319 evsel, machine, event)) { 328 evsel, machine, event);
329 if (ret < 0)
320 pr_debug("problem adding mem entry, skipping event\n"); 330 pr_debug("problem adding mem entry, skipping event\n");
321 return -1;
322 }
323 } else { 331 } else {
324 if (al.map != NULL) 332 if (al.map != NULL)
325 al.map->dso->hit = 1; 333 al.map->dso->hit = 1;
326 334
327 if (perf_evsel__add_hist_entry(evsel, &al, sample, machine)) { 335 ret = perf_evsel__add_hist_entry(evsel, &al, sample, machine);
336 if (ret < 0)
328 pr_debug("problem incrementing symbol period, skipping event\n"); 337 pr_debug("problem incrementing symbol period, skipping event\n");
329 return -1;
330 }
331 } 338 }
332 return 0; 339 return ret;
333} 340}
334 341
335static int process_read_event(struct perf_tool *tool, 342static int process_read_event(struct perf_tool *tool,
@@ -384,7 +391,7 @@ static int perf_report__setup_sample_type(struct perf_report *rep)
384 } 391 }
385 } 392 }
386 393
387 if (sort__branch_mode == 1) { 394 if (sort__mode == SORT_MODE__BRANCH) {
388 if (!self->fd_pipe && 395 if (!self->fd_pipe &&
389 !(sample_type & PERF_SAMPLE_BRANCH_STACK)) { 396 !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
390 ui__error("Selected -b but no branch data. " 397 ui__error("Selected -b but no branch data. "
@@ -455,7 +462,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
455 continue; 462 continue;
456 463
457 hists__fprintf_nr_sample_events(rep, hists, evname, stdout); 464 hists__fprintf_nr_sample_events(rep, hists, evname, stdout);
458 hists__fprintf(hists, true, 0, 0, stdout); 465 hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout);
459 fprintf(stdout, "\n\n"); 466 fprintf(stdout, "\n\n");
460 } 467 }
461 468
@@ -574,8 +581,8 @@ static int __cmd_report(struct perf_report *rep)
574 if (use_browser > 0) { 581 if (use_browser > 0) {
575 if (use_browser == 1) { 582 if (use_browser == 1) {
576 ret = perf_evlist__tui_browse_hists(session->evlist, 583 ret = perf_evlist__tui_browse_hists(session->evlist,
577 help, 584 help, NULL,
578 NULL, 585 rep->min_percent,
579 &session->header.env); 586 &session->header.env);
580 /* 587 /*
581 * Usually "ret" is the last pressed key, and we only 588 * Usually "ret" is the last pressed key, and we only
@@ -586,7 +593,7 @@ static int __cmd_report(struct perf_report *rep)
586 593
587 } else if (use_browser == 2) { 594 } else if (use_browser == 2) {
588 perf_evlist__gtk_browse_hists(session->evlist, help, 595 perf_evlist__gtk_browse_hists(session->evlist, help,
589 NULL); 596 NULL, rep->min_percent);
590 } 597 }
591 } else 598 } else
592 perf_evlist__tty_browse_hists(session->evlist, rep, help); 599 perf_evlist__tty_browse_hists(session->evlist, rep, help);
@@ -691,7 +698,19 @@ static int
691parse_branch_mode(const struct option *opt __maybe_unused, 698parse_branch_mode(const struct option *opt __maybe_unused,
692 const char *str __maybe_unused, int unset) 699 const char *str __maybe_unused, int unset)
693{ 700{
694 sort__branch_mode = !unset; 701 int *branch_mode = opt->value;
702
703 *branch_mode = !unset;
704 return 0;
705}
706
707static int
708parse_percent_limit(const struct option *opt, const char *str,
709 int unset __maybe_unused)
710{
711 struct perf_report *rep = opt->value;
712
713 rep->min_percent = strtof(str, NULL);
695 return 0; 714 return 0;
696} 715}
697 716
@@ -700,6 +719,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
700 struct perf_session *session; 719 struct perf_session *session;
701 struct stat st; 720 struct stat st;
702 bool has_br_stack = false; 721 bool has_br_stack = false;
722 int branch_mode = -1;
703 int ret = -1; 723 int ret = -1;
704 char callchain_default_opt[] = "fractal,0.5,callee"; 724 char callchain_default_opt[] = "fractal,0.5,callee";
705 const char * const report_usage[] = { 725 const char * const report_usage[] = {
@@ -796,17 +816,19 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
796 "Show a column with the sum of periods"), 816 "Show a column with the sum of periods"),
797 OPT_BOOLEAN(0, "group", &symbol_conf.event_group, 817 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
798 "Show event group information together"), 818 "Show event group information together"),
799 OPT_CALLBACK_NOOPT('b', "branch-stack", &sort__branch_mode, "", 819 OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
800 "use branch records for histogram filling", parse_branch_mode), 820 "use branch records for histogram filling", parse_branch_mode),
801 OPT_STRING(0, "objdump", &objdump_path, "path", 821 OPT_STRING(0, "objdump", &objdump_path, "path",
802 "objdump binary to use for disassembly and annotations"), 822 "objdump binary to use for disassembly and annotations"),
803 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, 823 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
804 "Disable symbol demangling"), 824 "Disable symbol demangling"),
805 OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"), 825 OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
826 OPT_CALLBACK(0, "percent-limit", &report, "percent",
827 "Don't show entries under that percent", parse_percent_limit),
806 OPT_END() 828 OPT_END()
807 }; 829 };
808 830
809 perf_config(perf_report_config, NULL); 831 perf_config(perf_report_config, &report);
810 832
811 argc = parse_options(argc, argv, options, report_usage, 0); 833 argc = parse_options(argc, argv, options, report_usage, 0);
812 834
@@ -846,11 +868,11 @@ repeat:
846 has_br_stack = perf_header__has_feat(&session->header, 868 has_br_stack = perf_header__has_feat(&session->header,
847 HEADER_BRANCH_STACK); 869 HEADER_BRANCH_STACK);
848 870
849 if (sort__branch_mode == -1 && has_br_stack) 871 if (branch_mode == -1 && has_br_stack)
850 sort__branch_mode = 1; 872 sort__mode = SORT_MODE__BRANCH;
851 873
852 /* sort__branch_mode could be 0 if --no-branch-stack */ 874 /* sort__mode could be NORMAL if --no-branch-stack */
853 if (sort__branch_mode == 1) { 875 if (sort__mode == SORT_MODE__BRANCH) {
854 /* 876 /*
855 * if no sort_order is provided, then specify 877 * if no sort_order is provided, then specify
856 * branch-mode specific order 878 * branch-mode specific order
@@ -861,10 +883,12 @@ repeat:
861 883
862 } 884 }
863 if (report.mem_mode) { 885 if (report.mem_mode) {
864 if (sort__branch_mode == 1) { 886 if (sort__mode == SORT_MODE__BRANCH) {
865 fprintf(stderr, "branch and mem mode incompatible\n"); 887 fprintf(stderr, "branch and mem mode incompatible\n");
866 goto error; 888 goto error;
867 } 889 }
890 sort__mode = SORT_MODE__MEMORY;
891
868 /* 892 /*
869 * if no sort_order is provided, then specify 893 * if no sort_order is provided, then specify
870 * branch-mode specific order 894 * branch-mode specific order
@@ -929,25 +953,7 @@ repeat:
929 report.symbol_filter_str = argv[0]; 953 report.symbol_filter_str = argv[0];
930 } 954 }
931 955
932 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout); 956 sort__setup_elide(stdout);
933
934 if (sort__branch_mode == 1) {
935 sort_entry__setup_elide(&sort_dso_from, symbol_conf.dso_from_list, "dso_from", stdout);
936 sort_entry__setup_elide(&sort_dso_to, symbol_conf.dso_to_list, "dso_to", stdout);
937 sort_entry__setup_elide(&sort_sym_from, symbol_conf.sym_from_list, "sym_from", stdout);
938 sort_entry__setup_elide(&sort_sym_to, symbol_conf.sym_to_list, "sym_to", stdout);
939 } else {
940 if (report.mem_mode) {
941 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "symbol_daddr", stdout);
942 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso_daddr", stdout);
943 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "mem", stdout);
944 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "local_weight", stdout);
945 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "tlb", stdout);
946 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "snoop", stdout);
947 }
948 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso", stdout);
949 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout);
950 }
951 957
952 ret = __cmd_report(&report); 958 ret = __cmd_report(&report);
953 if (ret == K_SWITCH_INPUT_DATA) { 959 if (ret == K_SWITCH_INPUT_DATA) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 67bdb9f14ad6..f036af9b6f09 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -70,10 +70,11 @@
70 70
71static volatile int done; 71static volatile int done;
72 72
73#define HEADER_LINE_NR 5
74
73static void perf_top__update_print_entries(struct perf_top *top) 75static void perf_top__update_print_entries(struct perf_top *top)
74{ 76{
75 if (top->print_entries > 9) 77 top->print_entries = top->winsize.ws_row - HEADER_LINE_NR;
76 top->print_entries -= 9;
77} 78}
78 79
79static void perf_top__sig_winch(int sig __maybe_unused, 80static void perf_top__sig_winch(int sig __maybe_unused,
@@ -82,13 +83,6 @@ static void perf_top__sig_winch(int sig __maybe_unused,
82 struct perf_top *top = arg; 83 struct perf_top *top = arg;
83 84
84 get_term_dimensions(&top->winsize); 85 get_term_dimensions(&top->winsize);
85 if (!top->print_entries
86 || (top->print_entries+4) > top->winsize.ws_row) {
87 top->print_entries = top->winsize.ws_row;
88 } else {
89 top->print_entries += 4;
90 top->winsize.ws_row = top->print_entries;
91 }
92 perf_top__update_print_entries(top); 86 perf_top__update_print_entries(top);
93} 87}
94 88
@@ -251,8 +245,11 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel,
251{ 245{
252 struct hist_entry *he; 246 struct hist_entry *he;
253 247
248 pthread_mutex_lock(&evsel->hists.lock);
254 he = __hists__add_entry(&evsel->hists, al, NULL, sample->period, 249 he = __hists__add_entry(&evsel->hists, al, NULL, sample->period,
255 sample->weight); 250 sample->weight);
251 pthread_mutex_unlock(&evsel->hists.lock);
252
256 if (he == NULL) 253 if (he == NULL)
257 return NULL; 254 return NULL;
258 255
@@ -290,16 +287,17 @@ static void perf_top__print_sym_table(struct perf_top *top)
290 return; 287 return;
291 } 288 }
292 289
293 hists__collapse_resort_threaded(&top->sym_evsel->hists); 290 hists__collapse_resort(&top->sym_evsel->hists);
294 hists__output_resort_threaded(&top->sym_evsel->hists); 291 hists__output_resort(&top->sym_evsel->hists);
295 hists__decay_entries_threaded(&top->sym_evsel->hists, 292 hists__decay_entries(&top->sym_evsel->hists,
296 top->hide_user_symbols, 293 top->hide_user_symbols,
297 top->hide_kernel_symbols); 294 top->hide_kernel_symbols);
298 hists__output_recalc_col_len(&top->sym_evsel->hists, 295 hists__output_recalc_col_len(&top->sym_evsel->hists,
299 top->winsize.ws_row - 3); 296 top->print_entries - printed);
300 putchar('\n'); 297 putchar('\n');
301 hists__fprintf(&top->sym_evsel->hists, false, 298 hists__fprintf(&top->sym_evsel->hists, false,
302 top->winsize.ws_row - 4 - printed, win_width, stdout); 299 top->print_entries - printed, win_width,
300 top->min_percent, stdout);
303} 301}
304 302
305static void prompt_integer(int *target, const char *msg) 303static void prompt_integer(int *target, const char *msg)
@@ -477,7 +475,6 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
477 perf_top__sig_winch(SIGWINCH, NULL, top); 475 perf_top__sig_winch(SIGWINCH, NULL, top);
478 sigaction(SIGWINCH, &act, NULL); 476 sigaction(SIGWINCH, &act, NULL);
479 } else { 477 } else {
480 perf_top__sig_winch(SIGWINCH, NULL, top);
481 signal(SIGWINCH, SIG_DFL); 478 signal(SIGWINCH, SIG_DFL);
482 } 479 }
483 break; 480 break;
@@ -556,11 +553,11 @@ static void perf_top__sort_new_samples(void *arg)
556 if (t->evlist->selected != NULL) 553 if (t->evlist->selected != NULL)
557 t->sym_evsel = t->evlist->selected; 554 t->sym_evsel = t->evlist->selected;
558 555
559 hists__collapse_resort_threaded(&t->sym_evsel->hists); 556 hists__collapse_resort(&t->sym_evsel->hists);
560 hists__output_resort_threaded(&t->sym_evsel->hists); 557 hists__output_resort(&t->sym_evsel->hists);
561 hists__decay_entries_threaded(&t->sym_evsel->hists, 558 hists__decay_entries(&t->sym_evsel->hists,
562 t->hide_user_symbols, 559 t->hide_user_symbols,
563 t->hide_kernel_symbols); 560 t->hide_kernel_symbols);
564} 561}
565 562
566static void *display_thread_tui(void *arg) 563static void *display_thread_tui(void *arg)
@@ -584,7 +581,7 @@ static void *display_thread_tui(void *arg)
584 list_for_each_entry(pos, &top->evlist->entries, node) 581 list_for_each_entry(pos, &top->evlist->entries, node)
585 pos->hists.uid_filter_str = top->record_opts.target.uid_str; 582 pos->hists.uid_filter_str = top->record_opts.target.uid_str;
586 583
587 perf_evlist__tui_browse_hists(top->evlist, help, &hbt, 584 perf_evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percent,
588 &top->session->header.env); 585 &top->session->header.env);
589 586
590 done = 1; 587 done = 1;
@@ -794,7 +791,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
794 return; 791 return;
795 } 792 }
796 793
797 if (top->sort_has_symbols) 794 if (sort__has_sym)
798 perf_top__record_precise_ip(top, he, evsel->idx, ip); 795 perf_top__record_precise_ip(top, he, evsel->idx, ip);
799 } 796 }
800 797
@@ -912,9 +909,9 @@ out_err:
912 return -1; 909 return -1;
913} 910}
914 911
915static int perf_top__setup_sample_type(struct perf_top *top) 912static int perf_top__setup_sample_type(struct perf_top *top __maybe_unused)
916{ 913{
917 if (!top->sort_has_symbols) { 914 if (!sort__has_sym) {
918 if (symbol_conf.use_callchain) { 915 if (symbol_conf.use_callchain) {
919 ui__error("Selected -g but \"sym\" not present in --sort/-s."); 916 ui__error("Selected -g but \"sym\" not present in --sort/-s.");
920 return -EINVAL; 917 return -EINVAL;
@@ -1025,6 +1022,16 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset)
1025 return record_parse_callchain_opt(opt, arg, unset); 1022 return record_parse_callchain_opt(opt, arg, unset);
1026} 1023}
1027 1024
1025static int
1026parse_percent_limit(const struct option *opt, const char *arg,
1027 int unset __maybe_unused)
1028{
1029 struct perf_top *top = opt->value;
1030
1031 top->min_percent = strtof(arg, NULL);
1032 return 0;
1033}
1034
1028int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) 1035int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1029{ 1036{
1030 int status; 1037 int status;
@@ -1110,6 +1117,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1110 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", 1117 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
1111 "Specify disassembler style (e.g. -M intel for intel syntax)"), 1118 "Specify disassembler style (e.g. -M intel for intel syntax)"),
1112 OPT_STRING('u', "uid", &target->uid_str, "user", "user to profile"), 1119 OPT_STRING('u', "uid", &target->uid_str, "user", "user to profile"),
1120 OPT_CALLBACK(0, "percent-limit", &top, "percent",
1121 "Don't show entries under that percent", parse_percent_limit),
1113 OPT_END() 1122 OPT_END()
1114 }; 1123 };
1115 const char * const top_usage[] = { 1124 const char * const top_usage[] = {
@@ -1133,6 +1142,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1133 if (setup_sorting() < 0) 1142 if (setup_sorting() < 0)
1134 usage_with_options(top_usage, options); 1143 usage_with_options(top_usage, options);
1135 1144
1145 /* display thread wants entries to be collapsed in a different tree */
1146 sort__need_collapse = 1;
1147
1136 if (top.use_stdio) 1148 if (top.use_stdio)
1137 use_browser = 0; 1149 use_browser = 0;
1138 else if (top.use_tui) 1150 else if (top.use_tui)
@@ -1200,15 +1212,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1200 if (symbol__init() < 0) 1212 if (symbol__init() < 0)
1201 return -1; 1213 return -1;
1202 1214
1203 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso", stdout); 1215 sort__setup_elide(stdout);
1204 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout);
1205 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout);
1206
1207 /*
1208 * Avoid annotation data structures overhead when symbols aren't on the
1209 * sort list.
1210 */
1211 top.sort_has_symbols = sort_sym.list.next != NULL;
1212 1216
1213 get_term_dimensions(&top.winsize); 1217 get_term_dimensions(&top.winsize);
1214 if (top.print_entries == 0) { 1218 if (top.print_entries == 0) {
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
new file mode 100644
index 000000000000..f139dcd2796e
--- /dev/null
+++ b/tools/perf/config/Makefile
@@ -0,0 +1,477 @@
1uname_M := $(shell uname -m 2>/dev/null || echo not)
2
3ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
4 -e s/arm.*/arm/ -e s/sa110/arm/ \
5 -e s/s390x/s390/ -e s/parisc64/parisc/ \
6 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
7 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
8NO_PERF_REGS := 1
9CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
10
11# Additional ARCH settings for x86
12ifeq ($(ARCH),i386)
13 override ARCH := x86
14 NO_PERF_REGS := 0
15 LIBUNWIND_LIBS = -lunwind -lunwind-x86
16endif
17
18ifeq ($(ARCH),x86_64)
19 override ARCH := x86
20 IS_X86_64 := 0
21 ifeq (, $(findstring m32,$(CFLAGS)))
22 IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
23 endif
24 ifeq (${IS_X86_64}, 1)
25 RAW_ARCH := x86_64
26 CFLAGS += -DARCH_X86_64
27 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
28 endif
29 NO_PERF_REGS := 0
30 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
31endif
32
33ifeq ($(NO_PERF_REGS),0)
34 CFLAGS += -DHAVE_PERF_REGS
35endif
36
37ifeq ($(src-perf),)
38src-perf := $(srctree)/tools/perf
39endif
40
41ifeq ($(obj-perf),)
42obj-perf := $(objtree)
43endif
44
45ifneq ($(obj-perf),)
46obj-perf := $(abspath $(obj-perf))/
47endif
48
49# include ARCH specific config
50-include $(src-perf)/arch/$(ARCH)/Makefile
51
52include $(src-perf)/config/feature-tests.mak
53include $(src-perf)/config/utilities.mak
54
55ifeq ($(call get-executable,$(FLEX)),)
56 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
57endif
58
59ifeq ($(call get-executable,$(BISON)),)
60 dummy := $(error Error: $(BISON) is missing on this system, please install it)
61endif
62
63# Treat warnings as errors unless directed not to
64ifneq ($(WERROR),0)
65 CFLAGS += -Werror
66endif
67
68ifeq ("$(origin DEBUG)", "command line")
69 PERF_DEBUG = $(DEBUG)
70endif
71ifndef PERF_DEBUG
72 CFLAGS += -O6
73endif
74
75ifdef PARSER_DEBUG
76 PARSER_DEBUG_BISON := -t
77 PARSER_DEBUG_FLEX := -d
78 CFLAGS += -DPARSER_DEBUG
79endif
80
81CFLAGS += -fno-omit-frame-pointer
82CFLAGS += -ggdb3
83CFLAGS += -funwind-tables
84CFLAGS += -Wall
85CFLAGS += -Wextra
86CFLAGS += -std=gnu99
87
88EXTLIBS = -lpthread -lrt -lelf -lm
89
90ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y)
91 CFLAGS += -fstack-protector-all
92endif
93
94ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wstack-protector,-Wstack-protector),y)
95 CFLAGS += -Wstack-protector
96endif
97
98ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-Wvolatile-register-var),y)
99 CFLAGS += -Wvolatile-register-var
100endif
101
102ifndef PERF_DEBUG
103 ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y)
104 CFLAGS += -D_FORTIFY_SOURCE=2
105 endif
106endif
107
108CFLAGS += -I$(src-perf)/util/include
109CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
110CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
111CFLAGS += -I$(srctree)/arch/$(ARCH)/include
112CFLAGS += -I$(srctree)/include/uapi
113CFLAGS += -I$(srctree)/include
114
115# $(obj-perf) for generated common-cmds.h
116# $(obj-perf)/util for generated bison/flex headers
117ifneq ($(OUTPUT),)
118CFLAGS += -I$(obj-perf)/util
119CFLAGS += -I$(obj-perf)
120endif
121
122CFLAGS += -I$(src-perf)/util
123CFLAGS += -I$(src-perf)
124CFLAGS += -I$(TRACE_EVENT_DIR)
125CFLAGS += -I$(srctree)/tools/lib/
126
127CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
128
129ifndef NO_BIONIC
130ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
131 BIONIC := 1
132 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
133 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
134endif
135endif # NO_BIONIC
136
137ifdef NO_LIBELF
138 NO_DWARF := 1
139 NO_DEMANGLE := 1
140 NO_LIBUNWIND := 1
141else
142FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
143ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF),libelf),y)
144 FLAGS_GLIBC=$(CFLAGS) $(LDFLAGS)
145 ifeq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC),glibc),y)
146 LIBC_SUPPORT := 1
147 endif
148 ifeq ($(BIONIC),1)
149 LIBC_SUPPORT := 1
150 endif
151 ifeq ($(LIBC_SUPPORT),1)
152 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
153
154 NO_LIBELF := 1
155 NO_DWARF := 1
156 NO_DEMANGLE := 1
157 else
158 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
159 endif
160else
161 # for linking with debug library, run like:
162 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
163 ifdef LIBDW_DIR
164 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
165 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
166 endif
167
168 FLAGS_DWARF=$(CFLAGS) $(LIBDW_CFLAGS) -ldw -lelf $(LIBDW_LDFLAGS) $(LDFLAGS) $(EXTLIBS)
169 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF),libdw),y)
170 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
171 NO_DWARF := 1
172 endif # Dwarf support
173endif # SOURCE_LIBELF
174endif # NO_LIBELF
175
176ifndef NO_LIBELF
177CFLAGS += -DLIBELF_SUPPORT
178FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
179ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
180 CFLAGS += -DLIBELF_MMAP
181endif
182
183# include ARCH specific config
184-include $(src-perf)/arch/$(ARCH)/Makefile
185
186ifndef NO_DWARF
187ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
188 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
189 NO_DWARF := 1
190else
191 CFLAGS += -DDWARF_SUPPORT $(LIBDW_CFLAGS)
192 LDFLAGS += $(LIBDW_LDFLAGS)
193 EXTLIBS += -lelf -ldw
194endif # PERF_HAVE_DWARF_REGS
195endif # NO_DWARF
196
197endif # NO_LIBELF
198
199ifndef NO_LIBELF
200CFLAGS += -DLIBELF_SUPPORT
201FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
202ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
203 CFLAGS += -DLIBELF_MMAP
204endif # try-cc
205endif # NO_LIBELF
206
207# There's only x86 (both 32 and 64) support for CFI unwind so far
208ifneq ($(ARCH),x86)
209 NO_LIBUNWIND := 1
210endif
211
212ifndef NO_LIBUNWIND
213# for linking with debug library, run like:
214# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
215ifdef LIBUNWIND_DIR
216 LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
217 LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
218endif
219
220FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(CFLAGS) $(LIBUNWIND_LDFLAGS) $(LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
221ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND),libunwind),y)
222 msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
223 NO_LIBUNWIND := 1
224endif # Libunwind support
225endif # NO_LIBUNWIND
226
227ifndef NO_LIBUNWIND
228 CFLAGS += -DLIBUNWIND_SUPPORT
229 EXTLIBS += $(LIBUNWIND_LIBS)
230 CFLAGS += $(LIBUNWIND_CFLAGS)
231 LDFLAGS += $(LIBUNWIND_LDFLAGS)
232endif # NO_LIBUNWIND
233
234ifndef NO_LIBAUDIT
235 FLAGS_LIBAUDIT = $(CFLAGS) $(LDFLAGS) -laudit
236 ifneq ($(call try-cc,$(SOURCE_LIBAUDIT),$(FLAGS_LIBAUDIT),libaudit),y)
237 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
238 NO_LIBAUDIT := 1
239 else
240 CFLAGS += -DLIBAUDIT_SUPPORT
241 EXTLIBS += -laudit
242 endif
243endif
244
245ifdef NO_NEWT
246 NO_SLANG=1
247endif
248
249ifndef NO_SLANG
250 FLAGS_SLANG=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -I/usr/include/slang -lslang
251 ifneq ($(call try-cc,$(SOURCE_SLANG),$(FLAGS_SLANG),libslang),y)
252 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
253 NO_SLANG := 1
254 else
255 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
256 CFLAGS += -I/usr/include/slang
257 CFLAGS += -DSLANG_SUPPORT
258 EXTLIBS += -lslang
259 endif
260endif
261
262ifndef NO_GTK2
263 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
264 ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2),gtk2),y)
265 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
266 NO_GTK2 := 1
267 else
268 ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2),-DHAVE_GTK_INFO_BAR),y)
269 CFLAGS += -DHAVE_GTK_INFO_BAR
270 endif
271 CFLAGS += -DGTK2_SUPPORT
272 CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
273 EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
274 endif
275endif
276
277grep-libs = $(filter -l%,$(1))
278strip-libs = $(filter-out -l%,$(1))
279
280ifdef NO_LIBPERL
281 CFLAGS += -DNO_LIBPERL
282else
283 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
284 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
285 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
286 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
287 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
288
289 ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED),perl),y)
290 CFLAGS += -DNO_LIBPERL
291 NO_LIBPERL := 1
292 else
293 LDFLAGS += $(PERL_EMBED_LDFLAGS)
294 EXTLIBS += $(PERL_EMBED_LIBADD)
295 endif
296endif
297
298disable-python = $(eval $(disable-python_code))
299define disable-python_code
300 CFLAGS += -DNO_LIBPYTHON
301 $(if $(1),$(warning No $(1) was found))
302 $(warning Python support will not be built)
303 NO_LIBPYTHON := 1
304endef
305
306override PYTHON := \
307 $(call get-executable-or-default,PYTHON,python)
308
309ifndef PYTHON
310 $(call disable-python,python interpreter)
311else
312
313 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
314
315 ifdef NO_LIBPYTHON
316 $(call disable-python)
317 else
318
319 override PYTHON_CONFIG := \
320 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
321
322 ifndef PYTHON_CONFIG
323 $(call disable-python,python-config tool)
324 else
325
326 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
327
328 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
329 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
330 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
331 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
332 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
333
334 ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED),python),y)
335 $(call disable-python,Python.h (for Python 2.x))
336 else
337
338 ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED),python version),y)
339 $(warning Python 3 is not yet supported; please set)
340 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
341 $(warning If you also have Python 2 installed, then)
342 $(warning try something like:)
343 $(warning $(and ,))
344 $(warning $(and ,) make PYTHON=python2)
345 $(warning $(and ,))
346 $(warning Otherwise, disable Python support entirely:)
347 $(warning $(and ,))
348 $(warning $(and ,) make NO_LIBPYTHON=1)
349 $(warning $(and ,))
350 $(error $(and ,))
351 else
352 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
353 EXTLIBS += $(PYTHON_EMBED_LIBADD)
354 LANG_BINDINGS += $(obj-perf)python/perf.so
355 endif
356 endif
357 endif
358 endif
359endif
360
361ifdef NO_DEMANGLE
362 CFLAGS += -DNO_DEMANGLE
363else
364 ifdef HAVE_CPLUS_DEMANGLE
365 EXTLIBS += -liberty
366 CFLAGS += -DHAVE_CPLUS_DEMANGLE
367 else
368 FLAGS_BFD=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
369 has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
370 ifeq ($(has_bfd),y)
371 EXTLIBS += -lbfd
372 else
373 FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
374 has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
375 ifeq ($(has_bfd_iberty),y)
376 EXTLIBS += -lbfd -liberty
377 else
378 FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
379 has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
380 ifeq ($(has_bfd_iberty_z),y)
381 EXTLIBS += -lbfd -liberty -lz
382 else
383 FLAGS_CPLUS_DEMANGLE=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -liberty
384 has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
385 ifeq ($(has_cplus_demangle),y)
386 EXTLIBS += -liberty
387 CFLAGS += -DHAVE_CPLUS_DEMANGLE
388 else
389 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
390 CFLAGS += -DNO_DEMANGLE
391 endif
392 endif
393 endif
394 endif
395 endif
396endif
397
398ifndef NO_STRLCPY
399 ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY),y)
400 CFLAGS += -DHAVE_STRLCPY
401 endif
402endif
403
404ifndef NO_ON_EXIT
405 ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT),y)
406 CFLAGS += -DHAVE_ON_EXIT
407 endif
408endif
409
410ifndef NO_BACKTRACE
411 ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DBACKTRACE_SUPPORT),y)
412 CFLAGS += -DBACKTRACE_SUPPORT
413 endif
414endif
415
416ifndef NO_LIBNUMA
417 FLAGS_LIBNUMA = $(CFLAGS) $(LDFLAGS) -lnuma
418 ifneq ($(call try-cc,$(SOURCE_LIBNUMA),$(FLAGS_LIBNUMA),libnuma),y)
419 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
420 NO_LIBNUMA := 1
421 else
422 CFLAGS += -DLIBNUMA_SUPPORT
423 EXTLIBS += -lnuma
424 endif
425endif
426
427# Among the variables below, these:
428# perfexecdir
429# template_dir
430# mandir
431# infodir
432# htmldir
433# ETC_PERFCONFIG (but not sysconfdir)
434# can be specified as a relative path some/where/else;
435# this is interpreted as relative to $(prefix) and "perf" at
436# runtime figures out where they are based on the path to the executable.
437# This can help installing the suite in a relocatable way.
438
439# Make the path relative to DESTDIR, not to prefix
440ifndef DESTDIR
441prefix = $(HOME)
442endif
443bindir_relative = bin
444bindir = $(prefix)/$(bindir_relative)
445mandir = share/man
446infodir = share/info
447perfexecdir = libexec/perf-core
448sharedir = $(prefix)/share
449template_dir = share/perf-core/templates
450htmldir = share/doc/perf-doc
451ifeq ($(prefix),/usr)
452sysconfdir = /etc
453ETC_PERFCONFIG = $(sysconfdir)/perfconfig
454else
455sysconfdir = $(prefix)/etc
456ETC_PERFCONFIG = etc/perfconfig
457endif
458lib = lib
459
460# Shell quote (do not use $(call) to accommodate ancient setups);
461ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
462DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
463bindir_SQ = $(subst ','\'',$(bindir))
464mandir_SQ = $(subst ','\'',$(mandir))
465infodir_SQ = $(subst ','\'',$(infodir))
466perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
467template_dir_SQ = $(subst ','\'',$(template_dir))
468htmldir_SQ = $(subst ','\'',$(htmldir))
469prefix_SQ = $(subst ','\'',$(prefix))
470sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
471
472ifneq ($(filter /%,$(firstword $(perfexecdir))),)
473perfexec_instdir = $(perfexecdir)
474else
475perfexec_instdir = $(prefix)/$(perfexecdir)
476endif
477perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
diff --git a/tools/perf/tests/attr/base-record b/tools/perf/tests/attr/base-record
index b4fc835de607..e9bd6391f2ae 100644
--- a/tools/perf/tests/attr/base-record
+++ b/tools/perf/tests/attr/base-record
@@ -27,8 +27,8 @@ watermark=0
27precise_ip=0 27precise_ip=0
28mmap_data=0 28mmap_data=0
29sample_id_all=1 29sample_id_all=1
30exclude_host=0 30exclude_host=0|1
31exclude_guest=1 31exclude_guest=0|1
32exclude_callchain_kernel=0 32exclude_callchain_kernel=0
33exclude_callchain_user=0 33exclude_callchain_user=0
34wakeup_events=0 34wakeup_events=0
diff --git a/tools/perf/tests/attr/base-stat b/tools/perf/tests/attr/base-stat
index 748ee949a204..91cd48b399f3 100644
--- a/tools/perf/tests/attr/base-stat
+++ b/tools/perf/tests/attr/base-stat
@@ -27,8 +27,8 @@ watermark=0
27precise_ip=0 27precise_ip=0
28mmap_data=0 28mmap_data=0
29sample_id_all=0 29sample_id_all=0
30exclude_host=0 30exclude_host=0|1
31exclude_guest=1 31exclude_guest=0|1
32exclude_callchain_kernel=0 32exclude_callchain_kernel=0
33exclude_callchain_user=0 33exclude_callchain_user=0
34wakeup_events=0 34wakeup_events=0
diff --git a/tools/perf/tests/attr/test-record-data b/tools/perf/tests/attr/test-record-data
index 6627c3e7534a..716e143b5291 100644
--- a/tools/perf/tests/attr/test-record-data
+++ b/tools/perf/tests/attr/test-record-data
@@ -4,5 +4,8 @@ args = -d kill >/dev/null 2>&1
4 4
5[event:base-record] 5[event:base-record]
6sample_period=4000 6sample_period=4000
7sample_type=271 7
8# sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_TIME |
9# PERF_SAMPLE_ADDR | PERF_SAMPLE_PERIOD | PERF_SAMPLE_DATA_SRC
10sample_type=33039
8mmap_data=1 11mmap_data=1
diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
index 68daa289e94c..aba095489193 100644
--- a/tools/perf/tests/bp_signal.c
+++ b/tools/perf/tests/bp_signal.c
@@ -4,6 +4,12 @@
4 * (git://github.com/deater/perf_event_tests) 4 * (git://github.com/deater/perf_event_tests)
5 */ 5 */
6 6
7/*
8 * Powerpc needs __SANE_USERSPACE_TYPES__ before <linux/types.h> to select
9 * 'int-ll64.h' and avoid compile warnings when printing __u64 with %llu.
10 */
11#define __SANE_USERSPACE_TYPES__
12
7#include <stdlib.h> 13#include <stdlib.h>
8#include <stdio.h> 14#include <stdio.h>
9#include <unistd.h> 15#include <unistd.h>
diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c
index fe7ed28815f8..44ac82179708 100644
--- a/tools/perf/tests/bp_signal_overflow.c
+++ b/tools/perf/tests/bp_signal_overflow.c
@@ -3,6 +3,12 @@
3 * perf_event_tests (git://github.com/deater/perf_event_tests) 3 * perf_event_tests (git://github.com/deater/perf_event_tests)
4 */ 4 */
5 5
6/*
7 * Powerpc needs __SANE_USERSPACE_TYPES__ before <linux/types.h> to select
8 * 'int-ll64.h' and avoid compile warnings when printing __u64 with %llu.
9 */
10#define __SANE_USERSPACE_TYPES__
11
6#include <stdlib.h> 12#include <stdlib.h>
7#include <stdio.h> 13#include <stdio.h>
8#include <unistd.h> 14#include <unistd.h>
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 0918ada4cc41..35b45f1466b5 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -70,7 +70,7 @@ static struct test {
70 .func = test__attr, 70 .func = test__attr,
71 }, 71 },
72 { 72 {
73 .desc = "Test matching and linking mutliple hists", 73 .desc = "Test matching and linking multiple hists",
74 .func = test__hists_link, 74 .func = test__hists_link,
75 }, 75 },
76 { 76 {
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
new file mode 100644
index 000000000000..c441a2875128
--- /dev/null
+++ b/tools/perf/tests/make
@@ -0,0 +1,138 @@
1PERF := .
2MK := Makefile
3
4# standard single make variable specified
5make_clean_all := clean all
6make_python_perf_so := python/perf.so
7make_debug := DEBUG=1
8make_no_libperl := NO_LIBPERL=1
9make_no_libpython := NO_LIBPYTHON=1
10make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1
11make_no_newt := NO_NEWT=1
12make_no_slang := NO_SLANG=1
13make_no_gtk2 := NO_GTK2=1
14make_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
15make_no_demangle := NO_DEMANGLE=1
16make_no_libelf := NO_LIBELF=1
17make_no_libunwind := NO_LIBUNWIND=1
18make_no_backtrace := NO_BACKTRACE=1
19make_no_libnuma := NO_LIBNUMA=1
20make_no_libaudit := NO_LIBAUDIT=1
21make_no_libbionic := NO_LIBBIONIC=1
22make_tags := tags
23make_cscope := cscope
24make_help := help
25make_doc := doc
26make_perf_o := perf.o
27make_util_map_o := util/map.o
28
29# all the NO_* variable combined
30make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
31make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
32make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
33
34# $(run) contains all available tests
35run := make_pure
36run += make_clean_all
37run += make_python_perf_so
38run += make_debug
39run += make_no_libperl
40run += make_no_libpython
41run += make_no_scripts
42run += make_no_newt
43run += make_no_slang
44run += make_no_gtk2
45run += make_no_ui
46run += make_no_demangle
47run += make_no_libelf
48run += make_no_libunwind
49run += make_no_backtrace
50run += make_no_libnuma
51run += make_no_libaudit
52run += make_no_libbionic
53run += make_tags
54run += make_cscope
55run += make_help
56run += make_doc
57run += make_perf_o
58run += make_util_map_o
59run += make_minimal
60
61# $(run_O) contains same portion of $(run) tests with '_O' attached
62# to distinguish O=... tests
63run_O := $(addsuffix _O,$(run))
64
65# disable some tests for O=...
66run_O := $(filter-out make_python_perf_so_O,$(run_O))
67
68# define test for each compile as 'test_NAME' variable
69# with the test itself as a value
70test_make_tags = test -f tags
71test_make_cscope = test -f cscope.out
72
73test_make_tags_O := $(test_make_tags)
74test_make_cscope_O := $(test_make_cscope)
75
76test_ok := true
77test_make_help := $(test_ok)
78test_make_doc := $(test_ok)
79test_make_help_O := $(test_ok)
80test_make_doc_O := $(test_ok)
81
82test_make_python_perf_so := test -f $(PERF)/python/perf.so
83
84test_make_perf_o := test -f $(PERF)/perf.o
85test_make_util_map_o := test -f $(PERF)/util/map.o
86
87# Kbuild tests only
88#test_make_python_perf_so_O := test -f $$TMP/tools/perf/python/perf.so
89#test_make_perf_o_O := test -f $$TMP/tools/perf/perf.o
90#test_make_util_map_o_O := test -f $$TMP/tools/perf/util/map.o
91
92test_make_perf_o_O := true
93test_make_util_map_o_O := true
94
95test_default = test -x $(PERF)/perf
96test = $(if $(test_$1),$(test_$1),$(test_default))
97
98test_default_O = test -x $$TMP/perf
99test_O = $(if $(test_$1),$(test_$1),$(test_default_O))
100
101all:
102
103ifdef DEBUG
104d := $(info run $(run))
105d := $(info run_O $(run_O))
106endif
107
108MAKEFLAGS := --no-print-directory
109
110clean := @(cd $(PERF); make -s -f $(MK) clean >/dev/null)
111
112$(run):
113 $(call clean)
114 @cmd="cd $(PERF) && make -f $(MK) $($@)"; \
115 echo "- $@: $$cmd" && echo $$cmd > $@ && \
116 ( eval $$cmd ) >> $@ 2>&1; \
117 echo " test: $(call test,$@)"; \
118 $(call test,$@) && \
119 rm -f $@
120
121$(run_O):
122 $(call clean)
123 @TMP=$$(mktemp -d); \
124 cmd="cd $(PERF) && make -f $(MK) $($(patsubst %_O,%,$@)) O=$$TMP"; \
125 echo "- $@: $$cmd" && echo $$cmd > $@ && \
126 ( eval $$cmd ) >> $@ 2>&1 && \
127 echo " test: $(call test_O,$@)"; \
128 $(call test_O,$@) && \
129 rm -f $@ && \
130 rm -rf $$TMP
131
132all: $(run) $(run_O)
133 @echo OK
134
135out: $(run_O)
136 @echo OK
137
138.PHONY: all $(run) $(run_O) clean
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index d88a2d0acb6d..fc0bd3843d34 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -25,7 +25,8 @@ struct hist_browser {
25 struct map_symbol *selection; 25 struct map_symbol *selection;
26 int print_seq; 26 int print_seq;
27 bool show_dso; 27 bool show_dso;
28 bool has_symbols; 28 float min_pcnt;
29 u64 nr_pcnt_entries;
29}; 30};
30 31
31extern void hist_browser__init_hpp(void); 32extern void hist_browser__init_hpp(void);
@@ -309,6 +310,8 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser)
309 "Or reduce the sampling frequency."); 310 "Or reduce the sampling frequency.");
310} 311}
311 312
313static void hist_browser__update_pcnt_entries(struct hist_browser *hb);
314
312static int hist_browser__run(struct hist_browser *browser, const char *ev_name, 315static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
313 struct hist_browser_timer *hbt) 316 struct hist_browser_timer *hbt)
314{ 317{
@@ -318,6 +321,8 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
318 321
319 browser->b.entries = &browser->hists->entries; 322 browser->b.entries = &browser->hists->entries;
320 browser->b.nr_entries = browser->hists->nr_entries; 323 browser->b.nr_entries = browser->hists->nr_entries;
324 if (browser->min_pcnt)
325 browser->b.nr_entries = browser->nr_pcnt_entries;
321 326
322 hist_browser__refresh_dimensions(browser); 327 hist_browser__refresh_dimensions(browser);
323 hists__browser_title(browser->hists, title, sizeof(title), ev_name); 328 hists__browser_title(browser->hists, title, sizeof(title), ev_name);
@@ -330,9 +335,18 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
330 key = ui_browser__run(&browser->b, delay_secs); 335 key = ui_browser__run(&browser->b, delay_secs);
331 336
332 switch (key) { 337 switch (key) {
333 case K_TIMER: 338 case K_TIMER: {
339 u64 nr_entries;
334 hbt->timer(hbt->arg); 340 hbt->timer(hbt->arg);
335 ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); 341
342 if (browser->min_pcnt) {
343 hist_browser__update_pcnt_entries(browser);
344 nr_entries = browser->nr_pcnt_entries;
345 } else {
346 nr_entries = browser->hists->nr_entries;
347 }
348
349 ui_browser__update_nr_entries(&browser->b, nr_entries);
336 350
337 if (browser->hists->stats.nr_lost_warned != 351 if (browser->hists->stats.nr_lost_warned !=
338 browser->hists->stats.nr_events[PERF_RECORD_LOST]) { 352 browser->hists->stats.nr_events[PERF_RECORD_LOST]) {
@@ -344,6 +358,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,
344 hists__browser_title(browser->hists, title, sizeof(title), ev_name); 358 hists__browser_title(browser->hists, title, sizeof(title), ev_name);
345 ui_browser__show_title(&browser->b, title); 359 ui_browser__show_title(&browser->b, title);
346 continue; 360 continue;
361 }
347 case 'D': { /* Debug */ 362 case 'D': { /* Debug */
348 static int seq; 363 static int seq;
349 struct hist_entry *h = rb_entry(browser->b.top, 364 struct hist_entry *h = rb_entry(browser->b.top,
@@ -796,10 +811,15 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)
796 811
797 for (nd = browser->top; nd; nd = rb_next(nd)) { 812 for (nd = browser->top; nd; nd = rb_next(nd)) {
798 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 813 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
814 float percent = h->stat.period * 100.0 /
815 hb->hists->stats.total_period;
799 816
800 if (h->filtered) 817 if (h->filtered)
801 continue; 818 continue;
802 819
820 if (percent < hb->min_pcnt)
821 continue;
822
803 row += hist_browser__show_entry(hb, h, row); 823 row += hist_browser__show_entry(hb, h, row);
804 if (row == browser->height) 824 if (row == browser->height)
805 break; 825 break;
@@ -808,10 +828,18 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)
808 return row; 828 return row;
809} 829}
810 830
811static struct rb_node *hists__filter_entries(struct rb_node *nd) 831static struct rb_node *hists__filter_entries(struct rb_node *nd,
832 struct hists *hists,
833 float min_pcnt)
812{ 834{
813 while (nd != NULL) { 835 while (nd != NULL) {
814 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 836 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
837 float percent = h->stat.period * 100.0 /
838 hists->stats.total_period;
839
840 if (percent < min_pcnt)
841 return NULL;
842
815 if (!h->filtered) 843 if (!h->filtered)
816 return nd; 844 return nd;
817 845
@@ -821,11 +849,16 @@ static struct rb_node *hists__filter_entries(struct rb_node *nd)
821 return NULL; 849 return NULL;
822} 850}
823 851
824static struct rb_node *hists__filter_prev_entries(struct rb_node *nd) 852static struct rb_node *hists__filter_prev_entries(struct rb_node *nd,
853 struct hists *hists,
854 float min_pcnt)
825{ 855{
826 while (nd != NULL) { 856 while (nd != NULL) {
827 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 857 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
828 if (!h->filtered) 858 float percent = h->stat.period * 100.0 /
859 hists->stats.total_period;
860
861 if (!h->filtered && percent >= min_pcnt)
829 return nd; 862 return nd;
830 863
831 nd = rb_prev(nd); 864 nd = rb_prev(nd);
@@ -840,6 +873,9 @@ static void ui_browser__hists_seek(struct ui_browser *browser,
840 struct hist_entry *h; 873 struct hist_entry *h;
841 struct rb_node *nd; 874 struct rb_node *nd;
842 bool first = true; 875 bool first = true;
876 struct hist_browser *hb;
877
878 hb = container_of(browser, struct hist_browser, b);
843 879
844 if (browser->nr_entries == 0) 880 if (browser->nr_entries == 0)
845 return; 881 return;
@@ -848,13 +884,15 @@ static void ui_browser__hists_seek(struct ui_browser *browser,
848 884
849 switch (whence) { 885 switch (whence) {
850 case SEEK_SET: 886 case SEEK_SET:
851 nd = hists__filter_entries(rb_first(browser->entries)); 887 nd = hists__filter_entries(rb_first(browser->entries),
888 hb->hists, hb->min_pcnt);
852 break; 889 break;
853 case SEEK_CUR: 890 case SEEK_CUR:
854 nd = browser->top; 891 nd = browser->top;
855 goto do_offset; 892 goto do_offset;
856 case SEEK_END: 893 case SEEK_END:
857 nd = hists__filter_prev_entries(rb_last(browser->entries)); 894 nd = hists__filter_prev_entries(rb_last(browser->entries),
895 hb->hists, hb->min_pcnt);
858 first = false; 896 first = false;
859 break; 897 break;
860 default: 898 default:
@@ -897,7 +935,8 @@ do_offset:
897 break; 935 break;
898 } 936 }
899 } 937 }
900 nd = hists__filter_entries(rb_next(nd)); 938 nd = hists__filter_entries(rb_next(nd), hb->hists,
939 hb->min_pcnt);
901 if (nd == NULL) 940 if (nd == NULL)
902 break; 941 break;
903 --offset; 942 --offset;
@@ -930,7 +969,8 @@ do_offset:
930 } 969 }
931 } 970 }
932 971
933 nd = hists__filter_prev_entries(rb_prev(nd)); 972 nd = hists__filter_prev_entries(rb_prev(nd), hb->hists,
973 hb->min_pcnt);
934 if (nd == NULL) 974 if (nd == NULL)
935 break; 975 break;
936 ++offset; 976 ++offset;
@@ -1099,14 +1139,17 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
1099 1139
1100static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) 1140static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp)
1101{ 1141{
1102 struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries)); 1142 struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries),
1143 browser->hists,
1144 browser->min_pcnt);
1103 int printed = 0; 1145 int printed = 0;
1104 1146
1105 while (nd) { 1147 while (nd) {
1106 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 1148 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1107 1149
1108 printed += hist_browser__fprintf_entry(browser, h, fp); 1150 printed += hist_browser__fprintf_entry(browser, h, fp);
1109 nd = hists__filter_entries(rb_next(nd)); 1151 nd = hists__filter_entries(rb_next(nd), browser->hists,
1152 browser->min_pcnt);
1110 } 1153 }
1111 1154
1112 return printed; 1155 return printed;
@@ -1155,10 +1198,6 @@ static struct hist_browser *hist_browser__new(struct hists *hists)
1155 browser->b.refresh = hist_browser__refresh; 1198 browser->b.refresh = hist_browser__refresh;
1156 browser->b.seek = ui_browser__hists_seek; 1199 browser->b.seek = ui_browser__hists_seek;
1157 browser->b.use_navkeypressed = true; 1200 browser->b.use_navkeypressed = true;
1158 if (sort__branch_mode == 1)
1159 browser->has_symbols = sort_sym_from.list.next != NULL;
1160 else
1161 browser->has_symbols = sort_sym.list.next != NULL;
1162 } 1201 }
1163 1202
1164 return browser; 1203 return browser;
@@ -1329,11 +1368,25 @@ close_file_and_continue:
1329 return ret; 1368 return ret;
1330} 1369}
1331 1370
1371static void hist_browser__update_pcnt_entries(struct hist_browser *hb)
1372{
1373 u64 nr_entries = 0;
1374 struct rb_node *nd = rb_first(&hb->hists->entries);
1375
1376 while (nd) {
1377 nr_entries++;
1378 nd = hists__filter_entries(rb_next(nd), hb->hists,
1379 hb->min_pcnt);
1380 }
1381
1382 hb->nr_pcnt_entries = nr_entries;
1383}
1332 1384
1333static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, 1385static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
1334 const char *helpline, const char *ev_name, 1386 const char *helpline, const char *ev_name,
1335 bool left_exits, 1387 bool left_exits,
1336 struct hist_browser_timer *hbt, 1388 struct hist_browser_timer *hbt,
1389 float min_pcnt,
1337 struct perf_session_env *env) 1390 struct perf_session_env *env)
1338{ 1391{
1339 struct hists *hists = &evsel->hists; 1392 struct hists *hists = &evsel->hists;
@@ -1350,6 +1403,11 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
1350 if (browser == NULL) 1403 if (browser == NULL)
1351 return -1; 1404 return -1;
1352 1405
1406 if (min_pcnt) {
1407 browser->min_pcnt = min_pcnt;
1408 hist_browser__update_pcnt_entries(browser);
1409 }
1410
1353 fstack = pstack__new(2); 1411 fstack = pstack__new(2);
1354 if (fstack == NULL) 1412 if (fstack == NULL)
1355 goto out; 1413 goto out;
@@ -1386,7 +1444,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
1386 */ 1444 */
1387 goto out_free_stack; 1445 goto out_free_stack;
1388 case 'a': 1446 case 'a':
1389 if (!browser->has_symbols) { 1447 if (!sort__has_sym) {
1390 ui_browser__warning(&browser->b, delay_secs * 2, 1448 ui_browser__warning(&browser->b, delay_secs * 2,
1391 "Annotation is only available for symbolic views, " 1449 "Annotation is only available for symbolic views, "
1392 "include \"sym*\" in --sort to use it."); 1450 "include \"sym*\" in --sort to use it.");
@@ -1485,10 +1543,10 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
1485 continue; 1543 continue;
1486 } 1544 }
1487 1545
1488 if (!browser->has_symbols) 1546 if (!sort__has_sym)
1489 goto add_exit_option; 1547 goto add_exit_option;
1490 1548
1491 if (sort__branch_mode == 1) { 1549 if (sort__mode == SORT_MODE__BRANCH) {
1492 bi = browser->he_selection->branch_info; 1550 bi = browser->he_selection->branch_info;
1493 if (browser->selection != NULL && 1551 if (browser->selection != NULL &&
1494 bi && 1552 bi &&
@@ -1689,6 +1747,7 @@ struct perf_evsel_menu {
1689 struct ui_browser b; 1747 struct ui_browser b;
1690 struct perf_evsel *selection; 1748 struct perf_evsel *selection;
1691 bool lost_events, lost_events_warned; 1749 bool lost_events, lost_events_warned;
1750 float min_pcnt;
1692 struct perf_session_env *env; 1751 struct perf_session_env *env;
1693}; 1752};
1694 1753
@@ -1782,6 +1841,7 @@ browse_hists:
1782 ev_name = perf_evsel__name(pos); 1841 ev_name = perf_evsel__name(pos);
1783 key = perf_evsel__hists_browse(pos, nr_events, help, 1842 key = perf_evsel__hists_browse(pos, nr_events, help,
1784 ev_name, true, hbt, 1843 ev_name, true, hbt,
1844 menu->min_pcnt,
1785 menu->env); 1845 menu->env);
1786 ui_browser__show_title(&menu->b, title); 1846 ui_browser__show_title(&menu->b, title);
1787 switch (key) { 1847 switch (key) {
@@ -1843,6 +1903,7 @@ static bool filter_group_entries(struct ui_browser *self __maybe_unused,
1843static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, 1903static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
1844 int nr_entries, const char *help, 1904 int nr_entries, const char *help,
1845 struct hist_browser_timer *hbt, 1905 struct hist_browser_timer *hbt,
1906 float min_pcnt,
1846 struct perf_session_env *env) 1907 struct perf_session_env *env)
1847{ 1908{
1848 struct perf_evsel *pos; 1909 struct perf_evsel *pos;
@@ -1856,6 +1917,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
1856 .nr_entries = nr_entries, 1917 .nr_entries = nr_entries,
1857 .priv = evlist, 1918 .priv = evlist,
1858 }, 1919 },
1920 .min_pcnt = min_pcnt,
1859 .env = env, 1921 .env = env,
1860 }; 1922 };
1861 1923
@@ -1874,6 +1936,7 @@ static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist,
1874 1936
1875int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, 1937int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
1876 struct hist_browser_timer *hbt, 1938 struct hist_browser_timer *hbt,
1939 float min_pcnt,
1877 struct perf_session_env *env) 1940 struct perf_session_env *env)
1878{ 1941{
1879 int nr_entries = evlist->nr_entries; 1942 int nr_entries = evlist->nr_entries;
@@ -1885,7 +1948,8 @@ single_entry:
1885 const char *ev_name = perf_evsel__name(first); 1948 const char *ev_name = perf_evsel__name(first);
1886 1949
1887 return perf_evsel__hists_browse(first, nr_entries, help, 1950 return perf_evsel__hists_browse(first, nr_entries, help,
1888 ev_name, false, hbt, env); 1951 ev_name, false, hbt, min_pcnt,
1952 env);
1889 } 1953 }
1890 1954
1891 if (symbol_conf.event_group) { 1955 if (symbol_conf.event_group) {
@@ -1901,5 +1965,5 @@ single_entry:
1901 } 1965 }
1902 1966
1903 return __perf_evlist__tui_browse_hists(evlist, nr_entries, help, 1967 return __perf_evlist__tui_browse_hists(evlist, nr_entries, help,
1904 hbt, env); 1968 hbt, min_pcnt, env);
1905} 1969}
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 6f259b3d14e2..9708dd5fb8f3 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -124,7 +124,8 @@ void perf_gtk__init_hpp(void)
124 perf_gtk__hpp_color_overhead_guest_us; 124 perf_gtk__hpp_color_overhead_guest_us;
125} 125}
126 126
127static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) 127static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
128 float min_pcnt)
128{ 129{
129 struct perf_hpp_fmt *fmt; 130 struct perf_hpp_fmt *fmt;
130 GType col_types[MAX_COLUMNS]; 131 GType col_types[MAX_COLUMNS];
@@ -189,10 +190,15 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
189 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { 190 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
190 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 191 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
191 GtkTreeIter iter; 192 GtkTreeIter iter;
193 float percent = h->stat.period * 100.0 /
194 hists->stats.total_period;
192 195
193 if (h->filtered) 196 if (h->filtered)
194 continue; 197 continue;
195 198
199 if (percent < min_pcnt)
200 continue;
201
196 gtk_list_store_append(store, &iter); 202 gtk_list_store_append(store, &iter);
197 203
198 col_idx = 0; 204 col_idx = 0;
@@ -222,7 +228,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
222 228
223int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, 229int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
224 const char *help, 230 const char *help,
225 struct hist_browser_timer *hbt __maybe_unused) 231 struct hist_browser_timer *hbt __maybe_unused,
232 float min_pcnt)
226{ 233{
227 struct perf_evsel *pos; 234 struct perf_evsel *pos;
228 GtkWidget *vbox; 235 GtkWidget *vbox;
@@ -286,7 +293,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
286 GTK_POLICY_AUTOMATIC, 293 GTK_POLICY_AUTOMATIC,
287 GTK_POLICY_AUTOMATIC); 294 GTK_POLICY_AUTOMATIC);
288 295
289 perf_gtk__show_hists(scrolled_window, hists); 296 perf_gtk__show_hists(scrolled_window, hists, min_pcnt);
290 297
291 tab_label = gtk_label_new(evname); 298 tab_label = gtk_label_new(evname);
292 299
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index ff1f60cf442e..ae7a75432249 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -334,7 +334,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
334} 334}
335 335
336size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, 336size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
337 int max_cols, FILE *fp) 337 int max_cols, float min_pcnt, FILE *fp)
338{ 338{
339 struct perf_hpp_fmt *fmt; 339 struct perf_hpp_fmt *fmt;
340 struct sort_entry *se; 340 struct sort_entry *se;
@@ -440,10 +440,15 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
440print_entries: 440print_entries:
441 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { 441 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
442 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 442 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
443 float percent = h->stat.period * 100.0 /
444 hists->stats.total_period;
443 445
444 if (h->filtered) 446 if (h->filtered)
445 continue; 447 continue;
446 448
449 if (percent < min_pcnt)
450 continue;
451
447 ret += hist_entry__fprintf(h, max_cols, hists, fp); 452 ret += hist_entry__fprintf(h, max_cols, hists, fp);
448 453
449 if (max_rows && ++nr_rows >= max_rows) 454 if (max_rows && ++nr_rows >= max_rows)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f7c727801aab..99b43dd18c57 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -776,6 +776,8 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,
776 if (pipe_output) 776 if (pipe_output)
777 dup2(2, 1); 777 dup2(2, 1);
778 778
779 signal(SIGTERM, SIG_DFL);
780
779 close(child_ready_pipe[0]); 781 close(child_ready_pipe[0]);
780 close(go_pipe[1]); 782 close(go_pipe[1]);
781 fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); 783 fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 07b1a3ad3e24..63b6f8c8edf2 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1514,7 +1514,7 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel,
1514 switch (err) { 1514 switch (err) {
1515 case EPERM: 1515 case EPERM:
1516 case EACCES: 1516 case EACCES:
1517 return scnprintf(msg, size, "%s", 1517 return scnprintf(msg, size,
1518 "You may not have permission to collect %sstats.\n" 1518 "You may not have permission to collect %sstats.\n"
1519 "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" 1519 "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
1520 " -1 - Not paranoid at all\n" 1520 " -1 - Not paranoid at all\n"
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 326068a593a5..738d3b8d9745 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2391,7 +2391,6 @@ out_err_write:
2391 } 2391 }
2392 lseek(fd, header->data_offset + header->data_size, SEEK_SET); 2392 lseek(fd, header->data_offset + header->data_size, SEEK_SET);
2393 2393
2394 header->frozen = 1;
2395 return 0; 2394 return 0;
2396} 2395}
2397 2396
@@ -2871,7 +2870,6 @@ int perf_session__read_header(struct perf_session *session, int fd)
2871 session->pevent)) 2870 session->pevent))
2872 goto out_delete_evlist; 2871 goto out_delete_evlist;
2873 2872
2874 header->frozen = 1;
2875 return 0; 2873 return 0;
2876out_errno: 2874out_errno:
2877 return -errno; 2875 return -errno;
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index c9fc55cada6d..16a3e83c584e 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -84,7 +84,6 @@ struct perf_session_env {
84}; 84};
85 85
86struct perf_header { 86struct perf_header {
87 int frozen;
88 bool needs_swap; 87 bool needs_swap;
89 s64 attr_offset; 88 s64 attr_offset;
90 u64 data_offset; 89 u64 data_offset;
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 6b32721f829a..b11a6cfdb414 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -70,9 +70,17 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
70 int symlen; 70 int symlen;
71 u16 len; 71 u16 len;
72 72
73 if (h->ms.sym) 73 /*
74 hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4); 74 * +4 accounts for '[x] ' priv level info
75 else { 75 * +2 accounts for 0x prefix on raw addresses
76 * +3 accounts for ' y ' symtab origin info
77 */
78 if (h->ms.sym) {
79 symlen = h->ms.sym->namelen + 4;
80 if (verbose)
81 symlen += BITS_PER_LONG / 4 + 2 + 3;
82 hists__new_col_len(hists, HISTC_SYMBOL, symlen);
83 } else {
76 symlen = unresolved_col_width + 4 + 2; 84 symlen = unresolved_col_width + 4 + 2;
77 hists__new_col_len(hists, HISTC_SYMBOL, symlen); 85 hists__new_col_len(hists, HISTC_SYMBOL, symlen);
78 hists__set_unres_dso_col_len(hists, HISTC_DSO); 86 hists__set_unres_dso_col_len(hists, HISTC_DSO);
@@ -91,12 +99,10 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
91 hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen); 99 hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen);
92 100
93 if (h->branch_info) { 101 if (h->branch_info) {
94 /*
95 * +4 accounts for '[x] ' priv level info
96 * +2 account of 0x prefix on raw addresses
97 */
98 if (h->branch_info->from.sym) { 102 if (h->branch_info->from.sym) {
99 symlen = (int)h->branch_info->from.sym->namelen + 4; 103 symlen = (int)h->branch_info->from.sym->namelen + 4;
104 if (verbose)
105 symlen += BITS_PER_LONG / 4 + 2 + 3;
100 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); 106 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
101 107
102 symlen = dso__name_len(h->branch_info->from.map->dso); 108 symlen = dso__name_len(h->branch_info->from.map->dso);
@@ -109,6 +115,8 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
109 115
110 if (h->branch_info->to.sym) { 116 if (h->branch_info->to.sym) {
111 symlen = (int)h->branch_info->to.sym->namelen + 4; 117 symlen = (int)h->branch_info->to.sym->namelen + 4;
118 if (verbose)
119 symlen += BITS_PER_LONG / 4 + 2 + 3;
112 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); 120 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
113 121
114 symlen = dso__name_len(h->branch_info->to.map->dso); 122 symlen = dso__name_len(h->branch_info->to.map->dso);
@@ -121,10 +129,6 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
121 } 129 }
122 130
123 if (h->mem_info) { 131 if (h->mem_info) {
124 /*
125 * +4 accounts for '[x] ' priv level info
126 * +2 account of 0x prefix on raw addresses
127 */
128 if (h->mem_info->daddr.sym) { 132 if (h->mem_info->daddr.sym) {
129 symlen = (int)h->mem_info->daddr.sym->namelen + 4 133 symlen = (int)h->mem_info->daddr.sym->namelen + 4
130 + unresolved_col_width + 2; 134 + unresolved_col_width + 2;
@@ -236,8 +240,7 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
236 return he->stat.period == 0; 240 return he->stat.period == 0;
237} 241}
238 242
239static void __hists__decay_entries(struct hists *hists, bool zap_user, 243void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
240 bool zap_kernel, bool threaded)
241{ 244{
242 struct rb_node *next = rb_first(&hists->entries); 245 struct rb_node *next = rb_first(&hists->entries);
243 struct hist_entry *n; 246 struct hist_entry *n;
@@ -256,7 +259,7 @@ static void __hists__decay_entries(struct hists *hists, bool zap_user,
256 !n->used) { 259 !n->used) {
257 rb_erase(&n->rb_node, &hists->entries); 260 rb_erase(&n->rb_node, &hists->entries);
258 261
259 if (sort__need_collapse || threaded) 262 if (sort__need_collapse)
260 rb_erase(&n->rb_node_in, &hists->entries_collapsed); 263 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
261 264
262 hist_entry__free(n); 265 hist_entry__free(n);
@@ -265,17 +268,6 @@ static void __hists__decay_entries(struct hists *hists, bool zap_user,
265 } 268 }
266} 269}
267 270
268void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
269{
270 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
271}
272
273void hists__decay_entries_threaded(struct hists *hists,
274 bool zap_user, bool zap_kernel)
275{
276 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
277}
278
279/* 271/*
280 * histogram, sorted on item, collects periods 272 * histogram, sorted on item, collects periods
281 */ 273 */
@@ -292,6 +284,20 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
292 he->ms.map->referenced = true; 284 he->ms.map->referenced = true;
293 285
294 if (he->branch_info) { 286 if (he->branch_info) {
287 /*
288 * This branch info is (a part of) allocated from
289 * machine__resolve_bstack() and will be freed after
290 * adding new entries. So we need to save a copy.
291 */
292 he->branch_info = malloc(sizeof(*he->branch_info));
293 if (he->branch_info == NULL) {
294 free(he);
295 return NULL;
296 }
297
298 memcpy(he->branch_info, template->branch_info,
299 sizeof(*he->branch_info));
300
295 if (he->branch_info->from.map) 301 if (he->branch_info->from.map)
296 he->branch_info->from.map->referenced = true; 302 he->branch_info->from.map->referenced = true;
297 if (he->branch_info->to.map) 303 if (he->branch_info->to.map)
@@ -341,8 +347,6 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
341 struct hist_entry *he; 347 struct hist_entry *he;
342 int cmp; 348 int cmp;
343 349
344 pthread_mutex_lock(&hists->lock);
345
346 p = &hists->entries_in->rb_node; 350 p = &hists->entries_in->rb_node;
347 351
348 while (*p != NULL) { 352 while (*p != NULL) {
@@ -360,6 +364,12 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
360 if (!cmp) { 364 if (!cmp) {
361 he_stat__add_period(&he->stat, period, weight); 365 he_stat__add_period(&he->stat, period, weight);
362 366
367 /*
368 * This mem info was allocated from machine__resolve_mem
369 * and will not be used anymore.
370 */
371 free(entry->mem_info);
372
363 /* If the map of an existing hist_entry has 373 /* If the map of an existing hist_entry has
364 * become out-of-date due to an exec() or 374 * become out-of-date due to an exec() or
365 * similar, update it. Otherwise we will 375 * similar, update it. Otherwise we will
@@ -382,14 +392,12 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
382 392
383 he = hist_entry__new(entry); 393 he = hist_entry__new(entry);
384 if (!he) 394 if (!he)
385 goto out_unlock; 395 return NULL;
386 396
387 rb_link_node(&he->rb_node_in, parent, p); 397 rb_link_node(&he->rb_node_in, parent, p);
388 rb_insert_color(&he->rb_node_in, hists->entries_in); 398 rb_insert_color(&he->rb_node_in, hists->entries_in);
389out: 399out:
390 hist_entry__add_cpumode_period(he, al->cpumode, period); 400 hist_entry__add_cpumode_period(he, al->cpumode, period);
391out_unlock:
392 pthread_mutex_unlock(&hists->lock);
393 return he; 401 return he;
394} 402}
395 403
@@ -589,13 +597,13 @@ static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
589 hists__filter_entry_by_symbol(hists, he); 597 hists__filter_entry_by_symbol(hists, he);
590} 598}
591 599
592static void __hists__collapse_resort(struct hists *hists, bool threaded) 600void hists__collapse_resort(struct hists *hists)
593{ 601{
594 struct rb_root *root; 602 struct rb_root *root;
595 struct rb_node *next; 603 struct rb_node *next;
596 struct hist_entry *n; 604 struct hist_entry *n;
597 605
598 if (!sort__need_collapse && !threaded) 606 if (!sort__need_collapse)
599 return; 607 return;
600 608
601 root = hists__get_rotate_entries_in(hists); 609 root = hists__get_rotate_entries_in(hists);
@@ -617,16 +625,6 @@ static void __hists__collapse_resort(struct hists *hists, bool threaded)
617 } 625 }
618} 626}
619 627
620void hists__collapse_resort(struct hists *hists)
621{
622 return __hists__collapse_resort(hists, false);
623}
624
625void hists__collapse_resort_threaded(struct hists *hists)
626{
627 return __hists__collapse_resort(hists, true);
628}
629
630/* 628/*
631 * reverse the map, sort on period. 629 * reverse the map, sort on period.
632 */ 630 */
@@ -713,7 +711,7 @@ static void __hists__insert_output_entry(struct rb_root *entries,
713 rb_insert_color(&he->rb_node, entries); 711 rb_insert_color(&he->rb_node, entries);
714} 712}
715 713
716static void __hists__output_resort(struct hists *hists, bool threaded) 714void hists__output_resort(struct hists *hists)
717{ 715{
718 struct rb_root *root; 716 struct rb_root *root;
719 struct rb_node *next; 717 struct rb_node *next;
@@ -722,7 +720,7 @@ static void __hists__output_resort(struct hists *hists, bool threaded)
722 720
723 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); 721 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
724 722
725 if (sort__need_collapse || threaded) 723 if (sort__need_collapse)
726 root = &hists->entries_collapsed; 724 root = &hists->entries_collapsed;
727 else 725 else
728 root = hists->entries_in; 726 root = hists->entries_in;
@@ -743,16 +741,6 @@ static void __hists__output_resort(struct hists *hists, bool threaded)
743 } 741 }
744} 742}
745 743
746void hists__output_resort(struct hists *hists)
747{
748 return __hists__output_resort(hists, false);
749}
750
751void hists__output_resort_threaded(struct hists *hists)
752{
753 return __hists__output_resort(hists, true);
754}
755
756static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h, 744static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
757 enum hist_filter filter) 745 enum hist_filter filter)
758{ 746{
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 14c2fe20aa62..2d3790fd99bb 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -43,12 +43,12 @@ enum hist_column {
43 HISTC_COMM, 43 HISTC_COMM,
44 HISTC_PARENT, 44 HISTC_PARENT,
45 HISTC_CPU, 45 HISTC_CPU,
46 HISTC_SRCLINE,
46 HISTC_MISPREDICT, 47 HISTC_MISPREDICT,
47 HISTC_SYMBOL_FROM, 48 HISTC_SYMBOL_FROM,
48 HISTC_SYMBOL_TO, 49 HISTC_SYMBOL_TO,
49 HISTC_DSO_FROM, 50 HISTC_DSO_FROM,
50 HISTC_DSO_TO, 51 HISTC_DSO_TO,
51 HISTC_SRCLINE,
52 HISTC_LOCAL_WEIGHT, 52 HISTC_LOCAL_WEIGHT,
53 HISTC_GLOBAL_WEIGHT, 53 HISTC_GLOBAL_WEIGHT,
54 HISTC_MEM_DADDR_SYMBOL, 54 HISTC_MEM_DADDR_SYMBOL,
@@ -104,13 +104,9 @@ struct hist_entry *__hists__add_mem_entry(struct hists *self,
104 u64 weight); 104 u64 weight);
105 105
106void hists__output_resort(struct hists *self); 106void hists__output_resort(struct hists *self);
107void hists__output_resort_threaded(struct hists *hists);
108void hists__collapse_resort(struct hists *self); 107void hists__collapse_resort(struct hists *self);
109void hists__collapse_resort_threaded(struct hists *hists);
110 108
111void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel); 109void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
112void hists__decay_entries_threaded(struct hists *hists, bool zap_user,
113 bool zap_kernel);
114void hists__output_recalc_col_len(struct hists *hists, int max_rows); 110void hists__output_recalc_col_len(struct hists *hists, int max_rows);
115 111
116void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h); 112void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h);
@@ -119,7 +115,7 @@ void events_stats__inc(struct events_stats *stats, u32 type);
119size_t events_stats__fprintf(struct events_stats *stats, FILE *fp); 115size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
120 116
121size_t hists__fprintf(struct hists *self, bool show_header, int max_rows, 117size_t hists__fprintf(struct hists *self, bool show_header, int max_rows,
122 int max_cols, FILE *fp); 118 int max_cols, float min_pcnt, FILE *fp);
123 119
124int hist_entry__inc_addr_samples(struct hist_entry *self, int evidx, u64 addr); 120int hist_entry__inc_addr_samples(struct hist_entry *self, int evidx, u64 addr);
125int hist_entry__annotate(struct hist_entry *self, size_t privsize); 121int hist_entry__annotate(struct hist_entry *self, size_t privsize);
@@ -199,6 +195,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
199 195
200int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, 196int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
201 struct hist_browser_timer *hbt, 197 struct hist_browser_timer *hbt,
198 float min_pcnt,
202 struct perf_session_env *env); 199 struct perf_session_env *env);
203int script_browse(const char *script_opt); 200int script_browse(const char *script_opt);
204#else 201#else
@@ -206,6 +203,7 @@ static inline
206int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, 203int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
207 const char *help __maybe_unused, 204 const char *help __maybe_unused,
208 struct hist_browser_timer *hbt __maybe_unused, 205 struct hist_browser_timer *hbt __maybe_unused,
206 float min_pcnt __maybe_unused,
209 struct perf_session_env *env __maybe_unused) 207 struct perf_session_env *env __maybe_unused)
210{ 208{
211 return 0; 209 return 0;
@@ -233,12 +231,14 @@ static inline int script_browse(const char *script_opt __maybe_unused)
233 231
234#ifdef GTK2_SUPPORT 232#ifdef GTK2_SUPPORT
235int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help, 233int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help,
236 struct hist_browser_timer *hbt __maybe_unused); 234 struct hist_browser_timer *hbt __maybe_unused,
235 float min_pcnt);
237#else 236#else
238static inline 237static inline
239int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused, 238int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused,
240 const char *help __maybe_unused, 239 const char *help __maybe_unused,
241 struct hist_browser_timer *hbt __maybe_unused) 240 struct hist_browser_timer *hbt __maybe_unused,
241 float min_pcnt __maybe_unused)
242{ 242{
243 return 0; 243 return 0;
244} 244}
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 6fcb9de62340..8bcdf9e54089 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -21,6 +21,7 @@ const char *map_type__name[MAP__NR_TYPES] = {
21static inline int is_anon_memory(const char *filename) 21static inline int is_anon_memory(const char *filename)
22{ 22{
23 return !strcmp(filename, "//anon") || 23 return !strcmp(filename, "//anon") ||
24 !strcmp(filename, "/dev/zero (deleted)") ||
24 !strcmp(filename, "/anon_hugepage (deleted)"); 25 !strcmp(filename, "/anon_hugepage (deleted)");
25} 26}
26 27
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 6b51d47acdba..f3b235ec7bf4 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -37,7 +37,6 @@ struct perf_session {
37 int fd; 37 int fd;
38 bool fd_pipe; 38 bool fd_pipe;
39 bool repipe; 39 bool repipe;
40 int cwdlen;
41 char *cwd; 40 char *cwd;
42 struct ordered_samples ordered_samples; 41 struct ordered_samples ordered_samples;
43 char filename[1]; 42 char filename[1];
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 6b0ed322907e..58ea5ca6c255 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -18,8 +18,9 @@ class install_lib(_install_lib):
18 self.build_dir = build_lib 18 self.build_dir = build_lib
19 19
20 20
21cflags = ['-fno-strict-aliasing', '-Wno-write-strings'] 21cflags = getenv('CFLAGS', '').split()
22cflags += getenv('CFLAGS', '').split() 22# switch off several checks (need to be at the end of cflags list)
23cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter' ]
23 24
24build_lib = getenv('PYTHON_EXTBUILD_LIB') 25build_lib = getenv('PYTHON_EXTBUILD_LIB')
25build_tmp = getenv('PYTHON_EXTBUILD_TMP') 26build_tmp = getenv('PYTHON_EXTBUILD_TMP')
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 5f52d492590c..313a5a730112 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1,5 +1,6 @@
1#include "sort.h" 1#include "sort.h"
2#include "hist.h" 2#include "hist.h"
3#include "symbol.h"
3 4
4regex_t parent_regex; 5regex_t parent_regex;
5const char default_parent_pattern[] = "^sys_|^do_page_fault"; 6const char default_parent_pattern[] = "^sys_|^do_page_fault";
@@ -9,7 +10,7 @@ const char *sort_order = default_sort_order;
9int sort__need_collapse = 0; 10int sort__need_collapse = 0;
10int sort__has_parent = 0; 11int sort__has_parent = 0;
11int sort__has_sym = 0; 12int sort__has_sym = 0;
12int sort__branch_mode = -1; /* -1 = means not set */ 13enum sort_mode sort__mode = SORT_MODE__NORMAL;
13 14
14enum sort_type sort__first_dimension; 15enum sort_type sort__first_dimension;
15 16
@@ -194,7 +195,7 @@ static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
194 if (verbose) { 195 if (verbose) {
195 char o = map ? dso__symtab_origin(map->dso) : '!'; 196 char o = map ? dso__symtab_origin(map->dso) : '!';
196 ret += repsep_snprintf(bf, size, "%-#*llx %c ", 197 ret += repsep_snprintf(bf, size, "%-#*llx %c ",
197 BITS_PER_LONG / 4, ip, o); 198 BITS_PER_LONG / 4 + 2, ip, o);
198 } 199 }
199 200
200 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level); 201 ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level);
@@ -871,14 +872,6 @@ static struct sort_dimension common_sort_dimensions[] = {
871 DIM(SORT_PARENT, "parent", sort_parent), 872 DIM(SORT_PARENT, "parent", sort_parent),
872 DIM(SORT_CPU, "cpu", sort_cpu), 873 DIM(SORT_CPU, "cpu", sort_cpu),
873 DIM(SORT_SRCLINE, "srcline", sort_srcline), 874 DIM(SORT_SRCLINE, "srcline", sort_srcline),
874 DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
875 DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
876 DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym),
877 DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso),
878 DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked),
879 DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb),
880 DIM(SORT_MEM_LVL, "mem", sort_mem_lvl),
881 DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop),
882}; 875};
883 876
884#undef DIM 877#undef DIM
@@ -895,6 +888,36 @@ static struct sort_dimension bstack_sort_dimensions[] = {
895 888
896#undef DIM 889#undef DIM
897 890
891#define DIM(d, n, func) [d - __SORT_MEMORY_MODE] = { .name = n, .entry = &(func) }
892
893static struct sort_dimension memory_sort_dimensions[] = {
894 DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
895 DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
896 DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym),
897 DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso),
898 DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked),
899 DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb),
900 DIM(SORT_MEM_LVL, "mem", sort_mem_lvl),
901 DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop),
902};
903
904#undef DIM
905
906static void __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
907{
908 if (sd->taken)
909 return;
910
911 if (sd->entry->se_collapse)
912 sort__need_collapse = 1;
913
914 if (list_empty(&hist_entry__sort_list))
915 sort__first_dimension = idx;
916
917 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
918 sd->taken = 1;
919}
920
898int sort_dimension__add(const char *tok) 921int sort_dimension__add(const char *tok)
899{ 922{
900 unsigned int i; 923 unsigned int i;
@@ -915,25 +938,11 @@ int sort_dimension__add(const char *tok)
915 return -EINVAL; 938 return -EINVAL;
916 } 939 }
917 sort__has_parent = 1; 940 sort__has_parent = 1;
918 } else if (sd->entry == &sort_sym || 941 } else if (sd->entry == &sort_sym) {
919 sd->entry == &sort_sym_from ||
920 sd->entry == &sort_sym_to ||
921 sd->entry == &sort_mem_daddr_sym) {
922 sort__has_sym = 1; 942 sort__has_sym = 1;
923 } 943 }
924 944
925 if (sd->taken) 945 __sort_dimension__add(sd, i);
926 return 0;
927
928 if (sd->entry->se_collapse)
929 sort__need_collapse = 1;
930
931 if (list_empty(&hist_entry__sort_list))
932 sort__first_dimension = i;
933
934 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
935 sd->taken = 1;
936
937 return 0; 946 return 0;
938 } 947 }
939 948
@@ -943,24 +952,29 @@ int sort_dimension__add(const char *tok)
943 if (strncasecmp(tok, sd->name, strlen(tok))) 952 if (strncasecmp(tok, sd->name, strlen(tok)))
944 continue; 953 continue;
945 954
946 if (sort__branch_mode != 1) 955 if (sort__mode != SORT_MODE__BRANCH)
947 return -EINVAL; 956 return -EINVAL;
948 957
949 if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to) 958 if (sd->entry == &sort_sym_from || sd->entry == &sort_sym_to)
950 sort__has_sym = 1; 959 sort__has_sym = 1;
951 960
952 if (sd->taken) 961 __sort_dimension__add(sd, i + __SORT_BRANCH_STACK);
953 return 0; 962 return 0;
963 }
954 964
955 if (sd->entry->se_collapse) 965 for (i = 0; i < ARRAY_SIZE(memory_sort_dimensions); i++) {
956 sort__need_collapse = 1; 966 struct sort_dimension *sd = &memory_sort_dimensions[i];
957 967
958 if (list_empty(&hist_entry__sort_list)) 968 if (strncasecmp(tok, sd->name, strlen(tok)))
959 sort__first_dimension = i + __SORT_BRANCH_STACK; 969 continue;
960 970
961 list_add_tail(&sd->entry->list, &hist_entry__sort_list); 971 if (sort__mode != SORT_MODE__MEMORY)
962 sd->taken = 1; 972 return -EINVAL;
973
974 if (sd->entry == &sort_mem_daddr_sym)
975 sort__has_sym = 1;
963 976
977 __sort_dimension__add(sd, i + __SORT_MEMORY_MODE);
964 return 0; 978 return 0;
965 } 979 }
966 980
@@ -993,8 +1007,9 @@ int setup_sorting(void)
993 return ret; 1007 return ret;
994} 1008}
995 1009
996void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list, 1010static void sort_entry__setup_elide(struct sort_entry *self,
997 const char *list_name, FILE *fp) 1011 struct strlist *list,
1012 const char *list_name, FILE *fp)
998{ 1013{
999 if (list && strlist__nr_entries(list) == 1) { 1014 if (list && strlist__nr_entries(list) == 1) {
1000 if (fp != NULL) 1015 if (fp != NULL)
@@ -1003,3 +1018,42 @@ void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
1003 self->elide = true; 1018 self->elide = true;
1004 } 1019 }
1005} 1020}
1021
1022void sort__setup_elide(FILE *output)
1023{
1024 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1025 "dso", output);
1026 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list,
1027 "comm", output);
1028 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list,
1029 "symbol", output);
1030
1031 if (sort__mode == SORT_MODE__BRANCH) {
1032 sort_entry__setup_elide(&sort_dso_from,
1033 symbol_conf.dso_from_list,
1034 "dso_from", output);
1035 sort_entry__setup_elide(&sort_dso_to,
1036 symbol_conf.dso_to_list,
1037 "dso_to", output);
1038 sort_entry__setup_elide(&sort_sym_from,
1039 symbol_conf.sym_from_list,
1040 "sym_from", output);
1041 sort_entry__setup_elide(&sort_sym_to,
1042 symbol_conf.sym_to_list,
1043 "sym_to", output);
1044 } else if (sort__mode == SORT_MODE__MEMORY) {
1045 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1046 "symbol_daddr", output);
1047 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1048 "dso_daddr", output);
1049 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1050 "mem", output);
1051 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1052 "local_weight", output);
1053 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1054 "tlb", output);
1055 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list,
1056 "snoop", output);
1057 }
1058
1059}
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index f24bdf64238c..45ac84c1e037 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -32,7 +32,7 @@ extern const char default_sort_order[];
32extern int sort__need_collapse; 32extern int sort__need_collapse;
33extern int sort__has_parent; 33extern int sort__has_parent;
34extern int sort__has_sym; 34extern int sort__has_sym;
35extern int sort__branch_mode; 35extern enum sort_mode sort__mode;
36extern struct sort_entry sort_comm; 36extern struct sort_entry sort_comm;
37extern struct sort_entry sort_dso; 37extern struct sort_entry sort_dso;
38extern struct sort_entry sort_sym; 38extern struct sort_entry sort_sym;
@@ -117,12 +117,18 @@ static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
117 return NULL; 117 return NULL;
118} 118}
119 119
120static inline void hist_entry__add_pair(struct hist_entry *he, 120static inline void hist_entry__add_pair(struct hist_entry *pair,
121 struct hist_entry *pair) 121 struct hist_entry *he)
122{ 122{
123 list_add_tail(&he->pairs.head, &pair->pairs.node); 123 list_add_tail(&pair->pairs.node, &he->pairs.head);
124} 124}
125 125
126enum sort_mode {
127 SORT_MODE__NORMAL,
128 SORT_MODE__BRANCH,
129 SORT_MODE__MEMORY,
130};
131
126enum sort_type { 132enum sort_type {
127 /* common sort keys */ 133 /* common sort keys */
128 SORT_PID, 134 SORT_PID,
@@ -132,14 +138,6 @@ enum sort_type {
132 SORT_PARENT, 138 SORT_PARENT,
133 SORT_CPU, 139 SORT_CPU,
134 SORT_SRCLINE, 140 SORT_SRCLINE,
135 SORT_LOCAL_WEIGHT,
136 SORT_GLOBAL_WEIGHT,
137 SORT_MEM_DADDR_SYMBOL,
138 SORT_MEM_DADDR_DSO,
139 SORT_MEM_LOCKED,
140 SORT_MEM_TLB,
141 SORT_MEM_LVL,
142 SORT_MEM_SNOOP,
143 141
144 /* branch stack specific sort keys */ 142 /* branch stack specific sort keys */
145 __SORT_BRANCH_STACK, 143 __SORT_BRANCH_STACK,
@@ -148,6 +146,17 @@ enum sort_type {
148 SORT_SYM_FROM, 146 SORT_SYM_FROM,
149 SORT_SYM_TO, 147 SORT_SYM_TO,
150 SORT_MISPREDICT, 148 SORT_MISPREDICT,
149
150 /* memory mode specific sort keys */
151 __SORT_MEMORY_MODE,
152 SORT_LOCAL_WEIGHT = __SORT_MEMORY_MODE,
153 SORT_GLOBAL_WEIGHT,
154 SORT_MEM_DADDR_SYMBOL,
155 SORT_MEM_DADDR_DSO,
156 SORT_MEM_LOCKED,
157 SORT_MEM_TLB,
158 SORT_MEM_LVL,
159 SORT_MEM_SNOOP,
151}; 160};
152 161
153/* 162/*
@@ -172,7 +181,6 @@ extern struct list_head hist_entry__sort_list;
172 181
173int setup_sorting(void); 182int setup_sorting(void);
174extern int sort_dimension__add(const char *); 183extern int sort_dimension__add(const char *);
175void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list, 184void sort__setup_elide(FILE *fp);
176 const char *list_name, FILE *fp);
177 185
178#endif /* __PERF_SORT_H */ 186#endif /* __PERF_SORT_H */
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 23742126f47c..7c59c28afcc5 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -37,7 +37,7 @@ double stddev_stats(struct stats *stats)
37{ 37{
38 double variance, variance_mean; 38 double variance, variance_mean;
39 39
40 if (!stats->n) 40 if (stats->n < 2)
41 return 0.0; 41 return 0.0;
42 42
43 variance = stats->M2 / (stats->n - 1); 43 variance = stats->M2 / (stats->n - 1);
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 632e40e5ceca..40399cbcca77 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -14,6 +14,7 @@ struct thread *thread__new(pid_t pid)
14 if (self != NULL) { 14 if (self != NULL) {
15 map_groups__init(&self->mg); 15 map_groups__init(&self->mg);
16 self->pid = pid; 16 self->pid = pid;
17 self->ppid = -1;
17 self->comm = malloc(32); 18 self->comm = malloc(32);
18 if (self->comm) 19 if (self->comm)
19 snprintf(self->comm, 32, ":%d", self->pid); 20 snprintf(self->comm, 32, ":%d", self->pid);
@@ -82,5 +83,8 @@ int thread__fork(struct thread *self, struct thread *parent)
82 for (i = 0; i < MAP__NR_TYPES; ++i) 83 for (i = 0; i < MAP__NR_TYPES; ++i)
83 if (map_groups__clone(&self->mg, &parent->mg, i) < 0) 84 if (map_groups__clone(&self->mg, &parent->mg, i) < 0)
84 return -ENOMEM; 85 return -ENOMEM;
86
87 self->ppid = parent->pid;
88
85 return 0; 89 return 0;
86} 90}
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 5ad266403098..eeb7ac62b9e3 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -13,6 +13,7 @@ struct thread {
13 }; 13 };
14 struct map_groups mg; 14 struct map_groups mg;
15 pid_t pid; 15 pid_t pid;
16 pid_t ppid;
16 char shortname[3]; 17 char shortname[3];
17 bool comm_set; 18 bool comm_set;
18 char *comm; 19 char *comm;
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 54d37a4753c5..f857b51b6bde 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -23,20 +23,31 @@
23 23
24size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size) 24size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
25{ 25{
26 float samples_per_sec = top->samples / top->delay_secs; 26 float samples_per_sec;
27 float ksamples_per_sec = top->kernel_samples / top->delay_secs; 27 float ksamples_per_sec;
28 float esamples_percent = (100.0 * top->exact_samples) / top->samples; 28 float esamples_percent;
29 struct perf_record_opts *opts = &top->record_opts; 29 struct perf_record_opts *opts = &top->record_opts;
30 struct perf_target *target = &opts->target; 30 struct perf_target *target = &opts->target;
31 size_t ret = 0; 31 size_t ret = 0;
32 32
33 if (top->samples) {
34 samples_per_sec = top->samples / top->delay_secs;
35 ksamples_per_sec = top->kernel_samples / top->delay_secs;
36 esamples_percent = (100.0 * top->exact_samples) / top->samples;
37 } else {
38 samples_per_sec = ksamples_per_sec = esamples_percent = 0.0;
39 }
40
33 if (!perf_guest) { 41 if (!perf_guest) {
42 float ksamples_percent = 0.0;
43
44 if (samples_per_sec)
45 ksamples_percent = (100.0 * ksamples_per_sec) /
46 samples_per_sec;
34 ret = SNPRINTF(bf, size, 47 ret = SNPRINTF(bf, size,
35 " PerfTop:%8.0f irqs/sec kernel:%4.1f%%" 48 " PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
36 " exact: %4.1f%% [", samples_per_sec, 49 " exact: %4.1f%% [", samples_per_sec,
37 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) / 50 ksamples_percent, esamples_percent);
38 samples_per_sec)),
39 esamples_percent);
40 } else { 51 } else {
41 float us_samples_per_sec = top->us_samples / top->delay_secs; 52 float us_samples_per_sec = top->us_samples / top->delay_secs;
42 float guest_kernel_samples_per_sec = top->guest_kernel_samples / top->delay_secs; 53 float guest_kernel_samples_per_sec = top->guest_kernel_samples / top->delay_secs;
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index 7ebf357dc9e1..df46be93d902 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -26,7 +26,6 @@ struct perf_top {
26 int print_entries, count_filter, delay_secs; 26 int print_entries, count_filter, delay_secs;
27 bool hide_kernel_symbols, hide_user_symbols, zero; 27 bool hide_kernel_symbols, hide_user_symbols, zero;
28 bool use_tui, use_stdio; 28 bool use_tui, use_stdio;
29 bool sort_has_symbols;
30 bool kptr_restrict_warned; 29 bool kptr_restrict_warned;
31 bool vmlinux_warned; 30 bool vmlinux_warned;
32 bool dump_symtab; 31 bool dump_symtab;
@@ -37,6 +36,7 @@ struct perf_top {
37 int realtime_prio; 36 int realtime_prio;
38 int sym_pcnt_filter; 37 int sym_pcnt_filter;
39 const char *sym_filter; 38 const char *sym_filter;
39 float min_percent;
40}; 40};
41 41
42size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size); 42size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size);
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index a45710b70a55..7a484c97e500 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -221,8 +221,8 @@ extern unsigned char sane_ctype[256];
221#define isalpha(x) sane_istest(x,GIT_ALPHA) 221#define isalpha(x) sane_istest(x,GIT_ALPHA)
222#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) 222#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
223#define isprint(x) sane_istest(x,GIT_PRINT) 223#define isprint(x) sane_istest(x,GIT_PRINT)
224#define islower(x) (sane_istest(x,GIT_ALPHA) && sane_istest(x,0x20)) 224#define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20))
225#define isupper(x) (sane_istest(x,GIT_ALPHA) && !sane_istest(x,0x20)) 225#define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20))
226#define tolower(x) sane_case((unsigned char)(x), 0x20) 226#define tolower(x) sane_case((unsigned char)(x), 0x20)
227#define toupper(x) sane_case((unsigned char)(x), 0) 227#define toupper(x) sane_case((unsigned char)(x), 0)
228 228