diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-12 22:18:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-12 22:18:49 -0400 |
commit | 3737a12761636ebde0f09ef49daebb8eed18cc8a (patch) | |
tree | 965057f4bccd97049f8c0140f8670c5d4278ca3e /tools | |
parent | c29deef32e3699e40da3e9e82267610de04e6b54 (diff) | |
parent | 82b897782d10fcc4930c9d4a15b175348fdd2871 (diff) |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull more perf updates from Ingo Molnar:
"A second round of perf updates:
- wide reaching kprobes sanitization and robustization, with the hope
of fixing all 'probe this function crashes the kernel' bugs, by
Masami Hiramatsu.
- uprobes updates from Oleg Nesterov: tmpfs support, corner case
fixes and robustization work.
- perf tooling updates and fixes from Jiri Olsa, Namhyung Ki, Arnaldo
et al:
* Add support to accumulate hist periods (Namhyung Kim)
* various fixes, refactorings and enhancements"
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (101 commits)
perf: Differentiate exec() and non-exec() comm events
perf: Fix perf_event_comm() vs. exec() assumption
uprobes/x86: Rename arch_uprobe->def to ->defparam, minor comment updates
perf/documentation: Add description for conditional branch filter
perf/x86: Add conditional branch filtering support
perf/tool: Add conditional branch filter 'cond' to perf record
perf: Add new conditional branch filter 'PERF_SAMPLE_BRANCH_COND'
uprobes: Teach copy_insn() to support tmpfs
uprobes: Shift ->readpage check from __copy_insn() to uprobe_register()
perf/x86: Use common PMU interrupt disabled code
perf/ARM: Use common PMU interrupt disabled code
perf: Disable sampled events if no PMU interrupt
perf: Fix use after free in perf_remove_from_context()
perf tools: Fix 'make help' message error
perf record: Fix poll return value propagation
perf tools: Move elide bool into perf_hpp_fmt struct
perf tools: Remove elide setup for SORT_MODE__MEMORY mode
perf tools: Fix "==" into "=" in ui_browser__warning assignment
perf tools: Allow overriding sysfs and proc finding with env var
perf tools: Consider header files outside perf directory in tags target
...
Diffstat (limited to 'tools')
34 files changed, 1903 insertions, 388 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index 5b5eb788996e..c1b49c36a951 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c | |||
@@ -1,8 +1,10 @@ | |||
1 | /* TODO merge/factor in debugfs.c here */ | 1 | /* TODO merge/factor in debugfs.c here */ |
2 | 2 | ||
3 | #include <ctype.h> | ||
3 | #include <errno.h> | 4 | #include <errno.h> |
4 | #include <stdbool.h> | 5 | #include <stdbool.h> |
5 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <stdlib.h> | ||
6 | #include <string.h> | 8 | #include <string.h> |
7 | #include <sys/vfs.h> | 9 | #include <sys/vfs.h> |
8 | 10 | ||
@@ -96,12 +98,51 @@ static bool fs__check_mounts(struct fs *fs) | |||
96 | return false; | 98 | return false; |
97 | } | 99 | } |
98 | 100 | ||
101 | static void mem_toupper(char *f, size_t len) | ||
102 | { | ||
103 | while (len) { | ||
104 | *f = toupper(*f); | ||
105 | f++; | ||
106 | len--; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * Check for "NAME_PATH" environment variable to override fs location (for | ||
112 | * testing). This matches the recommendation in Documentation/sysfs-rules.txt | ||
113 | * for SYSFS_PATH. | ||
114 | */ | ||
115 | static bool fs__env_override(struct fs *fs) | ||
116 | { | ||
117 | char *override_path; | ||
118 | size_t name_len = strlen(fs->name); | ||
119 | /* name + "_PATH" + '\0' */ | ||
120 | char upper_name[name_len + 5 + 1]; | ||
121 | memcpy(upper_name, fs->name, name_len); | ||
122 | mem_toupper(upper_name, name_len); | ||
123 | strcpy(&upper_name[name_len], "_PATH"); | ||
124 | |||
125 | override_path = getenv(upper_name); | ||
126 | if (!override_path) | ||
127 | return false; | ||
128 | |||
129 | fs->found = true; | ||
130 | strncpy(fs->path, override_path, sizeof(fs->path)); | ||
131 | return true; | ||
132 | } | ||
133 | |||
99 | static const char *fs__get_mountpoint(struct fs *fs) | 134 | static const char *fs__get_mountpoint(struct fs *fs) |
100 | { | 135 | { |
136 | if (fs__env_override(fs)) | ||
137 | return fs->path; | ||
138 | |||
101 | if (fs__check_mounts(fs)) | 139 | if (fs__check_mounts(fs)) |
102 | return fs->path; | 140 | return fs->path; |
103 | 141 | ||
104 | return fs__read_mounts(fs) ? fs->path : NULL; | 142 | if (fs__read_mounts(fs)) |
143 | return fs->path; | ||
144 | |||
145 | return NULL; | ||
105 | } | 146 | } |
106 | 147 | ||
107 | static const char *fs__mountpoint(int idx) | 148 | static const char *fs__mountpoint(int idx) |
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index c71b0f36d9e8..d460049cae8e 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
@@ -184,9 +184,10 @@ following filters are defined: | |||
184 | - in_tx: only when the target is in a hardware transaction | 184 | - in_tx: only when the target is in a hardware transaction |
185 | - no_tx: only when the target is not in a hardware transaction | 185 | - no_tx: only when the target is not in a hardware transaction |
186 | - abort_tx: only when the target is a hardware transaction abort | 186 | - abort_tx: only when the target is a hardware transaction abort |
187 | - cond: conditional branches | ||
187 | 188 | ||
188 | + | 189 | + |
189 | The option requires at least one branch type among any, any_call, any_ret, ind_call. | 190 | The option requires at least one branch type among any, any_call, any_ret, ind_call, cond. |
190 | The privilege levels may be omitted, in which case, the privilege levels of the associated | 191 | The privilege levels may be omitted, in which case, the privilege levels of the associated |
191 | event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege | 192 | event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege |
192 | levels are subject to permissions. When sampling on multiple events, branch stack sampling | 193 | levels are subject to permissions. When sampling on multiple events, branch stack sampling |
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt index a1b5185402d5..cefdf430d1b4 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt | |||
@@ -111,7 +111,7 @@ OPTIONS | |||
111 | --fields=:: | 111 | --fields=:: |
112 | Specify output field - multiple keys can be specified in CSV format. | 112 | Specify output field - multiple keys can be specified in CSV format. |
113 | Following fields are available: | 113 | Following fields are available: |
114 | overhead, overhead_sys, overhead_us, sample and period. | 114 | overhead, overhead_sys, overhead_us, overhead_children, sample and period. |
115 | Also it can contain any sort key(s). | 115 | Also it can contain any sort key(s). |
116 | 116 | ||
117 | By default, every sort keys not specified in -F will be appended | 117 | By default, every sort keys not specified in -F will be appended |
@@ -163,6 +163,11 @@ OPTIONS | |||
163 | 163 | ||
164 | Default: fractal,0.5,callee,function. | 164 | Default: fractal,0.5,callee,function. |
165 | 165 | ||
166 | --children:: | ||
167 | Accumulate callchain of children to parent entry so that then can | ||
168 | show up in the output. The output will have a new "Children" column | ||
169 | and will be sorted on the data. It requires callchains are recorded. | ||
170 | |||
166 | --max-stack:: | 171 | --max-stack:: |
167 | Set the stack depth limit when parsing the callchain, anything | 172 | Set the stack depth limit when parsing the callchain, anything |
168 | beyond the specified depth will be ignored. This is a trade-off | 173 | beyond the specified depth will be ignored. This is a trade-off |
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt index dcfa54c851e9..180ae02137a5 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt | |||
@@ -119,7 +119,7 @@ Default is to monitor all CPUS. | |||
119 | --fields=:: | 119 | --fields=:: |
120 | Specify output field - multiple keys can be specified in CSV format. | 120 | Specify output field - multiple keys can be specified in CSV format. |
121 | Following fields are available: | 121 | Following fields are available: |
122 | overhead, overhead_sys, overhead_us, sample and period. | 122 | overhead, overhead_sys, overhead_us, overhead_children, sample and period. |
123 | Also it can contain any sort key(s). | 123 | Also it can contain any sort key(s). |
124 | 124 | ||
125 | By default, every sort keys not specified in --field will be appended | 125 | By default, every sort keys not specified in --field will be appended |
@@ -161,6 +161,12 @@ Default is to monitor all CPUS. | |||
161 | Setup and enable call-graph (stack chain/backtrace) recording, | 161 | Setup and enable call-graph (stack chain/backtrace) recording, |
162 | implies -g. | 162 | implies -g. |
163 | 163 | ||
164 | --children:: | ||
165 | Accumulate callchain of children to parent entry so that then can | ||
166 | show up in the output. The output will have a new "Children" column | ||
167 | and will be sorted on the data. It requires -g/--call-graph option | ||
168 | enabled. | ||
169 | |||
164 | --max-stack:: | 170 | --max-stack:: |
165 | Set the stack depth limit when parsing the callchain, anything | 171 | Set the stack depth limit when parsing the callchain, anything |
166 | beyond the specified depth will be ignored. This is a trade-off | 172 | beyond the specified depth will be ignored. This is a trade-off |
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 02f0a4dd1a80..ae20edfcc3f7 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -400,6 +400,7 @@ LIB_OBJS += $(OUTPUT)tests/hists_common.o | |||
400 | LIB_OBJS += $(OUTPUT)tests/hists_link.o | 400 | LIB_OBJS += $(OUTPUT)tests/hists_link.o |
401 | LIB_OBJS += $(OUTPUT)tests/hists_filter.o | 401 | LIB_OBJS += $(OUTPUT)tests/hists_filter.o |
402 | LIB_OBJS += $(OUTPUT)tests/hists_output.o | 402 | LIB_OBJS += $(OUTPUT)tests/hists_output.o |
403 | LIB_OBJS += $(OUTPUT)tests/hists_cumulate.o | ||
403 | LIB_OBJS += $(OUTPUT)tests/python-use.o | 404 | LIB_OBJS += $(OUTPUT)tests/python-use.o |
404 | LIB_OBJS += $(OUTPUT)tests/bp_signal.o | 405 | LIB_OBJS += $(OUTPUT)tests/bp_signal.o |
405 | LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o | 406 | LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o |
@@ -788,8 +789,8 @@ help: | |||
788 | @echo '' | 789 | @echo '' |
789 | @echo 'Perf install targets:' | 790 | @echo 'Perf install targets:' |
790 | @echo ' NOTE: documentation build requires asciidoc, xmlto packages to be installed' | 791 | @echo ' NOTE: documentation build requires asciidoc, xmlto packages to be installed' |
791 | @echo ' HINT: use "make prefix=<path> <install target>" to install to a particular' | 792 | @echo ' HINT: use "prefix" or "DESTDIR" to install to a particular' |
792 | @echo ' path like make prefix=/usr/local install install-doc' | 793 | @echo ' path like "make prefix=/usr/local install install-doc"' |
793 | @echo ' install - install compiled binaries' | 794 | @echo ' install - install compiled binaries' |
794 | @echo ' install-doc - install *all* documentation' | 795 | @echo ' install-doc - install *all* documentation' |
795 | @echo ' install-man - install manpage documentation' | 796 | @echo ' install-man - install manpage documentation' |
@@ -814,17 +815,20 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html | |||
814 | $(DOC_TARGETS): | 815 | $(DOC_TARGETS): |
815 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all) | 816 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all) |
816 | 817 | ||
818 | TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol | ||
819 | TAG_FILES= ../../include/uapi/linux/perf_event.h | ||
820 | |||
817 | TAGS: | 821 | TAGS: |
818 | $(RM) TAGS | 822 | $(RM) TAGS |
819 | $(FIND) . -name '*.[hcS]' -print | xargs etags -a | 823 | $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs etags -a $(TAG_FILES) |
820 | 824 | ||
821 | tags: | 825 | tags: |
822 | $(RM) tags | 826 | $(RM) tags |
823 | $(FIND) . -name '*.[hcS]' -print | xargs ctags -a | 827 | $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs ctags -a $(TAG_FILES) |
824 | 828 | ||
825 | cscope: | 829 | cscope: |
826 | $(RM) cscope* | 830 | $(RM) cscope* |
827 | $(FIND) . -name '*.[hcS]' -print | xargs cscope -b | 831 | $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs cscope -b $(TAG_FILES) |
828 | 832 | ||
829 | ### Detect prefix changes | 833 | ### Detect prefix changes |
830 | TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):\ | 834 | TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):\ |
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index d30d2c2e2a7a..1ec429fef2be 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -65,12 +65,13 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel, | |||
65 | return 0; | 65 | return 0; |
66 | } | 66 | } |
67 | 67 | ||
68 | he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, 1, 1, 0); | 68 | he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, 1, 1, 0, |
69 | true); | ||
69 | if (he == NULL) | 70 | if (he == NULL) |
70 | return -ENOMEM; | 71 | return -ENOMEM; |
71 | 72 | ||
72 | ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); | 73 | ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); |
73 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); | 74 | hists__inc_nr_samples(&evsel->hists, true); |
74 | return ret; | 75 | return ret; |
75 | } | 76 | } |
76 | 77 | ||
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 8bff543acaab..9a5a035cb426 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -315,7 +315,7 @@ static int hists__add_entry(struct hists *hists, | |||
315 | u64 weight, u64 transaction) | 315 | u64 weight, u64 transaction) |
316 | { | 316 | { |
317 | if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight, | 317 | if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight, |
318 | transaction) != NULL) | 318 | transaction, true) != NULL) |
319 | return 0; | 319 | return 0; |
320 | return -ENOMEM; | 320 | return -ENOMEM; |
321 | } | 321 | } |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e4c85b8f46c2..378b85b731a7 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -454,7 +454,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) | |||
454 | if (done) | 454 | if (done) |
455 | break; | 455 | break; |
456 | err = poll(rec->evlist->pollfd, rec->evlist->nr_fds, -1); | 456 | err = poll(rec->evlist->pollfd, rec->evlist->nr_fds, -1); |
457 | if (err < 0 && errno == EINTR) | 457 | /* |
458 | * Propagate error, only if there's any. Ignore positive | ||
459 | * number of returned events and interrupt error. | ||
460 | */ | ||
461 | if (err > 0 || (err < 0 && errno == EINTR)) | ||
458 | err = 0; | 462 | err = 0; |
459 | waking++; | 463 | waking++; |
460 | } | 464 | } |
@@ -544,6 +548,7 @@ static const struct branch_mode branch_modes[] = { | |||
544 | BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX), | 548 | BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX), |
545 | BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX), | 549 | BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX), |
546 | BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX), | 550 | BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX), |
551 | BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND), | ||
547 | BRANCH_END | 552 | BRANCH_END |
548 | }; | 553 | }; |
549 | 554 | ||
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index bc0eec1ce4be..21d830bafff3 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -72,6 +72,10 @@ static int report__config(const char *var, const char *value, void *cb) | |||
72 | rep->min_percent = strtof(value, NULL); | 72 | rep->min_percent = strtof(value, NULL); |
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | if (!strcmp(var, "report.children")) { | ||
76 | symbol_conf.cumulate_callchain = perf_config_bool(var, value); | ||
77 | return 0; | ||
78 | } | ||
75 | 79 | ||
76 | return perf_default_config(var, value, cb); | 80 | return perf_default_config(var, value, cb); |
77 | } | 81 | } |
@@ -85,156 +89,52 @@ static void report__inc_stats(struct report *rep, struct hist_entry *he) | |||
85 | */ | 89 | */ |
86 | if (he->stat.nr_events == 1) | 90 | if (he->stat.nr_events == 1) |
87 | rep->nr_entries++; | 91 | rep->nr_entries++; |
88 | |||
89 | /* | ||
90 | * Only counts number of samples at this stage as it's more | ||
91 | * natural to do it here and non-sample events are also | ||
92 | * counted in perf_session_deliver_event(). The dump_trace | ||
93 | * requires this info is ready before going to the output tree. | ||
94 | */ | ||
95 | hists__inc_nr_events(he->hists, PERF_RECORD_SAMPLE); | ||
96 | if (!he->filtered) | ||
97 | he->hists->stats.nr_non_filtered_samples++; | ||
98 | } | 92 | } |
99 | 93 | ||
100 | static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al, | 94 | static int hist_iter__report_callback(struct hist_entry_iter *iter, |
101 | struct perf_sample *sample, struct perf_evsel *evsel) | 95 | struct addr_location *al, bool single, |
96 | void *arg) | ||
102 | { | 97 | { |
103 | struct symbol *parent = NULL; | 98 | int err = 0; |
104 | struct hist_entry *he; | 99 | struct report *rep = arg; |
105 | struct mem_info *mi, *mx; | 100 | struct hist_entry *he = iter->he; |
106 | uint64_t cost; | 101 | struct perf_evsel *evsel = iter->evsel; |
107 | int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack); | 102 | struct mem_info *mi; |
108 | 103 | struct branch_info *bi; | |
109 | if (err) | ||
110 | return err; | ||
111 | 104 | ||
112 | mi = sample__resolve_mem(sample, al); | 105 | report__inc_stats(rep, he); |
113 | if (!mi) | ||
114 | return -ENOMEM; | ||
115 | 106 | ||
116 | if (rep->hide_unresolved && !al->sym) | 107 | if (!ui__has_annotation()) |
117 | return 0; | 108 | return 0; |
118 | 109 | ||
119 | cost = sample->weight; | 110 | if (sort__mode == SORT_MODE__BRANCH) { |
120 | if (!cost) | 111 | bi = he->branch_info; |
121 | cost = 1; | 112 | err = addr_map_symbol__inc_samples(&bi->from, evsel->idx); |
122 | |||
123 | /* | ||
124 | * must pass period=weight in order to get the correct | ||
125 | * sorting from hists__collapse_resort() which is solely | ||
126 | * based on periods. We want sorting be done on nr_events * weight | ||
127 | * and this is indirectly achieved by passing period=weight here | ||
128 | * and the he_stat__add_period() function. | ||
129 | */ | ||
130 | he = __hists__add_entry(&evsel->hists, al, parent, NULL, mi, | ||
131 | cost, cost, 0); | ||
132 | if (!he) | ||
133 | return -ENOMEM; | ||
134 | |||
135 | if (ui__has_annotation()) { | ||
136 | err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); | ||
137 | if (err) | ||
138 | goto out; | ||
139 | |||
140 | mx = he->mem_info; | ||
141 | err = addr_map_symbol__inc_samples(&mx->daddr, evsel->idx); | ||
142 | if (err) | 113 | if (err) |
143 | goto out; | 114 | goto out; |
144 | } | ||
145 | |||
146 | report__inc_stats(rep, he); | ||
147 | |||
148 | err = hist_entry__append_callchain(he, sample); | ||
149 | out: | ||
150 | return err; | ||
151 | } | ||
152 | |||
153 | static int report__add_branch_hist_entry(struct report *rep, struct addr_location *al, | ||
154 | struct perf_sample *sample, struct perf_evsel *evsel) | ||
155 | { | ||
156 | struct symbol *parent = NULL; | ||
157 | unsigned i; | ||
158 | struct hist_entry *he; | ||
159 | struct branch_info *bi, *bx; | ||
160 | int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack); | ||
161 | 115 | ||
162 | if (err) | 116 | err = addr_map_symbol__inc_samples(&bi->to, evsel->idx); |
163 | return err; | ||
164 | |||
165 | bi = sample__resolve_bstack(sample, al); | ||
166 | if (!bi) | ||
167 | return -ENOMEM; | ||
168 | |||
169 | for (i = 0; i < sample->branch_stack->nr; i++) { | ||
170 | if (rep->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) | ||
171 | continue; | ||
172 | 117 | ||
173 | err = -ENOMEM; | 118 | } else if (rep->mem_mode) { |
174 | 119 | mi = he->mem_info; | |
175 | /* overwrite the 'al' to branch-to info */ | 120 | err = addr_map_symbol__inc_samples(&mi->daddr, evsel->idx); |
176 | al->map = bi[i].to.map; | 121 | if (err) |
177 | al->sym = bi[i].to.sym; | ||
178 | al->addr = bi[i].to.addr; | ||
179 | /* | ||
180 | * The report shows the percentage of total branches captured | ||
181 | * and not events sampled. Thus we use a pseudo period of 1. | ||
182 | */ | ||
183 | he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL, | ||
184 | 1, 1, 0); | ||
185 | if (he) { | ||
186 | if (ui__has_annotation()) { | ||
187 | bx = he->branch_info; | ||
188 | err = addr_map_symbol__inc_samples(&bx->from, | ||
189 | evsel->idx); | ||
190 | if (err) | ||
191 | goto out; | ||
192 | |||
193 | err = addr_map_symbol__inc_samples(&bx->to, | ||
194 | evsel->idx); | ||
195 | if (err) | ||
196 | goto out; | ||
197 | } | ||
198 | report__inc_stats(rep, he); | ||
199 | } else | ||
200 | goto out; | 122 | goto out; |
201 | } | ||
202 | err = 0; | ||
203 | out: | ||
204 | free(bi); | ||
205 | return err; | ||
206 | } | ||
207 | |||
208 | static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel, | ||
209 | struct addr_location *al, struct perf_sample *sample) | ||
210 | { | ||
211 | struct symbol *parent = NULL; | ||
212 | struct hist_entry *he; | ||
213 | int err = sample__resolve_callchain(sample, &parent, evsel, al, rep->max_stack); | ||
214 | |||
215 | if (err) | ||
216 | return err; | ||
217 | 123 | ||
218 | he = __hists__add_entry(&evsel->hists, al, parent, NULL, NULL, | ||
219 | sample->period, sample->weight, | ||
220 | sample->transaction); | ||
221 | if (he == NULL) | ||
222 | return -ENOMEM; | ||
223 | |||
224 | err = hist_entry__append_callchain(he, sample); | ||
225 | if (err) | ||
226 | goto out; | ||
227 | |||
228 | if (ui__has_annotation()) | ||
229 | err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); | 124 | err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); |
230 | 125 | ||
231 | report__inc_stats(rep, he); | 126 | } else if (symbol_conf.cumulate_callchain) { |
127 | if (single) | ||
128 | err = hist_entry__inc_addr_samples(he, evsel->idx, | ||
129 | al->addr); | ||
130 | } else { | ||
131 | err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); | ||
132 | } | ||
232 | 133 | ||
233 | out: | 134 | out: |
234 | return err; | 135 | return err; |
235 | } | 136 | } |
236 | 137 | ||
237 | |||
238 | static int process_sample_event(struct perf_tool *tool, | 138 | static int process_sample_event(struct perf_tool *tool, |
239 | union perf_event *event, | 139 | union perf_event *event, |
240 | struct perf_sample *sample, | 140 | struct perf_sample *sample, |
@@ -243,6 +143,10 @@ static int process_sample_event(struct perf_tool *tool, | |||
243 | { | 143 | { |
244 | struct report *rep = container_of(tool, struct report, tool); | 144 | struct report *rep = container_of(tool, struct report, tool); |
245 | struct addr_location al; | 145 | struct addr_location al; |
146 | struct hist_entry_iter iter = { | ||
147 | .hide_unresolved = rep->hide_unresolved, | ||
148 | .add_entry_cb = hist_iter__report_callback, | ||
149 | }; | ||
246 | int ret; | 150 | int ret; |
247 | 151 | ||
248 | if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { | 152 | if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { |
@@ -257,22 +161,23 @@ static int process_sample_event(struct perf_tool *tool, | |||
257 | if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) | 161 | if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) |
258 | return 0; | 162 | return 0; |
259 | 163 | ||
260 | if (sort__mode == SORT_MODE__BRANCH) { | 164 | if (sort__mode == SORT_MODE__BRANCH) |
261 | ret = report__add_branch_hist_entry(rep, &al, sample, evsel); | 165 | iter.ops = &hist_iter_branch; |
262 | if (ret < 0) | 166 | else if (rep->mem_mode) |
263 | pr_debug("problem adding lbr entry, skipping event\n"); | 167 | iter.ops = &hist_iter_mem; |
264 | } else if (rep->mem_mode == 1) { | 168 | else if (symbol_conf.cumulate_callchain) |
265 | ret = report__add_mem_hist_entry(rep, &al, sample, evsel); | 169 | iter.ops = &hist_iter_cumulative; |
266 | if (ret < 0) | 170 | else |
267 | pr_debug("problem adding mem entry, skipping event\n"); | 171 | iter.ops = &hist_iter_normal; |
268 | } else { | 172 | |
269 | if (al.map != NULL) | 173 | if (al.map != NULL) |
270 | al.map->dso->hit = 1; | 174 | al.map->dso->hit = 1; |
175 | |||
176 | ret = hist_entry_iter__add(&iter, &al, evsel, sample, rep->max_stack, | ||
177 | rep); | ||
178 | if (ret < 0) | ||
179 | pr_debug("problem adding hist entry, skipping event\n"); | ||
271 | 180 | ||
272 | ret = report__add_hist_entry(rep, evsel, &al, sample); | ||
273 | if (ret < 0) | ||
274 | pr_debug("problem incrementing symbol period, skipping event\n"); | ||
275 | } | ||
276 | return ret; | 181 | return ret; |
277 | } | 182 | } |
278 | 183 | ||
@@ -329,6 +234,14 @@ static int report__setup_sample_type(struct report *rep) | |||
329 | } | 234 | } |
330 | } | 235 | } |
331 | 236 | ||
237 | if (symbol_conf.cumulate_callchain) { | ||
238 | /* Silently ignore if callchain is missing */ | ||
239 | if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) { | ||
240 | symbol_conf.cumulate_callchain = false; | ||
241 | perf_hpp__cancel_cumulate(); | ||
242 | } | ||
243 | } | ||
244 | |||
332 | if (sort__mode == SORT_MODE__BRANCH) { | 245 | if (sort__mode == SORT_MODE__BRANCH) { |
333 | if (!is_pipe && | 246 | if (!is_pipe && |
334 | !(sample_type & PERF_SAMPLE_BRANCH_STACK)) { | 247 | !(sample_type & PERF_SAMPLE_BRANCH_STACK)) { |
@@ -712,6 +625,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
712 | OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order", | 625 | OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order", |
713 | "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address). " | 626 | "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address). " |
714 | "Default: fractal,0.5,callee,function", &report_parse_callchain_opt, callchain_default_opt), | 627 | "Default: fractal,0.5,callee,function", &report_parse_callchain_opt, callchain_default_opt), |
628 | OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain, | ||
629 | "Accumulate callchains of children and show total overhead as well"), | ||
715 | OPT_INTEGER(0, "max-stack", &report.max_stack, | 630 | OPT_INTEGER(0, "max-stack", &report.max_stack, |
716 | "Set the maximum stack depth when parsing the callchain, " | 631 | "Set the maximum stack depth when parsing the callchain, " |
717 | "anything beyond the specified depth will be ignored. " | 632 | "anything beyond the specified depth will be ignored. " |
@@ -804,8 +719,10 @@ repeat: | |||
804 | has_br_stack = perf_header__has_feat(&session->header, | 719 | has_br_stack = perf_header__has_feat(&session->header, |
805 | HEADER_BRANCH_STACK); | 720 | HEADER_BRANCH_STACK); |
806 | 721 | ||
807 | if (branch_mode == -1 && has_br_stack) | 722 | if (branch_mode == -1 && has_br_stack) { |
808 | sort__mode = SORT_MODE__BRANCH; | 723 | sort__mode = SORT_MODE__BRANCH; |
724 | symbol_conf.cumulate_callchain = false; | ||
725 | } | ||
809 | 726 | ||
810 | if (report.mem_mode) { | 727 | if (report.mem_mode) { |
811 | if (sort__mode == SORT_MODE__BRANCH) { | 728 | if (sort__mode == SORT_MODE__BRANCH) { |
@@ -813,6 +730,7 @@ repeat: | |||
813 | goto error; | 730 | goto error; |
814 | } | 731 | } |
815 | sort__mode = SORT_MODE__MEMORY; | 732 | sort__mode = SORT_MODE__MEMORY; |
733 | symbol_conf.cumulate_callchain = false; | ||
816 | } | 734 | } |
817 | 735 | ||
818 | if (setup_sorting() < 0) { | 736 | if (setup_sorting() < 0) { |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index d7176830b9b2..c38d06c04775 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -1428,7 +1428,7 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool __maybe_ | |||
1428 | int err = 0; | 1428 | int err = 0; |
1429 | 1429 | ||
1430 | evsel->hists.stats.total_period += sample->period; | 1430 | evsel->hists.stats.total_period += sample->period; |
1431 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); | 1431 | hists__inc_nr_samples(&evsel->hists, true); |
1432 | 1432 | ||
1433 | if (evsel->handler != NULL) { | 1433 | if (evsel->handler != NULL) { |
1434 | tracepoint_handler f = evsel->handler; | 1434 | tracepoint_handler f = evsel->handler; |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 5b389ce4cd15..377971dc89a3 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -196,6 +196,12 @@ static void perf_top__record_precise_ip(struct perf_top *top, | |||
196 | 196 | ||
197 | pthread_mutex_unlock(¬es->lock); | 197 | pthread_mutex_unlock(¬es->lock); |
198 | 198 | ||
199 | /* | ||
200 | * This function is now called with he->hists->lock held. | ||
201 | * Release it before going to sleep. | ||
202 | */ | ||
203 | pthread_mutex_unlock(&he->hists->lock); | ||
204 | |||
199 | if (err == -ERANGE && !he->ms.map->erange_warned) | 205 | if (err == -ERANGE && !he->ms.map->erange_warned) |
200 | ui__warn_map_erange(he->ms.map, sym, ip); | 206 | ui__warn_map_erange(he->ms.map, sym, ip); |
201 | else if (err == -ENOMEM) { | 207 | else if (err == -ENOMEM) { |
@@ -203,6 +209,8 @@ static void perf_top__record_precise_ip(struct perf_top *top, | |||
203 | sym->name); | 209 | sym->name); |
204 | sleep(1); | 210 | sleep(1); |
205 | } | 211 | } |
212 | |||
213 | pthread_mutex_lock(&he->hists->lock); | ||
206 | } | 214 | } |
207 | 215 | ||
208 | static void perf_top__show_details(struct perf_top *top) | 216 | static void perf_top__show_details(struct perf_top *top) |
@@ -238,27 +246,6 @@ out_unlock: | |||
238 | pthread_mutex_unlock(¬es->lock); | 246 | pthread_mutex_unlock(¬es->lock); |
239 | } | 247 | } |
240 | 248 | ||
241 | static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel, | ||
242 | struct addr_location *al, | ||
243 | struct perf_sample *sample) | ||
244 | { | ||
245 | struct hist_entry *he; | ||
246 | |||
247 | pthread_mutex_lock(&evsel->hists.lock); | ||
248 | he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, | ||
249 | sample->period, sample->weight, | ||
250 | sample->transaction); | ||
251 | pthread_mutex_unlock(&evsel->hists.lock); | ||
252 | if (he == NULL) | ||
253 | return NULL; | ||
254 | |||
255 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); | ||
256 | if (!he->filtered) | ||
257 | evsel->hists.stats.nr_non_filtered_samples++; | ||
258 | |||
259 | return he; | ||
260 | } | ||
261 | |||
262 | static void perf_top__print_sym_table(struct perf_top *top) | 249 | static void perf_top__print_sym_table(struct perf_top *top) |
263 | { | 250 | { |
264 | char bf[160]; | 251 | char bf[160]; |
@@ -662,6 +649,26 @@ static int symbol_filter(struct map *map __maybe_unused, struct symbol *sym) | |||
662 | return 0; | 649 | return 0; |
663 | } | 650 | } |
664 | 651 | ||
652 | static int hist_iter__top_callback(struct hist_entry_iter *iter, | ||
653 | struct addr_location *al, bool single, | ||
654 | void *arg) | ||
655 | { | ||
656 | struct perf_top *top = arg; | ||
657 | struct hist_entry *he = iter->he; | ||
658 | struct perf_evsel *evsel = iter->evsel; | ||
659 | |||
660 | if (sort__has_sym && single) { | ||
661 | u64 ip = al->addr; | ||
662 | |||
663 | if (al->map) | ||
664 | ip = al->map->unmap_ip(al->map, ip); | ||
665 | |||
666 | perf_top__record_precise_ip(top, he, evsel->idx, ip); | ||
667 | } | ||
668 | |||
669 | return 0; | ||
670 | } | ||
671 | |||
665 | static void perf_event__process_sample(struct perf_tool *tool, | 672 | static void perf_event__process_sample(struct perf_tool *tool, |
666 | const union perf_event *event, | 673 | const union perf_event *event, |
667 | struct perf_evsel *evsel, | 674 | struct perf_evsel *evsel, |
@@ -669,8 +676,6 @@ static void perf_event__process_sample(struct perf_tool *tool, | |||
669 | struct machine *machine) | 676 | struct machine *machine) |
670 | { | 677 | { |
671 | struct perf_top *top = container_of(tool, struct perf_top, tool); | 678 | struct perf_top *top = container_of(tool, struct perf_top, tool); |
672 | struct symbol *parent = NULL; | ||
673 | u64 ip = sample->ip; | ||
674 | struct addr_location al; | 679 | struct addr_location al; |
675 | int err; | 680 | int err; |
676 | 681 | ||
@@ -745,25 +750,23 @@ static void perf_event__process_sample(struct perf_tool *tool, | |||
745 | } | 750 | } |
746 | 751 | ||
747 | if (al.sym == NULL || !al.sym->ignore) { | 752 | if (al.sym == NULL || !al.sym->ignore) { |
748 | struct hist_entry *he; | 753 | struct hist_entry_iter iter = { |
754 | .add_entry_cb = hist_iter__top_callback, | ||
755 | }; | ||
749 | 756 | ||
750 | err = sample__resolve_callchain(sample, &parent, evsel, &al, | 757 | if (symbol_conf.cumulate_callchain) |
751 | top->max_stack); | 758 | iter.ops = &hist_iter_cumulative; |
752 | if (err) | 759 | else |
753 | return; | 760 | iter.ops = &hist_iter_normal; |
754 | 761 | ||
755 | he = perf_evsel__add_hist_entry(evsel, &al, sample); | 762 | pthread_mutex_lock(&evsel->hists.lock); |
756 | if (he == NULL) { | ||
757 | pr_err("Problem incrementing symbol period, skipping event\n"); | ||
758 | return; | ||
759 | } | ||
760 | 763 | ||
761 | err = hist_entry__append_callchain(he, sample); | 764 | err = hist_entry_iter__add(&iter, &al, evsel, sample, |
762 | if (err) | 765 | top->max_stack, top); |
763 | return; | 766 | if (err < 0) |
767 | pr_err("Problem incrementing symbol period, skipping event\n"); | ||
764 | 768 | ||
765 | if (sort__has_sym) | 769 | pthread_mutex_unlock(&evsel->hists.lock); |
766 | perf_top__record_precise_ip(top, he, evsel->idx, ip); | ||
767 | } | 770 | } |
768 | 771 | ||
769 | return; | 772 | return; |
@@ -1001,6 +1004,10 @@ static int perf_top_config(const char *var, const char *value, void *cb) | |||
1001 | 1004 | ||
1002 | if (!strcmp(var, "top.call-graph")) | 1005 | if (!strcmp(var, "top.call-graph")) |
1003 | return record_parse_callchain(value, &top->record_opts); | 1006 | return record_parse_callchain(value, &top->record_opts); |
1007 | if (!strcmp(var, "top.children")) { | ||
1008 | symbol_conf.cumulate_callchain = perf_config_bool(var, value); | ||
1009 | return 0; | ||
1010 | } | ||
1004 | 1011 | ||
1005 | return perf_default_config(var, value, cb); | 1012 | return perf_default_config(var, value, cb); |
1006 | } | 1013 | } |
@@ -1095,6 +1102,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1095 | OPT_CALLBACK(0, "call-graph", &top.record_opts, | 1102 | OPT_CALLBACK(0, "call-graph", &top.record_opts, |
1096 | "mode[,dump_size]", record_callchain_help, | 1103 | "mode[,dump_size]", record_callchain_help, |
1097 | &parse_callchain_opt), | 1104 | &parse_callchain_opt), |
1105 | OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain, | ||
1106 | "Accumulate callchains of children and show total overhead as well"), | ||
1098 | OPT_INTEGER(0, "max-stack", &top.max_stack, | 1107 | OPT_INTEGER(0, "max-stack", &top.max_stack, |
1099 | "Set the maximum stack depth when parsing the callchain. " | 1108 | "Set the maximum stack depth when parsing the callchain. " |
1100 | "Default: " __stringify(PERF_MAX_STACK_DEPTH)), | 1109 | "Default: " __stringify(PERF_MAX_STACK_DEPTH)), |
@@ -1200,6 +1209,11 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1200 | 1209 | ||
1201 | top.sym_evsel = perf_evlist__first(top.evlist); | 1210 | top.sym_evsel = perf_evlist__first(top.evlist); |
1202 | 1211 | ||
1212 | if (!symbol_conf.use_callchain) { | ||
1213 | symbol_conf.cumulate_callchain = false; | ||
1214 | perf_hpp__cancel_cumulate(); | ||
1215 | } | ||
1216 | |||
1203 | symbol_conf.priv_size = sizeof(struct annotation); | 1217 | symbol_conf.priv_size = sizeof(struct annotation); |
1204 | 1218 | ||
1205 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); | 1219 | symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); |
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index 729bbdf5cec7..4f100b54ba8b 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
@@ -447,6 +447,7 @@ else | |||
447 | ifneq ($(feature-libperl), 1) | 447 | ifneq ($(feature-libperl), 1) |
448 | CFLAGS += -DNO_LIBPERL | 448 | CFLAGS += -DNO_LIBPERL |
449 | NO_LIBPERL := 1 | 449 | NO_LIBPERL := 1 |
450 | msg := $(warning Missing perl devel files. Disabling perl scripting support, consider installing perl-ExtUtils-Embed); | ||
450 | else | 451 | else |
451 | LDFLAGS += $(PERL_EMBED_LDFLAGS) | 452 | LDFLAGS += $(PERL_EMBED_LDFLAGS) |
452 | EXTLIBS += $(PERL_EMBED_LIBADD) | 453 | EXTLIBS += $(PERL_EMBED_LIBADD) |
@@ -599,7 +600,7 @@ endif | |||
599 | 600 | ||
600 | # Make the path relative to DESTDIR, not to prefix | 601 | # Make the path relative to DESTDIR, not to prefix |
601 | ifndef DESTDIR | 602 | ifndef DESTDIR |
602 | prefix = $(HOME) | 603 | prefix ?= $(HOME) |
603 | endif | 604 | endif |
604 | bindir_relative = bin | 605 | bindir_relative = bin |
605 | bindir = $(prefix)/$(bindir_relative) | 606 | bindir = $(prefix)/$(bindir_relative) |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 431798a4110d..78f7b920e548 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -481,14 +481,18 @@ int main(int argc, const char **argv) | |||
481 | fprintf(stderr, "cannot handle %s internally", cmd); | 481 | fprintf(stderr, "cannot handle %s internally", cmd); |
482 | goto out; | 482 | goto out; |
483 | } | 483 | } |
484 | #ifdef HAVE_LIBAUDIT_SUPPORT | ||
485 | if (!prefixcmp(cmd, "trace")) { | 484 | if (!prefixcmp(cmd, "trace")) { |
485 | #ifdef HAVE_LIBAUDIT_SUPPORT | ||
486 | set_buildid_dir(); | 486 | set_buildid_dir(); |
487 | setup_path(); | 487 | setup_path(); |
488 | argv[0] = "trace"; | 488 | argv[0] = "trace"; |
489 | return cmd_trace(argc, argv, NULL); | 489 | return cmd_trace(argc, argv, NULL); |
490 | } | 490 | #else |
491 | fprintf(stderr, | ||
492 | "trace command not available: missing audit-libs devel package at build time.\n"); | ||
493 | goto out; | ||
491 | #endif | 494 | #endif |
495 | } | ||
492 | /* Look for flags.. */ | 496 | /* Look for flags.. */ |
493 | argv++; | 497 | argv++; |
494 | argc--; | 498 | argc--; |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 831f52cae197..802e3cd50f6f 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
@@ -140,6 +140,10 @@ static struct test { | |||
140 | .func = test__hists_output, | 140 | .func = test__hists_output, |
141 | }, | 141 | }, |
142 | { | 142 | { |
143 | .desc = "Test cumulation of child hist entries", | ||
144 | .func = test__hists_cumulate, | ||
145 | }, | ||
146 | { | ||
143 | .func = NULL, | 147 | .func = NULL, |
144 | }, | 148 | }, |
145 | }; | 149 | }; |
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c index e4e01aadc3be..a62c09134516 100644 --- a/tools/perf/tests/hists_common.c +++ b/tools/perf/tests/hists_common.c | |||
@@ -12,9 +12,9 @@ static struct { | |||
12 | u32 pid; | 12 | u32 pid; |
13 | const char *comm; | 13 | const char *comm; |
14 | } fake_threads[] = { | 14 | } fake_threads[] = { |
15 | { 100, "perf" }, | 15 | { FAKE_PID_PERF1, "perf" }, |
16 | { 200, "perf" }, | 16 | { FAKE_PID_PERF2, "perf" }, |
17 | { 300, "bash" }, | 17 | { FAKE_PID_BASH, "bash" }, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | static struct { | 20 | static struct { |
@@ -22,15 +22,15 @@ static struct { | |||
22 | u64 start; | 22 | u64 start; |
23 | const char *filename; | 23 | const char *filename; |
24 | } fake_mmap_info[] = { | 24 | } fake_mmap_info[] = { |
25 | { 100, 0x40000, "perf" }, | 25 | { FAKE_PID_PERF1, FAKE_MAP_PERF, "perf" }, |
26 | { 100, 0x50000, "libc" }, | 26 | { FAKE_PID_PERF1, FAKE_MAP_LIBC, "libc" }, |
27 | { 100, 0xf0000, "[kernel]" }, | 27 | { FAKE_PID_PERF1, FAKE_MAP_KERNEL, "[kernel]" }, |
28 | { 200, 0x40000, "perf" }, | 28 | { FAKE_PID_PERF2, FAKE_MAP_PERF, "perf" }, |
29 | { 200, 0x50000, "libc" }, | 29 | { FAKE_PID_PERF2, FAKE_MAP_LIBC, "libc" }, |
30 | { 200, 0xf0000, "[kernel]" }, | 30 | { FAKE_PID_PERF2, FAKE_MAP_KERNEL, "[kernel]" }, |
31 | { 300, 0x40000, "bash" }, | 31 | { FAKE_PID_BASH, FAKE_MAP_BASH, "bash" }, |
32 | { 300, 0x50000, "libc" }, | 32 | { FAKE_PID_BASH, FAKE_MAP_LIBC, "libc" }, |
33 | { 300, 0xf0000, "[kernel]" }, | 33 | { FAKE_PID_BASH, FAKE_MAP_KERNEL, "[kernel]" }, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | struct fake_sym { | 36 | struct fake_sym { |
@@ -40,27 +40,30 @@ struct fake_sym { | |||
40 | }; | 40 | }; |
41 | 41 | ||
42 | static struct fake_sym perf_syms[] = { | 42 | static struct fake_sym perf_syms[] = { |
43 | { 700, 100, "main" }, | 43 | { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "main" }, |
44 | { 800, 100, "run_command" }, | 44 | { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "run_command" }, |
45 | { 900, 100, "cmd_record" }, | 45 | { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "cmd_record" }, |
46 | }; | 46 | }; |
47 | 47 | ||
48 | static struct fake_sym bash_syms[] = { | 48 | static struct fake_sym bash_syms[] = { |
49 | { 700, 100, "main" }, | 49 | { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "main" }, |
50 | { 800, 100, "xmalloc" }, | 50 | { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "xmalloc" }, |
51 | { 900, 100, "xfree" }, | 51 | { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "xfree" }, |
52 | }; | 52 | }; |
53 | 53 | ||
54 | static struct fake_sym libc_syms[] = { | 54 | static struct fake_sym libc_syms[] = { |
55 | { 700, 100, "malloc" }, | 55 | { 700, 100, "malloc" }, |
56 | { 800, 100, "free" }, | 56 | { 800, 100, "free" }, |
57 | { 900, 100, "realloc" }, | 57 | { 900, 100, "realloc" }, |
58 | { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "malloc" }, | ||
59 | { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "free" }, | ||
60 | { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "realloc" }, | ||
58 | }; | 61 | }; |
59 | 62 | ||
60 | static struct fake_sym kernel_syms[] = { | 63 | static struct fake_sym kernel_syms[] = { |
61 | { 700, 100, "schedule" }, | 64 | { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "schedule" }, |
62 | { 800, 100, "page_fault" }, | 65 | { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "page_fault" }, |
63 | { 900, 100, "sys_perf_event_open" }, | 66 | { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "sys_perf_event_open" }, |
64 | }; | 67 | }; |
65 | 68 | ||
66 | static struct { | 69 | static struct { |
@@ -102,7 +105,7 @@ struct machine *setup_fake_machine(struct machines *machines) | |||
102 | .pid = fake_mmap_info[i].pid, | 105 | .pid = fake_mmap_info[i].pid, |
103 | .tid = fake_mmap_info[i].pid, | 106 | .tid = fake_mmap_info[i].pid, |
104 | .start = fake_mmap_info[i].start, | 107 | .start = fake_mmap_info[i].start, |
105 | .len = 0x1000ULL, | 108 | .len = FAKE_MAP_LENGTH, |
106 | .pgoff = 0ULL, | 109 | .pgoff = 0ULL, |
107 | }, | 110 | }, |
108 | }; | 111 | }; |
@@ -193,10 +196,11 @@ void print_hists_out(struct hists *hists) | |||
193 | he = rb_entry(node, struct hist_entry, rb_node); | 196 | he = rb_entry(node, struct hist_entry, rb_node); |
194 | 197 | ||
195 | if (!he->filtered) { | 198 | if (!he->filtered) { |
196 | pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"\n", | 199 | pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n", |
197 | i, thread__comm_str(he->thread), he->thread->tid, | 200 | i, thread__comm_str(he->thread), he->thread->tid, |
198 | he->ms.map->dso->short_name, | 201 | he->ms.map->dso->short_name, |
199 | he->ms.sym->name, he->stat.period); | 202 | he->ms.sym->name, he->stat.period, |
203 | he->stat_acc ? he->stat_acc->period : 0); | ||
200 | } | 204 | } |
201 | 205 | ||
202 | i++; | 206 | i++; |
diff --git a/tools/perf/tests/hists_common.h b/tools/perf/tests/hists_common.h index 1415ae69d7b6..888254e8665c 100644 --- a/tools/perf/tests/hists_common.h +++ b/tools/perf/tests/hists_common.h | |||
@@ -4,6 +4,34 @@ | |||
4 | struct machine; | 4 | struct machine; |
5 | struct machines; | 5 | struct machines; |
6 | 6 | ||
7 | #define FAKE_PID_PERF1 100 | ||
8 | #define FAKE_PID_PERF2 200 | ||
9 | #define FAKE_PID_BASH 300 | ||
10 | |||
11 | #define FAKE_MAP_PERF 0x400000 | ||
12 | #define FAKE_MAP_BASH 0x400000 | ||
13 | #define FAKE_MAP_LIBC 0x500000 | ||
14 | #define FAKE_MAP_KERNEL 0xf00000 | ||
15 | #define FAKE_MAP_LENGTH 0x100000 | ||
16 | |||
17 | #define FAKE_SYM_OFFSET1 700 | ||
18 | #define FAKE_SYM_OFFSET2 800 | ||
19 | #define FAKE_SYM_OFFSET3 900 | ||
20 | #define FAKE_SYM_LENGTH 100 | ||
21 | |||
22 | #define FAKE_IP_PERF_MAIN FAKE_MAP_PERF + FAKE_SYM_OFFSET1 | ||
23 | #define FAKE_IP_PERF_RUN_COMMAND FAKE_MAP_PERF + FAKE_SYM_OFFSET2 | ||
24 | #define FAKE_IP_PERF_CMD_RECORD FAKE_MAP_PERF + FAKE_SYM_OFFSET3 | ||
25 | #define FAKE_IP_BASH_MAIN FAKE_MAP_BASH + FAKE_SYM_OFFSET1 | ||
26 | #define FAKE_IP_BASH_XMALLOC FAKE_MAP_BASH + FAKE_SYM_OFFSET2 | ||
27 | #define FAKE_IP_BASH_XFREE FAKE_MAP_BASH + FAKE_SYM_OFFSET3 | ||
28 | #define FAKE_IP_LIBC_MALLOC FAKE_MAP_LIBC + FAKE_SYM_OFFSET1 | ||
29 | #define FAKE_IP_LIBC_FREE FAKE_MAP_LIBC + FAKE_SYM_OFFSET2 | ||
30 | #define FAKE_IP_LIBC_REALLOC FAKE_MAP_LIBC + FAKE_SYM_OFFSET3 | ||
31 | #define FAKE_IP_KERNEL_SCHEDULE FAKE_MAP_KERNEL + FAKE_SYM_OFFSET1 | ||
32 | #define FAKE_IP_KERNEL_PAGE_FAULT FAKE_MAP_KERNEL + FAKE_SYM_OFFSET2 | ||
33 | #define FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN FAKE_MAP_KERNEL + FAKE_SYM_OFFSET3 | ||
34 | |||
7 | /* | 35 | /* |
8 | * The setup_fake_machine() provides a test environment which consists | 36 | * The setup_fake_machine() provides a test environment which consists |
9 | * of 3 processes that have 3 mappings and in turn, have 3 symbols | 37 | * of 3 processes that have 3 mappings and in turn, have 3 symbols |
@@ -13,7 +41,7 @@ struct machines; | |||
13 | * ............. ............. ................... | 41 | * ............. ............. ................... |
14 | * perf: 100 perf main | 42 | * perf: 100 perf main |
15 | * perf: 100 perf run_command | 43 | * perf: 100 perf run_command |
16 | * perf: 100 perf comd_record | 44 | * perf: 100 perf cmd_record |
17 | * perf: 100 libc malloc | 45 | * perf: 100 libc malloc |
18 | * perf: 100 libc free | 46 | * perf: 100 libc free |
19 | * perf: 100 libc realloc | 47 | * perf: 100 libc realloc |
@@ -22,7 +50,7 @@ struct machines; | |||
22 | * perf: 100 [kernel] sys_perf_event_open | 50 | * perf: 100 [kernel] sys_perf_event_open |
23 | * perf: 200 perf main | 51 | * perf: 200 perf main |
24 | * perf: 200 perf run_command | 52 | * perf: 200 perf run_command |
25 | * perf: 200 perf comd_record | 53 | * perf: 200 perf cmd_record |
26 | * perf: 200 libc malloc | 54 | * perf: 200 libc malloc |
27 | * perf: 200 libc free | 55 | * perf: 200 libc free |
28 | * perf: 200 libc realloc | 56 | * perf: 200 libc realloc |
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c new file mode 100644 index 000000000000..0ac240db2e24 --- /dev/null +++ b/tools/perf/tests/hists_cumulate.c | |||
@@ -0,0 +1,726 @@ | |||
1 | #include "perf.h" | ||
2 | #include "util/debug.h" | ||
3 | #include "util/symbol.h" | ||
4 | #include "util/sort.h" | ||
5 | #include "util/evsel.h" | ||
6 | #include "util/evlist.h" | ||
7 | #include "util/machine.h" | ||
8 | #include "util/thread.h" | ||
9 | #include "util/parse-events.h" | ||
10 | #include "tests/tests.h" | ||
11 | #include "tests/hists_common.h" | ||
12 | |||
13 | struct sample { | ||
14 | u32 pid; | ||
15 | u64 ip; | ||
16 | struct thread *thread; | ||
17 | struct map *map; | ||
18 | struct symbol *sym; | ||
19 | }; | ||
20 | |||
21 | /* For the numbers, see hists_common.c */ | ||
22 | static struct sample fake_samples[] = { | ||
23 | /* perf [kernel] schedule() */ | ||
24 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, | ||
25 | /* perf [perf] main() */ | ||
26 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, }, | ||
27 | /* perf [perf] cmd_record() */ | ||
28 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_CMD_RECORD, }, | ||
29 | /* perf [libc] malloc() */ | ||
30 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, | ||
31 | /* perf [libc] free() */ | ||
32 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_FREE, }, | ||
33 | /* perf [perf] main() */ | ||
34 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, | ||
35 | /* perf [kernel] page_fault() */ | ||
36 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, | ||
37 | /* bash [bash] main() */ | ||
38 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, }, | ||
39 | /* bash [bash] xmalloc() */ | ||
40 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, | ||
41 | /* bash [kernel] page_fault() */ | ||
42 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, | ||
43 | }; | ||
44 | |||
45 | /* | ||
46 | * Will be casted to struct ip_callchain which has all 64 bit entries | ||
47 | * of nr and ips[]. | ||
48 | */ | ||
49 | static u64 fake_callchains[][10] = { | ||
50 | /* schedule => run_command => main */ | ||
51 | { 3, FAKE_IP_KERNEL_SCHEDULE, FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, }, | ||
52 | /* main */ | ||
53 | { 1, FAKE_IP_PERF_MAIN, }, | ||
54 | /* cmd_record => run_command => main */ | ||
55 | { 3, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, }, | ||
56 | /* malloc => cmd_record => run_command => main */ | ||
57 | { 4, FAKE_IP_LIBC_MALLOC, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND, | ||
58 | FAKE_IP_PERF_MAIN, }, | ||
59 | /* free => cmd_record => run_command => main */ | ||
60 | { 4, FAKE_IP_LIBC_FREE, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND, | ||
61 | FAKE_IP_PERF_MAIN, }, | ||
62 | /* main */ | ||
63 | { 1, FAKE_IP_PERF_MAIN, }, | ||
64 | /* page_fault => sys_perf_event_open => run_command => main */ | ||
65 | { 4, FAKE_IP_KERNEL_PAGE_FAULT, FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN, | ||
66 | FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, }, | ||
67 | /* main */ | ||
68 | { 1, FAKE_IP_BASH_MAIN, }, | ||
69 | /* xmalloc => malloc => xmalloc => malloc => xmalloc => main */ | ||
70 | { 6, FAKE_IP_BASH_XMALLOC, FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_XMALLOC, | ||
71 | FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_XMALLOC, FAKE_IP_BASH_MAIN, }, | ||
72 | /* page_fault => malloc => main */ | ||
73 | { 3, FAKE_IP_KERNEL_PAGE_FAULT, FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_MAIN, }, | ||
74 | }; | ||
75 | |||
76 | static int add_hist_entries(struct hists *hists, struct machine *machine) | ||
77 | { | ||
78 | struct addr_location al; | ||
79 | struct perf_evsel *evsel = hists_to_evsel(hists); | ||
80 | struct perf_sample sample = { .period = 1000, }; | ||
81 | size_t i; | ||
82 | |||
83 | for (i = 0; i < ARRAY_SIZE(fake_samples); i++) { | ||
84 | const union perf_event event = { | ||
85 | .header = { | ||
86 | .misc = PERF_RECORD_MISC_USER, | ||
87 | }, | ||
88 | }; | ||
89 | struct hist_entry_iter iter = { | ||
90 | .hide_unresolved = false, | ||
91 | }; | ||
92 | |||
93 | if (symbol_conf.cumulate_callchain) | ||
94 | iter.ops = &hist_iter_cumulative; | ||
95 | else | ||
96 | iter.ops = &hist_iter_normal; | ||
97 | |||
98 | sample.pid = fake_samples[i].pid; | ||
99 | sample.tid = fake_samples[i].pid; | ||
100 | sample.ip = fake_samples[i].ip; | ||
101 | sample.callchain = (struct ip_callchain *)fake_callchains[i]; | ||
102 | |||
103 | if (perf_event__preprocess_sample(&event, machine, &al, | ||
104 | &sample) < 0) | ||
105 | goto out; | ||
106 | |||
107 | if (hist_entry_iter__add(&iter, &al, evsel, &sample, | ||
108 | PERF_MAX_STACK_DEPTH, NULL) < 0) | ||
109 | goto out; | ||
110 | |||
111 | fake_samples[i].thread = al.thread; | ||
112 | fake_samples[i].map = al.map; | ||
113 | fake_samples[i].sym = al.sym; | ||
114 | } | ||
115 | |||
116 | return TEST_OK; | ||
117 | |||
118 | out: | ||
119 | pr_debug("Not enough memory for adding a hist entry\n"); | ||
120 | return TEST_FAIL; | ||
121 | } | ||
122 | |||
123 | static void del_hist_entries(struct hists *hists) | ||
124 | { | ||
125 | struct hist_entry *he; | ||
126 | struct rb_root *root_in; | ||
127 | struct rb_root *root_out; | ||
128 | struct rb_node *node; | ||
129 | |||
130 | if (sort__need_collapse) | ||
131 | root_in = &hists->entries_collapsed; | ||
132 | else | ||
133 | root_in = hists->entries_in; | ||
134 | |||
135 | root_out = &hists->entries; | ||
136 | |||
137 | while (!RB_EMPTY_ROOT(root_out)) { | ||
138 | node = rb_first(root_out); | ||
139 | |||
140 | he = rb_entry(node, struct hist_entry, rb_node); | ||
141 | rb_erase(node, root_out); | ||
142 | rb_erase(&he->rb_node_in, root_in); | ||
143 | hist_entry__free(he); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | typedef int (*test_fn_t)(struct perf_evsel *, struct machine *); | ||
148 | |||
149 | #define COMM(he) (thread__comm_str(he->thread)) | ||
150 | #define DSO(he) (he->ms.map->dso->short_name) | ||
151 | #define SYM(he) (he->ms.sym->name) | ||
152 | #define CPU(he) (he->cpu) | ||
153 | #define PID(he) (he->thread->tid) | ||
154 | #define DEPTH(he) (he->callchain->max_depth) | ||
155 | #define CDSO(cl) (cl->ms.map->dso->short_name) | ||
156 | #define CSYM(cl) (cl->ms.sym->name) | ||
157 | |||
158 | struct result { | ||
159 | u64 children; | ||
160 | u64 self; | ||
161 | const char *comm; | ||
162 | const char *dso; | ||
163 | const char *sym; | ||
164 | }; | ||
165 | |||
166 | struct callchain_result { | ||
167 | u64 nr; | ||
168 | struct { | ||
169 | const char *dso; | ||
170 | const char *sym; | ||
171 | } node[10]; | ||
172 | }; | ||
173 | |||
174 | static int do_test(struct hists *hists, struct result *expected, size_t nr_expected, | ||
175 | struct callchain_result *expected_callchain, size_t nr_callchain) | ||
176 | { | ||
177 | char buf[32]; | ||
178 | size_t i, c; | ||
179 | struct hist_entry *he; | ||
180 | struct rb_root *root; | ||
181 | struct rb_node *node; | ||
182 | struct callchain_node *cnode; | ||
183 | struct callchain_list *clist; | ||
184 | |||
185 | /* | ||
186 | * adding and deleting hist entries must be done outside of this | ||
187 | * function since TEST_ASSERT_VAL() returns in case of failure. | ||
188 | */ | ||
189 | hists__collapse_resort(hists, NULL); | ||
190 | hists__output_resort(hists); | ||
191 | |||
192 | if (verbose > 2) { | ||
193 | pr_info("use callchain: %d, cumulate callchain: %d\n", | ||
194 | symbol_conf.use_callchain, | ||
195 | symbol_conf.cumulate_callchain); | ||
196 | print_hists_out(hists); | ||
197 | } | ||
198 | |||
199 | root = &hists->entries; | ||
200 | for (node = rb_first(root), i = 0; | ||
201 | node && (he = rb_entry(node, struct hist_entry, rb_node)); | ||
202 | node = rb_next(node), i++) { | ||
203 | scnprintf(buf, sizeof(buf), "Invalid hist entry #%zd", i); | ||
204 | |||
205 | TEST_ASSERT_VAL("Incorrect number of hist entry", | ||
206 | i < nr_expected); | ||
207 | TEST_ASSERT_VAL(buf, he->stat.period == expected[i].self && | ||
208 | !strcmp(COMM(he), expected[i].comm) && | ||
209 | !strcmp(DSO(he), expected[i].dso) && | ||
210 | !strcmp(SYM(he), expected[i].sym)); | ||
211 | |||
212 | if (symbol_conf.cumulate_callchain) | ||
213 | TEST_ASSERT_VAL(buf, he->stat_acc->period == expected[i].children); | ||
214 | |||
215 | if (!symbol_conf.use_callchain) | ||
216 | continue; | ||
217 | |||
218 | /* check callchain entries */ | ||
219 | root = &he->callchain->node.rb_root; | ||
220 | cnode = rb_entry(rb_first(root), struct callchain_node, rb_node); | ||
221 | |||
222 | c = 0; | ||
223 | list_for_each_entry(clist, &cnode->val, list) { | ||
224 | scnprintf(buf, sizeof(buf), "Invalid callchain entry #%zd/%zd", i, c); | ||
225 | |||
226 | TEST_ASSERT_VAL("Incorrect number of callchain entry", | ||
227 | c < expected_callchain[i].nr); | ||
228 | TEST_ASSERT_VAL(buf, | ||
229 | !strcmp(CDSO(clist), expected_callchain[i].node[c].dso) && | ||
230 | !strcmp(CSYM(clist), expected_callchain[i].node[c].sym)); | ||
231 | c++; | ||
232 | } | ||
233 | /* TODO: handle multiple child nodes properly */ | ||
234 | TEST_ASSERT_VAL("Incorrect number of callchain entry", | ||
235 | c <= expected_callchain[i].nr); | ||
236 | } | ||
237 | TEST_ASSERT_VAL("Incorrect number of hist entry", | ||
238 | i == nr_expected); | ||
239 | TEST_ASSERT_VAL("Incorrect number of callchain entry", | ||
240 | !symbol_conf.use_callchain || nr_expected == nr_callchain); | ||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | /* NO callchain + NO children */ | ||
245 | static int test1(struct perf_evsel *evsel, struct machine *machine) | ||
246 | { | ||
247 | int err; | ||
248 | struct hists *hists = &evsel->hists; | ||
249 | /* | ||
250 | * expected output: | ||
251 | * | ||
252 | * Overhead Command Shared Object Symbol | ||
253 | * ======== ======= ============= ============== | ||
254 | * 20.00% perf perf [.] main | ||
255 | * 10.00% bash [kernel] [k] page_fault | ||
256 | * 10.00% bash bash [.] main | ||
257 | * 10.00% bash bash [.] xmalloc | ||
258 | * 10.00% perf [kernel] [k] page_fault | ||
259 | * 10.00% perf [kernel] [k] schedule | ||
260 | * 10.00% perf libc [.] free | ||
261 | * 10.00% perf libc [.] malloc | ||
262 | * 10.00% perf perf [.] cmd_record | ||
263 | */ | ||
264 | struct result expected[] = { | ||
265 | { 0, 2000, "perf", "perf", "main" }, | ||
266 | { 0, 1000, "bash", "[kernel]", "page_fault" }, | ||
267 | { 0, 1000, "bash", "bash", "main" }, | ||
268 | { 0, 1000, "bash", "bash", "xmalloc" }, | ||
269 | { 0, 1000, "perf", "[kernel]", "page_fault" }, | ||
270 | { 0, 1000, "perf", "[kernel]", "schedule" }, | ||
271 | { 0, 1000, "perf", "libc", "free" }, | ||
272 | { 0, 1000, "perf", "libc", "malloc" }, | ||
273 | { 0, 1000, "perf", "perf", "cmd_record" }, | ||
274 | }; | ||
275 | |||
276 | symbol_conf.use_callchain = false; | ||
277 | symbol_conf.cumulate_callchain = false; | ||
278 | |||
279 | setup_sorting(); | ||
280 | callchain_register_param(&callchain_param); | ||
281 | |||
282 | err = add_hist_entries(hists, machine); | ||
283 | if (err < 0) | ||
284 | goto out; | ||
285 | |||
286 | err = do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0); | ||
287 | |||
288 | out: | ||
289 | del_hist_entries(hists); | ||
290 | reset_output_field(); | ||
291 | return err; | ||
292 | } | ||
293 | |||
294 | /* callcain + NO children */ | ||
295 | static int test2(struct perf_evsel *evsel, struct machine *machine) | ||
296 | { | ||
297 | int err; | ||
298 | struct hists *hists = &evsel->hists; | ||
299 | /* | ||
300 | * expected output: | ||
301 | * | ||
302 | * Overhead Command Shared Object Symbol | ||
303 | * ======== ======= ============= ============== | ||
304 | * 20.00% perf perf [.] main | ||
305 | * | | ||
306 | * --- main | ||
307 | * | ||
308 | * 10.00% bash [kernel] [k] page_fault | ||
309 | * | | ||
310 | * --- page_fault | ||
311 | * malloc | ||
312 | * main | ||
313 | * | ||
314 | * 10.00% bash bash [.] main | ||
315 | * | | ||
316 | * --- main | ||
317 | * | ||
318 | * 10.00% bash bash [.] xmalloc | ||
319 | * | | ||
320 | * --- xmalloc | ||
321 | * malloc | ||
322 | * xmalloc <--- NOTE: there's a cycle | ||
323 | * malloc | ||
324 | * xmalloc | ||
325 | * main | ||
326 | * | ||
327 | * 10.00% perf [kernel] [k] page_fault | ||
328 | * | | ||
329 | * --- page_fault | ||
330 | * sys_perf_event_open | ||
331 | * run_command | ||
332 | * main | ||
333 | * | ||
334 | * 10.00% perf [kernel] [k] schedule | ||
335 | * | | ||
336 | * --- schedule | ||
337 | * run_command | ||
338 | * main | ||
339 | * | ||
340 | * 10.00% perf libc [.] free | ||
341 | * | | ||
342 | * --- free | ||
343 | * cmd_record | ||
344 | * run_command | ||
345 | * main | ||
346 | * | ||
347 | * 10.00% perf libc [.] malloc | ||
348 | * | | ||
349 | * --- malloc | ||
350 | * cmd_record | ||
351 | * run_command | ||
352 | * main | ||
353 | * | ||
354 | * 10.00% perf perf [.] cmd_record | ||
355 | * | | ||
356 | * --- cmd_record | ||
357 | * run_command | ||
358 | * main | ||
359 | * | ||
360 | */ | ||
361 | struct result expected[] = { | ||
362 | { 0, 2000, "perf", "perf", "main" }, | ||
363 | { 0, 1000, "bash", "[kernel]", "page_fault" }, | ||
364 | { 0, 1000, "bash", "bash", "main" }, | ||
365 | { 0, 1000, "bash", "bash", "xmalloc" }, | ||
366 | { 0, 1000, "perf", "[kernel]", "page_fault" }, | ||
367 | { 0, 1000, "perf", "[kernel]", "schedule" }, | ||
368 | { 0, 1000, "perf", "libc", "free" }, | ||
369 | { 0, 1000, "perf", "libc", "malloc" }, | ||
370 | { 0, 1000, "perf", "perf", "cmd_record" }, | ||
371 | }; | ||
372 | struct callchain_result expected_callchain[] = { | ||
373 | { | ||
374 | 1, { { "perf", "main" }, }, | ||
375 | }, | ||
376 | { | ||
377 | 3, { { "[kernel]", "page_fault" }, | ||
378 | { "libc", "malloc" }, | ||
379 | { "bash", "main" }, }, | ||
380 | }, | ||
381 | { | ||
382 | 1, { { "bash", "main" }, }, | ||
383 | }, | ||
384 | { | ||
385 | 6, { { "bash", "xmalloc" }, | ||
386 | { "libc", "malloc" }, | ||
387 | { "bash", "xmalloc" }, | ||
388 | { "libc", "malloc" }, | ||
389 | { "bash", "xmalloc" }, | ||
390 | { "bash", "main" }, }, | ||
391 | }, | ||
392 | { | ||
393 | 4, { { "[kernel]", "page_fault" }, | ||
394 | { "[kernel]", "sys_perf_event_open" }, | ||
395 | { "perf", "run_command" }, | ||
396 | { "perf", "main" }, }, | ||
397 | }, | ||
398 | { | ||
399 | 3, { { "[kernel]", "schedule" }, | ||
400 | { "perf", "run_command" }, | ||
401 | { "perf", "main" }, }, | ||
402 | }, | ||
403 | { | ||
404 | 4, { { "libc", "free" }, | ||
405 | { "perf", "cmd_record" }, | ||
406 | { "perf", "run_command" }, | ||
407 | { "perf", "main" }, }, | ||
408 | }, | ||
409 | { | ||
410 | 4, { { "libc", "malloc" }, | ||
411 | { "perf", "cmd_record" }, | ||
412 | { "perf", "run_command" }, | ||
413 | { "perf", "main" }, }, | ||
414 | }, | ||
415 | { | ||
416 | 3, { { "perf", "cmd_record" }, | ||
417 | { "perf", "run_command" }, | ||
418 | { "perf", "main" }, }, | ||
419 | }, | ||
420 | }; | ||
421 | |||
422 | symbol_conf.use_callchain = true; | ||
423 | symbol_conf.cumulate_callchain = false; | ||
424 | |||
425 | setup_sorting(); | ||
426 | callchain_register_param(&callchain_param); | ||
427 | |||
428 | err = add_hist_entries(hists, machine); | ||
429 | if (err < 0) | ||
430 | goto out; | ||
431 | |||
432 | err = do_test(hists, expected, ARRAY_SIZE(expected), | ||
433 | expected_callchain, ARRAY_SIZE(expected_callchain)); | ||
434 | |||
435 | out: | ||
436 | del_hist_entries(hists); | ||
437 | reset_output_field(); | ||
438 | return err; | ||
439 | } | ||
440 | |||
441 | /* NO callchain + children */ | ||
442 | static int test3(struct perf_evsel *evsel, struct machine *machine) | ||
443 | { | ||
444 | int err; | ||
445 | struct hists *hists = &evsel->hists; | ||
446 | /* | ||
447 | * expected output: | ||
448 | * | ||
449 | * Children Self Command Shared Object Symbol | ||
450 | * ======== ======== ======= ============= ======================= | ||
451 | * 70.00% 20.00% perf perf [.] main | ||
452 | * 50.00% 0.00% perf perf [.] run_command | ||
453 | * 30.00% 10.00% bash bash [.] main | ||
454 | * 30.00% 10.00% perf perf [.] cmd_record | ||
455 | * 20.00% 0.00% bash libc [.] malloc | ||
456 | * 10.00% 10.00% bash [kernel] [k] page_fault | ||
457 | * 10.00% 10.00% perf [kernel] [k] schedule | ||
458 | * 10.00% 0.00% perf [kernel] [k] sys_perf_event_open | ||
459 | * 10.00% 10.00% perf [kernel] [k] page_fault | ||
460 | * 10.00% 10.00% perf libc [.] free | ||
461 | * 10.00% 10.00% perf libc [.] malloc | ||
462 | * 10.00% 10.00% bash bash [.] xmalloc | ||
463 | */ | ||
464 | struct result expected[] = { | ||
465 | { 7000, 2000, "perf", "perf", "main" }, | ||
466 | { 5000, 0, "perf", "perf", "run_command" }, | ||
467 | { 3000, 1000, "bash", "bash", "main" }, | ||
468 | { 3000, 1000, "perf", "perf", "cmd_record" }, | ||
469 | { 2000, 0, "bash", "libc", "malloc" }, | ||
470 | { 1000, 1000, "bash", "[kernel]", "page_fault" }, | ||
471 | { 1000, 1000, "perf", "[kernel]", "schedule" }, | ||
472 | { 1000, 0, "perf", "[kernel]", "sys_perf_event_open" }, | ||
473 | { 1000, 1000, "perf", "[kernel]", "page_fault" }, | ||
474 | { 1000, 1000, "perf", "libc", "free" }, | ||
475 | { 1000, 1000, "perf", "libc", "malloc" }, | ||
476 | { 1000, 1000, "bash", "bash", "xmalloc" }, | ||
477 | }; | ||
478 | |||
479 | symbol_conf.use_callchain = false; | ||
480 | symbol_conf.cumulate_callchain = true; | ||
481 | |||
482 | setup_sorting(); | ||
483 | callchain_register_param(&callchain_param); | ||
484 | |||
485 | err = add_hist_entries(hists, machine); | ||
486 | if (err < 0) | ||
487 | goto out; | ||
488 | |||
489 | err = do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0); | ||
490 | |||
491 | out: | ||
492 | del_hist_entries(hists); | ||
493 | reset_output_field(); | ||
494 | return err; | ||
495 | } | ||
496 | |||
497 | /* callchain + children */ | ||
498 | static int test4(struct perf_evsel *evsel, struct machine *machine) | ||
499 | { | ||
500 | int err; | ||
501 | struct hists *hists = &evsel->hists; | ||
502 | /* | ||
503 | * expected output: | ||
504 | * | ||
505 | * Children Self Command Shared Object Symbol | ||
506 | * ======== ======== ======= ============= ======================= | ||
507 | * 70.00% 20.00% perf perf [.] main | ||
508 | * | | ||
509 | * --- main | ||
510 | * | ||
511 | * 50.00% 0.00% perf perf [.] run_command | ||
512 | * | | ||
513 | * --- run_command | ||
514 | * main | ||
515 | * | ||
516 | * 30.00% 10.00% bash bash [.] main | ||
517 | * | | ||
518 | * --- main | ||
519 | * | ||
520 | * 30.00% 10.00% perf perf [.] cmd_record | ||
521 | * | | ||
522 | * --- cmd_record | ||
523 | * run_command | ||
524 | * main | ||
525 | * | ||
526 | * 20.00% 0.00% bash libc [.] malloc | ||
527 | * | | ||
528 | * --- malloc | ||
529 | * | | ||
530 | * |--50.00%-- xmalloc | ||
531 | * | main | ||
532 | * --50.00%-- main | ||
533 | * | ||
534 | * 10.00% 10.00% bash [kernel] [k] page_fault | ||
535 | * | | ||
536 | * --- page_fault | ||
537 | * malloc | ||
538 | * main | ||
539 | * | ||
540 | * 10.00% 10.00% perf [kernel] [k] schedule | ||
541 | * | | ||
542 | * --- schedule | ||
543 | * run_command | ||
544 | * main | ||
545 | * | ||
546 | * 10.00% 0.00% perf [kernel] [k] sys_perf_event_open | ||
547 | * | | ||
548 | * --- sys_perf_event_open | ||
549 | * run_command | ||
550 | * main | ||
551 | * | ||
552 | * 10.00% 10.00% perf [kernel] [k] page_fault | ||
553 | * | | ||
554 | * --- page_fault | ||
555 | * sys_perf_event_open | ||
556 | * run_command | ||
557 | * main | ||
558 | * | ||
559 | * 10.00% 10.00% perf libc [.] free | ||
560 | * | | ||
561 | * --- free | ||
562 | * cmd_record | ||
563 | * run_command | ||
564 | * main | ||
565 | * | ||
566 | * 10.00% 10.00% perf libc [.] malloc | ||
567 | * | | ||
568 | * --- malloc | ||
569 | * cmd_record | ||
570 | * run_command | ||
571 | * main | ||
572 | * | ||
573 | * 10.00% 10.00% bash bash [.] xmalloc | ||
574 | * | | ||
575 | * --- xmalloc | ||
576 | * malloc | ||
577 | * xmalloc <--- NOTE: there's a cycle | ||
578 | * malloc | ||
579 | * xmalloc | ||
580 | * main | ||
581 | * | ||
582 | */ | ||
583 | struct result expected[] = { | ||
584 | { 7000, 2000, "perf", "perf", "main" }, | ||
585 | { 5000, 0, "perf", "perf", "run_command" }, | ||
586 | { 3000, 1000, "bash", "bash", "main" }, | ||
587 | { 3000, 1000, "perf", "perf", "cmd_record" }, | ||
588 | { 2000, 0, "bash", "libc", "malloc" }, | ||
589 | { 1000, 1000, "bash", "[kernel]", "page_fault" }, | ||
590 | { 1000, 1000, "perf", "[kernel]", "schedule" }, | ||
591 | { 1000, 0, "perf", "[kernel]", "sys_perf_event_open" }, | ||
592 | { 1000, 1000, "perf", "[kernel]", "page_fault" }, | ||
593 | { 1000, 1000, "perf", "libc", "free" }, | ||
594 | { 1000, 1000, "perf", "libc", "malloc" }, | ||
595 | { 1000, 1000, "bash", "bash", "xmalloc" }, | ||
596 | }; | ||
597 | struct callchain_result expected_callchain[] = { | ||
598 | { | ||
599 | 1, { { "perf", "main" }, }, | ||
600 | }, | ||
601 | { | ||
602 | 2, { { "perf", "run_command" }, | ||
603 | { "perf", "main" }, }, | ||
604 | }, | ||
605 | { | ||
606 | 1, { { "bash", "main" }, }, | ||
607 | }, | ||
608 | { | ||
609 | 3, { { "perf", "cmd_record" }, | ||
610 | { "perf", "run_command" }, | ||
611 | { "perf", "main" }, }, | ||
612 | }, | ||
613 | { | ||
614 | 4, { { "libc", "malloc" }, | ||
615 | { "bash", "xmalloc" }, | ||
616 | { "bash", "main" }, | ||
617 | { "bash", "main" }, }, | ||
618 | }, | ||
619 | { | ||
620 | 3, { { "[kernel]", "page_fault" }, | ||
621 | { "libc", "malloc" }, | ||
622 | { "bash", "main" }, }, | ||
623 | }, | ||
624 | { | ||
625 | 3, { { "[kernel]", "schedule" }, | ||
626 | { "perf", "run_command" }, | ||
627 | { "perf", "main" }, }, | ||
628 | }, | ||
629 | { | ||
630 | 3, { { "[kernel]", "sys_perf_event_open" }, | ||
631 | { "perf", "run_command" }, | ||
632 | { "perf", "main" }, }, | ||
633 | }, | ||
634 | { | ||
635 | 4, { { "[kernel]", "page_fault" }, | ||
636 | { "[kernel]", "sys_perf_event_open" }, | ||
637 | { "perf", "run_command" }, | ||
638 | { "perf", "main" }, }, | ||
639 | }, | ||
640 | { | ||
641 | 4, { { "libc", "free" }, | ||
642 | { "perf", "cmd_record" }, | ||
643 | { "perf", "run_command" }, | ||
644 | { "perf", "main" }, }, | ||
645 | }, | ||
646 | { | ||
647 | 4, { { "libc", "malloc" }, | ||
648 | { "perf", "cmd_record" }, | ||
649 | { "perf", "run_command" }, | ||
650 | { "perf", "main" }, }, | ||
651 | }, | ||
652 | { | ||
653 | 6, { { "bash", "xmalloc" }, | ||
654 | { "libc", "malloc" }, | ||
655 | { "bash", "xmalloc" }, | ||
656 | { "libc", "malloc" }, | ||
657 | { "bash", "xmalloc" }, | ||
658 | { "bash", "main" }, }, | ||
659 | }, | ||
660 | }; | ||
661 | |||
662 | symbol_conf.use_callchain = true; | ||
663 | symbol_conf.cumulate_callchain = true; | ||
664 | |||
665 | setup_sorting(); | ||
666 | callchain_register_param(&callchain_param); | ||
667 | |||
668 | err = add_hist_entries(hists, machine); | ||
669 | if (err < 0) | ||
670 | goto out; | ||
671 | |||
672 | err = do_test(hists, expected, ARRAY_SIZE(expected), | ||
673 | expected_callchain, ARRAY_SIZE(expected_callchain)); | ||
674 | |||
675 | out: | ||
676 | del_hist_entries(hists); | ||
677 | reset_output_field(); | ||
678 | return err; | ||
679 | } | ||
680 | |||
681 | int test__hists_cumulate(void) | ||
682 | { | ||
683 | int err = TEST_FAIL; | ||
684 | struct machines machines; | ||
685 | struct machine *machine; | ||
686 | struct perf_evsel *evsel; | ||
687 | struct perf_evlist *evlist = perf_evlist__new(); | ||
688 | size_t i; | ||
689 | test_fn_t testcases[] = { | ||
690 | test1, | ||
691 | test2, | ||
692 | test3, | ||
693 | test4, | ||
694 | }; | ||
695 | |||
696 | TEST_ASSERT_VAL("No memory", evlist); | ||
697 | |||
698 | err = parse_events(evlist, "cpu-clock"); | ||
699 | if (err) | ||
700 | goto out; | ||
701 | |||
702 | machines__init(&machines); | ||
703 | |||
704 | /* setup threads/dso/map/symbols also */ | ||
705 | machine = setup_fake_machine(&machines); | ||
706 | if (!machine) | ||
707 | goto out; | ||
708 | |||
709 | if (verbose > 1) | ||
710 | machine__fprintf(machine, stderr); | ||
711 | |||
712 | evsel = perf_evlist__first(evlist); | ||
713 | |||
714 | for (i = 0; i < ARRAY_SIZE(testcases); i++) { | ||
715 | err = testcases[i](evsel, machine); | ||
716 | if (err < 0) | ||
717 | break; | ||
718 | } | ||
719 | |||
720 | out: | ||
721 | /* tear down everything */ | ||
722 | perf_evlist__delete(evlist); | ||
723 | machines__exit(&machines); | ||
724 | |||
725 | return err; | ||
726 | } | ||
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index c5ba924a3581..821f581fd930 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c | |||
@@ -21,33 +21,33 @@ struct sample { | |||
21 | /* For the numbers, see hists_common.c */ | 21 | /* For the numbers, see hists_common.c */ |
22 | static struct sample fake_samples[] = { | 22 | static struct sample fake_samples[] = { |
23 | /* perf [kernel] schedule() */ | 23 | /* perf [kernel] schedule() */ |
24 | { .pid = 100, .ip = 0xf0000 + 700, }, | 24 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, |
25 | /* perf [perf] main() */ | 25 | /* perf [perf] main() */ |
26 | { .pid = 100, .ip = 0x40000 + 700, }, | 26 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, }, |
27 | /* perf [libc] malloc() */ | 27 | /* perf [libc] malloc() */ |
28 | { .pid = 100, .ip = 0x50000 + 700, }, | 28 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, |
29 | /* perf [perf] main() */ | 29 | /* perf [perf] main() */ |
30 | { .pid = 200, .ip = 0x40000 + 700, }, /* will be merged */ | 30 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, /* will be merged */ |
31 | /* perf [perf] cmd_record() */ | 31 | /* perf [perf] cmd_record() */ |
32 | { .pid = 200, .ip = 0x40000 + 900, }, | 32 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, }, |
33 | /* perf [kernel] page_fault() */ | 33 | /* perf [kernel] page_fault() */ |
34 | { .pid = 200, .ip = 0xf0000 + 800, }, | 34 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, |
35 | /* bash [bash] main() */ | 35 | /* bash [bash] main() */ |
36 | { .pid = 300, .ip = 0x40000 + 700, }, | 36 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, }, |
37 | /* bash [bash] xmalloc() */ | 37 | /* bash [bash] xmalloc() */ |
38 | { .pid = 300, .ip = 0x40000 + 800, }, | 38 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, |
39 | /* bash [libc] malloc() */ | 39 | /* bash [libc] malloc() */ |
40 | { .pid = 300, .ip = 0x50000 + 700, }, | 40 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, }, |
41 | /* bash [kernel] page_fault() */ | 41 | /* bash [kernel] page_fault() */ |
42 | { .pid = 300, .ip = 0xf0000 + 800, }, | 42 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, |
43 | }; | 43 | }; |
44 | 44 | ||
45 | static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | 45 | static int add_hist_entries(struct perf_evlist *evlist, |
46 | struct machine *machine __maybe_unused) | ||
46 | { | 47 | { |
47 | struct perf_evsel *evsel; | 48 | struct perf_evsel *evsel; |
48 | struct addr_location al; | 49 | struct addr_location al; |
49 | struct hist_entry *he; | 50 | struct perf_sample sample = { .period = 100, }; |
50 | struct perf_sample sample = { .cpu = 0, }; | ||
51 | size_t i; | 51 | size_t i; |
52 | 52 | ||
53 | /* | 53 | /* |
@@ -62,6 +62,10 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
62 | .misc = PERF_RECORD_MISC_USER, | 62 | .misc = PERF_RECORD_MISC_USER, |
63 | }, | 63 | }, |
64 | }; | 64 | }; |
65 | struct hist_entry_iter iter = { | ||
66 | .ops = &hist_iter_normal, | ||
67 | .hide_unresolved = false, | ||
68 | }; | ||
65 | 69 | ||
66 | /* make sure it has no filter at first */ | 70 | /* make sure it has no filter at first */ |
67 | evsel->hists.thread_filter = NULL; | 71 | evsel->hists.thread_filter = NULL; |
@@ -76,18 +80,13 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
76 | &sample) < 0) | 80 | &sample) < 0) |
77 | goto out; | 81 | goto out; |
78 | 82 | ||
79 | he = __hists__add_entry(&evsel->hists, &al, NULL, | 83 | if (hist_entry_iter__add(&iter, &al, evsel, &sample, |
80 | NULL, NULL, 100, 1, 0); | 84 | PERF_MAX_STACK_DEPTH, NULL) < 0) |
81 | if (he == NULL) | ||
82 | goto out; | 85 | goto out; |
83 | 86 | ||
84 | fake_samples[i].thread = al.thread; | 87 | fake_samples[i].thread = al.thread; |
85 | fake_samples[i].map = al.map; | 88 | fake_samples[i].map = al.map; |
86 | fake_samples[i].sym = al.sym; | 89 | fake_samples[i].sym = al.sym; |
87 | |||
88 | hists__inc_nr_events(he->hists, PERF_RECORD_SAMPLE); | ||
89 | if (!he->filtered) | ||
90 | he->hists->stats.nr_non_filtered_samples++; | ||
91 | } | 90 | } |
92 | } | 91 | } |
93 | 92 | ||
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 5ffa2c3eb77d..d4b34b0f50a2 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c | |||
@@ -21,41 +21,41 @@ struct sample { | |||
21 | /* For the numbers, see hists_common.c */ | 21 | /* For the numbers, see hists_common.c */ |
22 | static struct sample fake_common_samples[] = { | 22 | static struct sample fake_common_samples[] = { |
23 | /* perf [kernel] schedule() */ | 23 | /* perf [kernel] schedule() */ |
24 | { .pid = 100, .ip = 0xf0000 + 700, }, | 24 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, |
25 | /* perf [perf] main() */ | 25 | /* perf [perf] main() */ |
26 | { .pid = 200, .ip = 0x40000 + 700, }, | 26 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, |
27 | /* perf [perf] cmd_record() */ | 27 | /* perf [perf] cmd_record() */ |
28 | { .pid = 200, .ip = 0x40000 + 900, }, | 28 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, }, |
29 | /* bash [bash] xmalloc() */ | 29 | /* bash [bash] xmalloc() */ |
30 | { .pid = 300, .ip = 0x40000 + 800, }, | 30 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, |
31 | /* bash [libc] malloc() */ | 31 | /* bash [libc] malloc() */ |
32 | { .pid = 300, .ip = 0x50000 + 700, }, | 32 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, }, |
33 | }; | 33 | }; |
34 | 34 | ||
35 | static struct sample fake_samples[][5] = { | 35 | static struct sample fake_samples[][5] = { |
36 | { | 36 | { |
37 | /* perf [perf] run_command() */ | 37 | /* perf [perf] run_command() */ |
38 | { .pid = 100, .ip = 0x40000 + 800, }, | 38 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_RUN_COMMAND, }, |
39 | /* perf [libc] malloc() */ | 39 | /* perf [libc] malloc() */ |
40 | { .pid = 100, .ip = 0x50000 + 700, }, | 40 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, |
41 | /* perf [kernel] page_fault() */ | 41 | /* perf [kernel] page_fault() */ |
42 | { .pid = 100, .ip = 0xf0000 + 800, }, | 42 | { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, |
43 | /* perf [kernel] sys_perf_event_open() */ | 43 | /* perf [kernel] sys_perf_event_open() */ |
44 | { .pid = 200, .ip = 0xf0000 + 900, }, | 44 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN, }, |
45 | /* bash [libc] free() */ | 45 | /* bash [libc] free() */ |
46 | { .pid = 300, .ip = 0x50000 + 800, }, | 46 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_FREE, }, |
47 | }, | 47 | }, |
48 | { | 48 | { |
49 | /* perf [libc] free() */ | 49 | /* perf [libc] free() */ |
50 | { .pid = 200, .ip = 0x50000 + 800, }, | 50 | { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_LIBC_FREE, }, |
51 | /* bash [libc] malloc() */ | 51 | /* bash [libc] malloc() */ |
52 | { .pid = 300, .ip = 0x50000 + 700, }, /* will be merged */ | 52 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, }, /* will be merged */ |
53 | /* bash [bash] xfee() */ | 53 | /* bash [bash] xfee() */ |
54 | { .pid = 300, .ip = 0x40000 + 900, }, | 54 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XFREE, }, |
55 | /* bash [libc] realloc() */ | 55 | /* bash [libc] realloc() */ |
56 | { .pid = 300, .ip = 0x50000 + 900, }, | 56 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_REALLOC, }, |
57 | /* bash [kernel] page_fault() */ | 57 | /* bash [kernel] page_fault() */ |
58 | { .pid = 300, .ip = 0xf0000 + 800, }, | 58 | { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, |
59 | }, | 59 | }, |
60 | }; | 60 | }; |
61 | 61 | ||
@@ -64,7 +64,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
64 | struct perf_evsel *evsel; | 64 | struct perf_evsel *evsel; |
65 | struct addr_location al; | 65 | struct addr_location al; |
66 | struct hist_entry *he; | 66 | struct hist_entry *he; |
67 | struct perf_sample sample = { .cpu = 0, }; | 67 | struct perf_sample sample = { .period = 1, }; |
68 | size_t i = 0, k; | 68 | size_t i = 0, k; |
69 | 69 | ||
70 | /* | 70 | /* |
@@ -88,7 +88,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
88 | goto out; | 88 | goto out; |
89 | 89 | ||
90 | he = __hists__add_entry(&evsel->hists, &al, NULL, | 90 | he = __hists__add_entry(&evsel->hists, &al, NULL, |
91 | NULL, NULL, 1, 1, 0); | 91 | NULL, NULL, 1, 1, 0, true); |
92 | if (he == NULL) | 92 | if (he == NULL) |
93 | goto out; | 93 | goto out; |
94 | 94 | ||
@@ -112,7 +112,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
112 | goto out; | 112 | goto out; |
113 | 113 | ||
114 | he = __hists__add_entry(&evsel->hists, &al, NULL, | 114 | he = __hists__add_entry(&evsel->hists, &al, NULL, |
115 | NULL, NULL, 1, 1, 0); | 115 | NULL, NULL, 1, 1, 0, true); |
116 | if (he == NULL) | 116 | if (he == NULL) |
117 | goto out; | 117 | goto out; |
118 | 118 | ||
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index a16850551797..e3bbd6c54c1b 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c | |||
@@ -22,31 +22,31 @@ struct sample { | |||
22 | /* For the numbers, see hists_common.c */ | 22 | /* For the numbers, see hists_common.c */ |
23 | static struct sample fake_samples[] = { | 23 | static struct sample fake_samples[] = { |
24 | /* perf [kernel] schedule() */ | 24 | /* perf [kernel] schedule() */ |
25 | { .cpu = 0, .pid = 100, .ip = 0xf0000 + 700, }, | 25 | { .cpu = 0, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, |
26 | /* perf [perf] main() */ | 26 | /* perf [perf] main() */ |
27 | { .cpu = 1, .pid = 100, .ip = 0x40000 + 700, }, | 27 | { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, }, |
28 | /* perf [perf] cmd_record() */ | 28 | /* perf [perf] cmd_record() */ |
29 | { .cpu = 1, .pid = 100, .ip = 0x40000 + 900, }, | 29 | { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_CMD_RECORD, }, |
30 | /* perf [libc] malloc() */ | 30 | /* perf [libc] malloc() */ |
31 | { .cpu = 1, .pid = 100, .ip = 0x50000 + 700, }, | 31 | { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, |
32 | /* perf [libc] free() */ | 32 | /* perf [libc] free() */ |
33 | { .cpu = 2, .pid = 100, .ip = 0x50000 + 800, }, | 33 | { .cpu = 2, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_FREE, }, |
34 | /* perf [perf] main() */ | 34 | /* perf [perf] main() */ |
35 | { .cpu = 2, .pid = 200, .ip = 0x40000 + 700, }, | 35 | { .cpu = 2, .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, |
36 | /* perf [kernel] page_fault() */ | 36 | /* perf [kernel] page_fault() */ |
37 | { .cpu = 2, .pid = 200, .ip = 0xf0000 + 800, }, | 37 | { .cpu = 2, .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, |
38 | /* bash [bash] main() */ | 38 | /* bash [bash] main() */ |
39 | { .cpu = 3, .pid = 300, .ip = 0x40000 + 700, }, | 39 | { .cpu = 3, .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, }, |
40 | /* bash [bash] xmalloc() */ | 40 | /* bash [bash] xmalloc() */ |
41 | { .cpu = 0, .pid = 300, .ip = 0x40000 + 800, }, | 41 | { .cpu = 0, .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, |
42 | /* bash [kernel] page_fault() */ | 42 | /* bash [kernel] page_fault() */ |
43 | { .cpu = 1, .pid = 300, .ip = 0xf0000 + 800, }, | 43 | { .cpu = 1, .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, |
44 | }; | 44 | }; |
45 | 45 | ||
46 | static int add_hist_entries(struct hists *hists, struct machine *machine) | 46 | static int add_hist_entries(struct hists *hists, struct machine *machine) |
47 | { | 47 | { |
48 | struct addr_location al; | 48 | struct addr_location al; |
49 | struct hist_entry *he; | 49 | struct perf_evsel *evsel = hists_to_evsel(hists); |
50 | struct perf_sample sample = { .period = 100, }; | 50 | struct perf_sample sample = { .period = 100, }; |
51 | size_t i; | 51 | size_t i; |
52 | 52 | ||
@@ -56,6 +56,10 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) | |||
56 | .misc = PERF_RECORD_MISC_USER, | 56 | .misc = PERF_RECORD_MISC_USER, |
57 | }, | 57 | }, |
58 | }; | 58 | }; |
59 | struct hist_entry_iter iter = { | ||
60 | .ops = &hist_iter_normal, | ||
61 | .hide_unresolved = false, | ||
62 | }; | ||
59 | 63 | ||
60 | sample.cpu = fake_samples[i].cpu; | 64 | sample.cpu = fake_samples[i].cpu; |
61 | sample.pid = fake_samples[i].pid; | 65 | sample.pid = fake_samples[i].pid; |
@@ -66,9 +70,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) | |||
66 | &sample) < 0) | 70 | &sample) < 0) |
67 | goto out; | 71 | goto out; |
68 | 72 | ||
69 | he = __hists__add_entry(hists, &al, NULL, NULL, NULL, | 73 | if (hist_entry_iter__add(&iter, &al, evsel, &sample, |
70 | sample.period, 1, 0); | 74 | PERF_MAX_STACK_DEPTH, NULL) < 0) |
71 | if (he == NULL) | ||
72 | goto out; | 75 | goto out; |
73 | 76 | ||
74 | fake_samples[i].thread = al.thread; | 77 | fake_samples[i].thread = al.thread; |
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index d76c0e2e6635..022bb68fd9c7 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
@@ -45,6 +45,7 @@ int test__hists_filter(void); | |||
45 | int test__mmap_thread_lookup(void); | 45 | int test__mmap_thread_lookup(void); |
46 | int test__thread_mg_share(void); | 46 | int test__thread_mg_share(void); |
47 | int test__hists_output(void); | 47 | int test__hists_output(void); |
48 | int test__hists_cumulate(void); | ||
48 | 49 | ||
49 | #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) | 50 | #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) |
50 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | 51 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c index d11541d4d7d7..3ccf6e14f89b 100644 --- a/tools/perf/ui/browser.c +++ b/tools/perf/ui/browser.c | |||
@@ -194,7 +194,7 @@ int ui_browser__warning(struct ui_browser *browser, int timeout, | |||
194 | ui_helpline__vpush(format, args); | 194 | ui_helpline__vpush(format, args); |
195 | va_end(args); | 195 | va_end(args); |
196 | } else { | 196 | } else { |
197 | while ((key == ui__question_window("Warning!", text, | 197 | while ((key = ui__question_window("Warning!", text, |
198 | "Press any key...", | 198 | "Press any key...", |
199 | timeout)) == K_RESIZE) | 199 | timeout)) == K_RESIZE) |
200 | ui_browser__handle_resize(browser); | 200 | ui_browser__handle_resize(browser); |
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 1c331b934ffc..52c03fbbba17 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -37,7 +37,6 @@ static int hists__browser_title(struct hists *hists, char *bf, size_t size, | |||
37 | static void hist_browser__update_nr_entries(struct hist_browser *hb); | 37 | static void hist_browser__update_nr_entries(struct hist_browser *hb); |
38 | 38 | ||
39 | static struct rb_node *hists__filter_entries(struct rb_node *nd, | 39 | static struct rb_node *hists__filter_entries(struct rb_node *nd, |
40 | struct hists *hists, | ||
41 | float min_pcnt); | 40 | float min_pcnt); |
42 | 41 | ||
43 | static bool hist_browser__has_filter(struct hist_browser *hb) | 42 | static bool hist_browser__has_filter(struct hist_browser *hb) |
@@ -319,7 +318,7 @@ __hist_browser__set_folding(struct hist_browser *browser, bool unfold) | |||
319 | struct hists *hists = browser->hists; | 318 | struct hists *hists = browser->hists; |
320 | 319 | ||
321 | for (nd = rb_first(&hists->entries); | 320 | for (nd = rb_first(&hists->entries); |
322 | (nd = hists__filter_entries(nd, hists, browser->min_pcnt)) != NULL; | 321 | (nd = hists__filter_entries(nd, browser->min_pcnt)) != NULL; |
323 | nd = rb_next(nd)) { | 322 | nd = rb_next(nd)) { |
324 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 323 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
325 | hist_entry__set_folding(he, unfold); | 324 | hist_entry__set_folding(he, unfold); |
@@ -651,13 +650,36 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ | |||
651 | __hpp__slsmg_color_printf, true); \ | 650 | __hpp__slsmg_color_printf, true); \ |
652 | } | 651 | } |
653 | 652 | ||
653 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ | ||
654 | static u64 __hpp_get_acc_##_field(struct hist_entry *he) \ | ||
655 | { \ | ||
656 | return he->stat_acc->_field; \ | ||
657 | } \ | ||
658 | \ | ||
659 | static int \ | ||
660 | hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ | ||
661 | struct perf_hpp *hpp, \ | ||
662 | struct hist_entry *he) \ | ||
663 | { \ | ||
664 | if (!symbol_conf.cumulate_callchain) { \ | ||
665 | int ret = scnprintf(hpp->buf, hpp->size, "%8s", "N/A"); \ | ||
666 | slsmg_printf("%s", hpp->buf); \ | ||
667 | \ | ||
668 | return ret; \ | ||
669 | } \ | ||
670 | return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %6.2f%%", \ | ||
671 | __hpp__slsmg_color_printf, true); \ | ||
672 | } | ||
673 | |||
654 | __HPP_COLOR_PERCENT_FN(overhead, period) | 674 | __HPP_COLOR_PERCENT_FN(overhead, period) |
655 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) | 675 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) |
656 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) | 676 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) |
657 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) | 677 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) |
658 | __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) | 678 | __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) |
679 | __HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period) | ||
659 | 680 | ||
660 | #undef __HPP_COLOR_PERCENT_FN | 681 | #undef __HPP_COLOR_PERCENT_FN |
682 | #undef __HPP_COLOR_ACC_PERCENT_FN | ||
661 | 683 | ||
662 | void hist_browser__init_hpp(void) | 684 | void hist_browser__init_hpp(void) |
663 | { | 685 | { |
@@ -671,6 +693,8 @@ void hist_browser__init_hpp(void) | |||
671 | hist_browser__hpp_color_overhead_guest_sys; | 693 | hist_browser__hpp_color_overhead_guest_sys; |
672 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = | 694 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = |
673 | hist_browser__hpp_color_overhead_guest_us; | 695 | hist_browser__hpp_color_overhead_guest_us; |
696 | perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color = | ||
697 | hist_browser__hpp_color_overhead_acc; | ||
674 | } | 698 | } |
675 | 699 | ||
676 | static int hist_browser__show_entry(struct hist_browser *browser, | 700 | static int hist_browser__show_entry(struct hist_browser *browser, |
@@ -783,15 +807,12 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser) | |||
783 | 807 | ||
784 | for (nd = browser->top; nd; nd = rb_next(nd)) { | 808 | for (nd = browser->top; nd; nd = rb_next(nd)) { |
785 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 809 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
786 | u64 total = hists__total_period(h->hists); | 810 | float percent; |
787 | float percent = 0.0; | ||
788 | 811 | ||
789 | if (h->filtered) | 812 | if (h->filtered) |
790 | continue; | 813 | continue; |
791 | 814 | ||
792 | if (total) | 815 | percent = hist_entry__get_percent_limit(h); |
793 | percent = h->stat.period * 100.0 / total; | ||
794 | |||
795 | if (percent < hb->min_pcnt) | 816 | if (percent < hb->min_pcnt) |
796 | continue; | 817 | continue; |
797 | 818 | ||
@@ -804,16 +825,11 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser) | |||
804 | } | 825 | } |
805 | 826 | ||
806 | static struct rb_node *hists__filter_entries(struct rb_node *nd, | 827 | static struct rb_node *hists__filter_entries(struct rb_node *nd, |
807 | struct hists *hists, | ||
808 | float min_pcnt) | 828 | float min_pcnt) |
809 | { | 829 | { |
810 | while (nd != NULL) { | 830 | while (nd != NULL) { |
811 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 831 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
812 | u64 total = hists__total_period(hists); | 832 | float percent = hist_entry__get_percent_limit(h); |
813 | float percent = 0.0; | ||
814 | |||
815 | if (total) | ||
816 | percent = h->stat.period * 100.0 / total; | ||
817 | 833 | ||
818 | if (!h->filtered && percent >= min_pcnt) | 834 | if (!h->filtered && percent >= min_pcnt) |
819 | return nd; | 835 | return nd; |
@@ -825,16 +841,11 @@ static struct rb_node *hists__filter_entries(struct rb_node *nd, | |||
825 | } | 841 | } |
826 | 842 | ||
827 | static struct rb_node *hists__filter_prev_entries(struct rb_node *nd, | 843 | static struct rb_node *hists__filter_prev_entries(struct rb_node *nd, |
828 | struct hists *hists, | ||
829 | float min_pcnt) | 844 | float min_pcnt) |
830 | { | 845 | { |
831 | while (nd != NULL) { | 846 | while (nd != NULL) { |
832 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 847 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
833 | u64 total = hists__total_period(hists); | 848 | float percent = hist_entry__get_percent_limit(h); |
834 | float percent = 0.0; | ||
835 | |||
836 | if (total) | ||
837 | percent = h->stat.period * 100.0 / total; | ||
838 | 849 | ||
839 | if (!h->filtered && percent >= min_pcnt) | 850 | if (!h->filtered && percent >= min_pcnt) |
840 | return nd; | 851 | return nd; |
@@ -863,14 +874,14 @@ static void ui_browser__hists_seek(struct ui_browser *browser, | |||
863 | switch (whence) { | 874 | switch (whence) { |
864 | case SEEK_SET: | 875 | case SEEK_SET: |
865 | nd = hists__filter_entries(rb_first(browser->entries), | 876 | nd = hists__filter_entries(rb_first(browser->entries), |
866 | hb->hists, hb->min_pcnt); | 877 | hb->min_pcnt); |
867 | break; | 878 | break; |
868 | case SEEK_CUR: | 879 | case SEEK_CUR: |
869 | nd = browser->top; | 880 | nd = browser->top; |
870 | goto do_offset; | 881 | goto do_offset; |
871 | case SEEK_END: | 882 | case SEEK_END: |
872 | nd = hists__filter_prev_entries(rb_last(browser->entries), | 883 | nd = hists__filter_prev_entries(rb_last(browser->entries), |
873 | hb->hists, hb->min_pcnt); | 884 | hb->min_pcnt); |
874 | first = false; | 885 | first = false; |
875 | break; | 886 | break; |
876 | default: | 887 | default: |
@@ -913,8 +924,7 @@ do_offset: | |||
913 | break; | 924 | break; |
914 | } | 925 | } |
915 | } | 926 | } |
916 | nd = hists__filter_entries(rb_next(nd), hb->hists, | 927 | nd = hists__filter_entries(rb_next(nd), hb->min_pcnt); |
917 | hb->min_pcnt); | ||
918 | if (nd == NULL) | 928 | if (nd == NULL) |
919 | break; | 929 | break; |
920 | --offset; | 930 | --offset; |
@@ -947,7 +957,7 @@ do_offset: | |||
947 | } | 957 | } |
948 | } | 958 | } |
949 | 959 | ||
950 | nd = hists__filter_prev_entries(rb_prev(nd), hb->hists, | 960 | nd = hists__filter_prev_entries(rb_prev(nd), |
951 | hb->min_pcnt); | 961 | hb->min_pcnt); |
952 | if (nd == NULL) | 962 | if (nd == NULL) |
953 | break; | 963 | break; |
@@ -1126,7 +1136,6 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, | |||
1126 | static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) | 1136 | static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) |
1127 | { | 1137 | { |
1128 | struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries), | 1138 | struct rb_node *nd = hists__filter_entries(rb_first(browser->b.entries), |
1129 | browser->hists, | ||
1130 | browser->min_pcnt); | 1139 | browser->min_pcnt); |
1131 | int printed = 0; | 1140 | int printed = 0; |
1132 | 1141 | ||
@@ -1134,8 +1143,7 @@ static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) | |||
1134 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 1143 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
1135 | 1144 | ||
1136 | printed += hist_browser__fprintf_entry(browser, h, fp); | 1145 | printed += hist_browser__fprintf_entry(browser, h, fp); |
1137 | nd = hists__filter_entries(rb_next(nd), browser->hists, | 1146 | nd = hists__filter_entries(rb_next(nd), browser->min_pcnt); |
1138 | browser->min_pcnt); | ||
1139 | } | 1147 | } |
1140 | 1148 | ||
1141 | return printed; | 1149 | return printed; |
@@ -1372,8 +1380,7 @@ static void hist_browser__update_nr_entries(struct hist_browser *hb) | |||
1372 | return; | 1380 | return; |
1373 | } | 1381 | } |
1374 | 1382 | ||
1375 | while ((nd = hists__filter_entries(nd, hb->hists, | 1383 | while ((nd = hists__filter_entries(nd, hb->min_pcnt)) != NULL) { |
1376 | hb->min_pcnt)) != NULL) { | ||
1377 | nr_entries++; | 1384 | nr_entries++; |
1378 | nd = rb_next(nd); | 1385 | nd = rb_next(nd); |
1379 | } | 1386 | } |
@@ -1699,14 +1706,14 @@ zoom_dso: | |||
1699 | zoom_out_dso: | 1706 | zoom_out_dso: |
1700 | ui_helpline__pop(); | 1707 | ui_helpline__pop(); |
1701 | browser->hists->dso_filter = NULL; | 1708 | browser->hists->dso_filter = NULL; |
1702 | sort_dso.elide = false; | 1709 | perf_hpp__set_elide(HISTC_DSO, false); |
1703 | } else { | 1710 | } else { |
1704 | if (dso == NULL) | 1711 | if (dso == NULL) |
1705 | continue; | 1712 | continue; |
1706 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", | 1713 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", |
1707 | dso->kernel ? "the Kernel" : dso->short_name); | 1714 | dso->kernel ? "the Kernel" : dso->short_name); |
1708 | browser->hists->dso_filter = dso; | 1715 | browser->hists->dso_filter = dso; |
1709 | sort_dso.elide = true; | 1716 | perf_hpp__set_elide(HISTC_DSO, true); |
1710 | pstack__push(fstack, &browser->hists->dso_filter); | 1717 | pstack__push(fstack, &browser->hists->dso_filter); |
1711 | } | 1718 | } |
1712 | hists__filter_by_dso(hists); | 1719 | hists__filter_by_dso(hists); |
@@ -1718,13 +1725,13 @@ zoom_thread: | |||
1718 | zoom_out_thread: | 1725 | zoom_out_thread: |
1719 | ui_helpline__pop(); | 1726 | ui_helpline__pop(); |
1720 | browser->hists->thread_filter = NULL; | 1727 | browser->hists->thread_filter = NULL; |
1721 | sort_thread.elide = false; | 1728 | perf_hpp__set_elide(HISTC_THREAD, false); |
1722 | } else { | 1729 | } else { |
1723 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", | 1730 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", |
1724 | thread->comm_set ? thread__comm_str(thread) : "", | 1731 | thread->comm_set ? thread__comm_str(thread) : "", |
1725 | thread->tid); | 1732 | thread->tid); |
1726 | browser->hists->thread_filter = thread; | 1733 | browser->hists->thread_filter = thread; |
1727 | sort_thread.elide = true; | 1734 | perf_hpp__set_elide(HISTC_THREAD, false); |
1728 | pstack__push(fstack, &browser->hists->thread_filter); | 1735 | pstack__push(fstack, &browser->hists->thread_filter); |
1729 | } | 1736 | } |
1730 | hists__filter_by_thread(hists); | 1737 | hists__filter_by_thread(hists); |
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 9d90683914d4..6ca60e482cdc 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c | |||
@@ -47,11 +47,26 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, | |||
47 | __percent_color_snprintf, true); \ | 47 | __percent_color_snprintf, true); \ |
48 | } | 48 | } |
49 | 49 | ||
50 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ | ||
51 | static u64 he_get_acc_##_field(struct hist_entry *he) \ | ||
52 | { \ | ||
53 | return he->stat_acc->_field; \ | ||
54 | } \ | ||
55 | \ | ||
56 | static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ | ||
57 | struct perf_hpp *hpp, \ | ||
58 | struct hist_entry *he) \ | ||
59 | { \ | ||
60 | return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ | ||
61 | __percent_color_snprintf, true); \ | ||
62 | } | ||
63 | |||
50 | __HPP_COLOR_PERCENT_FN(overhead, period) | 64 | __HPP_COLOR_PERCENT_FN(overhead, period) |
51 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) | 65 | __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) |
52 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) | 66 | __HPP_COLOR_PERCENT_FN(overhead_us, period_us) |
53 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) | 67 | __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) |
54 | __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) | 68 | __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) |
69 | __HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period) | ||
55 | 70 | ||
56 | #undef __HPP_COLOR_PERCENT_FN | 71 | #undef __HPP_COLOR_PERCENT_FN |
57 | 72 | ||
@@ -68,6 +83,8 @@ void perf_gtk__init_hpp(void) | |||
68 | perf_gtk__hpp_color_overhead_guest_sys; | 83 | perf_gtk__hpp_color_overhead_guest_sys; |
69 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = | 84 | perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color = |
70 | perf_gtk__hpp_color_overhead_guest_us; | 85 | perf_gtk__hpp_color_overhead_guest_us; |
86 | perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color = | ||
87 | perf_gtk__hpp_color_overhead_acc; | ||
71 | } | 88 | } |
72 | 89 | ||
73 | static void callchain_list__sym_name(struct callchain_list *cl, | 90 | static void callchain_list__sym_name(struct callchain_list *cl, |
@@ -181,6 +198,13 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
181 | if (perf_hpp__should_skip(fmt)) | 198 | if (perf_hpp__should_skip(fmt)) |
182 | continue; | 199 | continue; |
183 | 200 | ||
201 | /* | ||
202 | * XXX no way to determine where symcol column is.. | ||
203 | * Just use last column for now. | ||
204 | */ | ||
205 | if (perf_hpp__is_sort_entry(fmt)) | ||
206 | sym_col = col_idx; | ||
207 | |||
184 | fmt->header(fmt, &hpp, hists_to_evsel(hists)); | 208 | fmt->header(fmt, &hpp, hists_to_evsel(hists)); |
185 | 209 | ||
186 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), | 210 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), |
@@ -209,14 +233,12 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
209 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 233 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
210 | GtkTreeIter iter; | 234 | GtkTreeIter iter; |
211 | u64 total = hists__total_period(h->hists); | 235 | u64 total = hists__total_period(h->hists); |
212 | float percent = 0.0; | 236 | float percent; |
213 | 237 | ||
214 | if (h->filtered) | 238 | if (h->filtered) |
215 | continue; | 239 | continue; |
216 | 240 | ||
217 | if (total) | 241 | percent = hist_entry__get_percent_limit(h); |
218 | percent = h->stat.period * 100.0 / total; | ||
219 | |||
220 | if (percent < min_pcnt) | 242 | if (percent < min_pcnt) |
221 | continue; | 243 | continue; |
222 | 244 | ||
@@ -238,7 +260,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
238 | 260 | ||
239 | if (symbol_conf.use_callchain && sort__has_sym) { | 261 | if (symbol_conf.use_callchain && sort__has_sym) { |
240 | if (callchain_param.mode == CHAIN_GRAPH_REL) | 262 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
241 | total = h->stat.period; | 263 | total = symbol_conf.cumulate_callchain ? |
264 | h->stat_acc->period : h->stat.period; | ||
242 | 265 | ||
243 | perf_gtk__add_callchain(&h->sorted_chain, store, &iter, | 266 | perf_gtk__add_callchain(&h->sorted_chain, store, &iter, |
244 | sym_col, total); | 267 | sym_col, total); |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 4484f5bd1b14..498adb23c02e 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -104,6 +104,18 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | |||
104 | return ret; | 104 | return ret; |
105 | } | 105 | } |
106 | 106 | ||
107 | int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, | ||
108 | hpp_field_fn get_field, const char *fmt, | ||
109 | hpp_snprint_fn print_fn, bool fmt_percent) | ||
110 | { | ||
111 | if (!symbol_conf.cumulate_callchain) { | ||
112 | return snprintf(hpp->buf, hpp->size, "%*s", | ||
113 | fmt_percent ? 8 : 12, "N/A"); | ||
114 | } | ||
115 | |||
116 | return __hpp__fmt(hpp, he, get_field, fmt, print_fn, fmt_percent); | ||
117 | } | ||
118 | |||
107 | static int field_cmp(u64 field_a, u64 field_b) | 119 | static int field_cmp(u64 field_a, u64 field_b) |
108 | { | 120 | { |
109 | if (field_a > field_b) | 121 | if (field_a > field_b) |
@@ -160,6 +172,24 @@ out: | |||
160 | return ret; | 172 | return ret; |
161 | } | 173 | } |
162 | 174 | ||
175 | static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b, | ||
176 | hpp_field_fn get_field) | ||
177 | { | ||
178 | s64 ret = 0; | ||
179 | |||
180 | if (symbol_conf.cumulate_callchain) { | ||
181 | /* | ||
182 | * Put caller above callee when they have equal period. | ||
183 | */ | ||
184 | ret = field_cmp(get_field(a), get_field(b)); | ||
185 | if (ret) | ||
186 | return ret; | ||
187 | |||
188 | ret = b->callchain->max_depth - a->callchain->max_depth; | ||
189 | } | ||
190 | return ret; | ||
191 | } | ||
192 | |||
163 | #define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ | 193 | #define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
164 | static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ | 194 | static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ |
165 | struct perf_hpp *hpp, \ | 195 | struct perf_hpp *hpp, \ |
@@ -242,6 +272,34 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ | |||
242 | return __hpp__sort(a, b, he_get_##_field); \ | 272 | return __hpp__sort(a, b, he_get_##_field); \ |
243 | } | 273 | } |
244 | 274 | ||
275 | #define __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ | ||
276 | static u64 he_get_acc_##_field(struct hist_entry *he) \ | ||
277 | { \ | ||
278 | return he->stat_acc->_field; \ | ||
279 | } \ | ||
280 | \ | ||
281 | static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ | ||
282 | struct perf_hpp *hpp, struct hist_entry *he) \ | ||
283 | { \ | ||
284 | return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ | ||
285 | hpp_color_scnprintf, true); \ | ||
286 | } | ||
287 | |||
288 | #define __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ | ||
289 | static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ | ||
290 | struct perf_hpp *hpp, struct hist_entry *he) \ | ||
291 | { \ | ||
292 | const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ | ||
293 | return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, fmt, \ | ||
294 | hpp_entry_scnprintf, true); \ | ||
295 | } | ||
296 | |||
297 | #define __HPP_SORT_ACC_FN(_type, _field) \ | ||
298 | static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ | ||
299 | { \ | ||
300 | return __hpp__sort_acc(a, b, he_get_acc_##_field); \ | ||
301 | } | ||
302 | |||
245 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ | 303 | #define __HPP_ENTRY_RAW_FN(_type, _field) \ |
246 | static u64 he_get_raw_##_field(struct hist_entry *he) \ | 304 | static u64 he_get_raw_##_field(struct hist_entry *he) \ |
247 | { \ | 305 | { \ |
@@ -270,18 +328,27 @@ __HPP_COLOR_PERCENT_FN(_type, _field) \ | |||
270 | __HPP_ENTRY_PERCENT_FN(_type, _field) \ | 328 | __HPP_ENTRY_PERCENT_FN(_type, _field) \ |
271 | __HPP_SORT_FN(_type, _field) | 329 | __HPP_SORT_FN(_type, _field) |
272 | 330 | ||
331 | #define HPP_PERCENT_ACC_FNS(_type, _str, _field, _min_width, _unit_width)\ | ||
332 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ | ||
333 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ | ||
334 | __HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ | ||
335 | __HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ | ||
336 | __HPP_SORT_ACC_FN(_type, _field) | ||
337 | |||
273 | #define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \ | 338 | #define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \ |
274 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ | 339 | __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ |
275 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ | 340 | __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ |
276 | __HPP_ENTRY_RAW_FN(_type, _field) \ | 341 | __HPP_ENTRY_RAW_FN(_type, _field) \ |
277 | __HPP_SORT_RAW_FN(_type, _field) | 342 | __HPP_SORT_RAW_FN(_type, _field) |
278 | 343 | ||
344 | __HPP_HEADER_FN(overhead_self, "Self", 8, 8) | ||
279 | 345 | ||
280 | HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) | 346 | HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) |
281 | HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) | 347 | HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) |
282 | HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) | 348 | HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) |
283 | HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) | 349 | HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) |
284 | HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8) | 350 | HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8) |
351 | HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period, 8, 8) | ||
285 | 352 | ||
286 | HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12) | 353 | HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12) |
287 | HPP_RAW_FNS(period, "Period", period, 12, 12) | 354 | HPP_RAW_FNS(period, "Period", period, 12, 12) |
@@ -303,6 +370,17 @@ static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, | |||
303 | .sort = hpp__sort_ ## _name, \ | 370 | .sort = hpp__sort_ ## _name, \ |
304 | } | 371 | } |
305 | 372 | ||
373 | #define HPP__COLOR_ACC_PRINT_FNS(_name) \ | ||
374 | { \ | ||
375 | .header = hpp__header_ ## _name, \ | ||
376 | .width = hpp__width_ ## _name, \ | ||
377 | .color = hpp__color_ ## _name, \ | ||
378 | .entry = hpp__entry_ ## _name, \ | ||
379 | .cmp = hpp__nop_cmp, \ | ||
380 | .collapse = hpp__nop_cmp, \ | ||
381 | .sort = hpp__sort_ ## _name, \ | ||
382 | } | ||
383 | |||
306 | #define HPP__PRINT_FNS(_name) \ | 384 | #define HPP__PRINT_FNS(_name) \ |
307 | { \ | 385 | { \ |
308 | .header = hpp__header_ ## _name, \ | 386 | .header = hpp__header_ ## _name, \ |
@@ -319,6 +397,7 @@ struct perf_hpp_fmt perf_hpp__format[] = { | |||
319 | HPP__COLOR_PRINT_FNS(overhead_us), | 397 | HPP__COLOR_PRINT_FNS(overhead_us), |
320 | HPP__COLOR_PRINT_FNS(overhead_guest_sys), | 398 | HPP__COLOR_PRINT_FNS(overhead_guest_sys), |
321 | HPP__COLOR_PRINT_FNS(overhead_guest_us), | 399 | HPP__COLOR_PRINT_FNS(overhead_guest_us), |
400 | HPP__COLOR_ACC_PRINT_FNS(overhead_acc), | ||
322 | HPP__PRINT_FNS(samples), | 401 | HPP__PRINT_FNS(samples), |
323 | HPP__PRINT_FNS(period) | 402 | HPP__PRINT_FNS(period) |
324 | }; | 403 | }; |
@@ -328,16 +407,23 @@ LIST_HEAD(perf_hpp__sort_list); | |||
328 | 407 | ||
329 | 408 | ||
330 | #undef HPP__COLOR_PRINT_FNS | 409 | #undef HPP__COLOR_PRINT_FNS |
410 | #undef HPP__COLOR_ACC_PRINT_FNS | ||
331 | #undef HPP__PRINT_FNS | 411 | #undef HPP__PRINT_FNS |
332 | 412 | ||
333 | #undef HPP_PERCENT_FNS | 413 | #undef HPP_PERCENT_FNS |
414 | #undef HPP_PERCENT_ACC_FNS | ||
334 | #undef HPP_RAW_FNS | 415 | #undef HPP_RAW_FNS |
335 | 416 | ||
336 | #undef __HPP_HEADER_FN | 417 | #undef __HPP_HEADER_FN |
337 | #undef __HPP_WIDTH_FN | 418 | #undef __HPP_WIDTH_FN |
338 | #undef __HPP_COLOR_PERCENT_FN | 419 | #undef __HPP_COLOR_PERCENT_FN |
339 | #undef __HPP_ENTRY_PERCENT_FN | 420 | #undef __HPP_ENTRY_PERCENT_FN |
421 | #undef __HPP_COLOR_ACC_PERCENT_FN | ||
422 | #undef __HPP_ENTRY_ACC_PERCENT_FN | ||
340 | #undef __HPP_ENTRY_RAW_FN | 423 | #undef __HPP_ENTRY_RAW_FN |
424 | #undef __HPP_SORT_FN | ||
425 | #undef __HPP_SORT_ACC_FN | ||
426 | #undef __HPP_SORT_RAW_FN | ||
341 | 427 | ||
342 | 428 | ||
343 | void perf_hpp__init(void) | 429 | void perf_hpp__init(void) |
@@ -361,6 +447,13 @@ void perf_hpp__init(void) | |||
361 | if (field_order) | 447 | if (field_order) |
362 | return; | 448 | return; |
363 | 449 | ||
450 | if (symbol_conf.cumulate_callchain) { | ||
451 | perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC); | ||
452 | |||
453 | perf_hpp__format[PERF_HPP__OVERHEAD].header = | ||
454 | hpp__header_overhead_self; | ||
455 | } | ||
456 | |||
364 | perf_hpp__column_enable(PERF_HPP__OVERHEAD); | 457 | perf_hpp__column_enable(PERF_HPP__OVERHEAD); |
365 | 458 | ||
366 | if (symbol_conf.show_cpu_utilization) { | 459 | if (symbol_conf.show_cpu_utilization) { |
@@ -383,6 +476,12 @@ void perf_hpp__init(void) | |||
383 | list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list; | 476 | list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list; |
384 | if (list_empty(list)) | 477 | if (list_empty(list)) |
385 | list_add(list, &perf_hpp__sort_list); | 478 | list_add(list, &perf_hpp__sort_list); |
479 | |||
480 | if (symbol_conf.cumulate_callchain) { | ||
481 | list = &perf_hpp__format[PERF_HPP__OVERHEAD_ACC].sort_list; | ||
482 | if (list_empty(list)) | ||
483 | list_add(list, &perf_hpp__sort_list); | ||
484 | } | ||
386 | } | 485 | } |
387 | 486 | ||
388 | void perf_hpp__column_register(struct perf_hpp_fmt *format) | 487 | void perf_hpp__column_register(struct perf_hpp_fmt *format) |
@@ -390,6 +489,11 @@ void perf_hpp__column_register(struct perf_hpp_fmt *format) | |||
390 | list_add_tail(&format->list, &perf_hpp__list); | 489 | list_add_tail(&format->list, &perf_hpp__list); |
391 | } | 490 | } |
392 | 491 | ||
492 | void perf_hpp__column_unregister(struct perf_hpp_fmt *format) | ||
493 | { | ||
494 | list_del(&format->list); | ||
495 | } | ||
496 | |||
393 | void perf_hpp__register_sort_field(struct perf_hpp_fmt *format) | 497 | void perf_hpp__register_sort_field(struct perf_hpp_fmt *format) |
394 | { | 498 | { |
395 | list_add_tail(&format->sort_list, &perf_hpp__sort_list); | 499 | list_add_tail(&format->sort_list, &perf_hpp__sort_list); |
@@ -401,6 +505,21 @@ void perf_hpp__column_enable(unsigned col) | |||
401 | perf_hpp__column_register(&perf_hpp__format[col]); | 505 | perf_hpp__column_register(&perf_hpp__format[col]); |
402 | } | 506 | } |
403 | 507 | ||
508 | void perf_hpp__column_disable(unsigned col) | ||
509 | { | ||
510 | BUG_ON(col >= PERF_HPP__MAX_INDEX); | ||
511 | perf_hpp__column_unregister(&perf_hpp__format[col]); | ||
512 | } | ||
513 | |||
514 | void perf_hpp__cancel_cumulate(void) | ||
515 | { | ||
516 | if (field_order) | ||
517 | return; | ||
518 | |||
519 | perf_hpp__column_disable(PERF_HPP__OVERHEAD_ACC); | ||
520 | perf_hpp__format[PERF_HPP__OVERHEAD].header = hpp__header_overhead; | ||
521 | } | ||
522 | |||
404 | void perf_hpp__setup_output_field(void) | 523 | void perf_hpp__setup_output_field(void) |
405 | { | 524 | { |
406 | struct perf_hpp_fmt *fmt; | 525 | struct perf_hpp_fmt *fmt; |
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index 9f57991025a9..90122abd3721 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
@@ -271,7 +271,9 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, | |||
271 | { | 271 | { |
272 | switch (callchain_param.mode) { | 272 | switch (callchain_param.mode) { |
273 | case CHAIN_GRAPH_REL: | 273 | case CHAIN_GRAPH_REL: |
274 | return callchain__fprintf_graph(fp, &he->sorted_chain, he->stat.period, | 274 | return callchain__fprintf_graph(fp, &he->sorted_chain, |
275 | symbol_conf.cumulate_callchain ? | ||
276 | he->stat_acc->period : he->stat.period, | ||
275 | left_margin); | 277 | left_margin); |
276 | break; | 278 | break; |
277 | case CHAIN_GRAPH_ABS: | 279 | case CHAIN_GRAPH_ABS: |
@@ -461,12 +463,12 @@ print_entries: | |||
461 | 463 | ||
462 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | 464 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
463 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 465 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
464 | float percent = h->stat.period * 100.0 / | 466 | float percent; |
465 | hists->stats.total_period; | ||
466 | 467 | ||
467 | if (h->filtered) | 468 | if (h->filtered) |
468 | continue; | 469 | continue; |
469 | 470 | ||
471 | percent = hist_entry__get_percent_limit(h); | ||
470 | if (percent < min_pcnt) | 472 | if (percent < min_pcnt) |
471 | continue; | 473 | continue; |
472 | 474 | ||
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 9a42382b3921..48b6d3f50012 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -616,7 +616,8 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent | |||
616 | if (sample->callchain == NULL) | 616 | if (sample->callchain == NULL) |
617 | return 0; | 617 | return 0; |
618 | 618 | ||
619 | if (symbol_conf.use_callchain || sort__has_parent) { | 619 | if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || |
620 | sort__has_parent) { | ||
620 | return machine__resolve_callchain(al->machine, evsel, al->thread, | 621 | return machine__resolve_callchain(al->machine, evsel, al->thread, |
621 | sample, parent, al, max_stack); | 622 | sample, parent, al, max_stack); |
622 | } | 623 | } |
@@ -629,3 +630,45 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *samp | |||
629 | return 0; | 630 | return 0; |
630 | return callchain_append(he->callchain, &callchain_cursor, sample->period); | 631 | return callchain_append(he->callchain, &callchain_cursor, sample->period); |
631 | } | 632 | } |
633 | |||
634 | int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, | ||
635 | bool hide_unresolved) | ||
636 | { | ||
637 | al->map = node->map; | ||
638 | al->sym = node->sym; | ||
639 | if (node->map) | ||
640 | al->addr = node->map->map_ip(node->map, node->ip); | ||
641 | else | ||
642 | al->addr = node->ip; | ||
643 | |||
644 | if (al->sym == NULL) { | ||
645 | if (hide_unresolved) | ||
646 | return 0; | ||
647 | if (al->map == NULL) | ||
648 | goto out; | ||
649 | } | ||
650 | |||
651 | if (al->map->groups == &al->machine->kmaps) { | ||
652 | if (machine__is_host(al->machine)) { | ||
653 | al->cpumode = PERF_RECORD_MISC_KERNEL; | ||
654 | al->level = 'k'; | ||
655 | } else { | ||
656 | al->cpumode = PERF_RECORD_MISC_GUEST_KERNEL; | ||
657 | al->level = 'g'; | ||
658 | } | ||
659 | } else { | ||
660 | if (machine__is_host(al->machine)) { | ||
661 | al->cpumode = PERF_RECORD_MISC_USER; | ||
662 | al->level = '.'; | ||
663 | } else if (perf_guest) { | ||
664 | al->cpumode = PERF_RECORD_MISC_GUEST_USER; | ||
665 | al->level = 'u'; | ||
666 | } else { | ||
667 | al->cpumode = PERF_RECORD_MISC_HYPERVISOR; | ||
668 | al->level = 'H'; | ||
669 | } | ||
670 | } | ||
671 | |||
672 | out: | ||
673 | return 1; | ||
674 | } | ||
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index bde2b0cc24cf..8f84423a75da 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -162,7 +162,18 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent | |||
162 | struct perf_evsel *evsel, struct addr_location *al, | 162 | struct perf_evsel *evsel, struct addr_location *al, |
163 | int max_stack); | 163 | int max_stack); |
164 | int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); | 164 | int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); |
165 | int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, | ||
166 | bool hide_unresolved); | ||
165 | 167 | ||
166 | extern const char record_callchain_help[]; | 168 | extern const char record_callchain_help[]; |
167 | int parse_callchain_report_opt(const char *arg); | 169 | int parse_callchain_report_opt(const char *arg); |
170 | |||
171 | static inline void callchain_cursor_snapshot(struct callchain_cursor *dest, | ||
172 | struct callchain_cursor *src) | ||
173 | { | ||
174 | *dest = *src; | ||
175 | |||
176 | dest->first = src->curr; | ||
177 | dest->nr -= src->pos; | ||
178 | } | ||
168 | #endif /* __PERF_CALLCHAIN_H */ | 179 | #endif /* __PERF_CALLCHAIN_H */ |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index b262b44b7a65..5a0a4b2cadc4 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include "session.h" | 4 | #include "session.h" |
5 | #include "sort.h" | 5 | #include "sort.h" |
6 | #include "evsel.h" | 6 | #include "evsel.h" |
7 | #include "annotate.h" | ||
7 | #include <math.h> | 8 | #include <math.h> |
8 | 9 | ||
9 | static bool hists__filter_entry_by_dso(struct hists *hists, | 10 | static bool hists__filter_entry_by_dso(struct hists *hists, |
@@ -231,6 +232,8 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) | |||
231 | return true; | 232 | return true; |
232 | 233 | ||
233 | he_stat__decay(&he->stat); | 234 | he_stat__decay(&he->stat); |
235 | if (symbol_conf.cumulate_callchain) | ||
236 | he_stat__decay(he->stat_acc); | ||
234 | 237 | ||
235 | diff = prev_period - he->stat.period; | 238 | diff = prev_period - he->stat.period; |
236 | 239 | ||
@@ -276,14 +279,31 @@ void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) | |||
276 | * histogram, sorted on item, collects periods | 279 | * histogram, sorted on item, collects periods |
277 | */ | 280 | */ |
278 | 281 | ||
279 | static struct hist_entry *hist_entry__new(struct hist_entry *template) | 282 | static struct hist_entry *hist_entry__new(struct hist_entry *template, |
283 | bool sample_self) | ||
280 | { | 284 | { |
281 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; | 285 | size_t callchain_size = 0; |
282 | struct hist_entry *he = zalloc(sizeof(*he) + callchain_size); | 286 | struct hist_entry *he; |
287 | |||
288 | if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) | ||
289 | callchain_size = sizeof(struct callchain_root); | ||
290 | |||
291 | he = zalloc(sizeof(*he) + callchain_size); | ||
283 | 292 | ||
284 | if (he != NULL) { | 293 | if (he != NULL) { |
285 | *he = *template; | 294 | *he = *template; |
286 | 295 | ||
296 | if (symbol_conf.cumulate_callchain) { | ||
297 | he->stat_acc = malloc(sizeof(he->stat)); | ||
298 | if (he->stat_acc == NULL) { | ||
299 | free(he); | ||
300 | return NULL; | ||
301 | } | ||
302 | memcpy(he->stat_acc, &he->stat, sizeof(he->stat)); | ||
303 | if (!sample_self) | ||
304 | memset(&he->stat, 0, sizeof(he->stat)); | ||
305 | } | ||
306 | |||
287 | if (he->ms.map) | 307 | if (he->ms.map) |
288 | he->ms.map->referenced = true; | 308 | he->ms.map->referenced = true; |
289 | 309 | ||
@@ -295,6 +315,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template) | |||
295 | */ | 315 | */ |
296 | he->branch_info = malloc(sizeof(*he->branch_info)); | 316 | he->branch_info = malloc(sizeof(*he->branch_info)); |
297 | if (he->branch_info == NULL) { | 317 | if (he->branch_info == NULL) { |
318 | free(he->stat_acc); | ||
298 | free(he); | 319 | free(he); |
299 | return NULL; | 320 | return NULL; |
300 | } | 321 | } |
@@ -333,7 +354,8 @@ static u8 symbol__parent_filter(const struct symbol *parent) | |||
333 | 354 | ||
334 | static struct hist_entry *add_hist_entry(struct hists *hists, | 355 | static struct hist_entry *add_hist_entry(struct hists *hists, |
335 | struct hist_entry *entry, | 356 | struct hist_entry *entry, |
336 | struct addr_location *al) | 357 | struct addr_location *al, |
358 | bool sample_self) | ||
337 | { | 359 | { |
338 | struct rb_node **p; | 360 | struct rb_node **p; |
339 | struct rb_node *parent = NULL; | 361 | struct rb_node *parent = NULL; |
@@ -357,7 +379,10 @@ static struct hist_entry *add_hist_entry(struct hists *hists, | |||
357 | cmp = hist_entry__cmp(he, entry); | 379 | cmp = hist_entry__cmp(he, entry); |
358 | 380 | ||
359 | if (!cmp) { | 381 | if (!cmp) { |
360 | he_stat__add_period(&he->stat, period, weight); | 382 | if (sample_self) |
383 | he_stat__add_period(&he->stat, period, weight); | ||
384 | if (symbol_conf.cumulate_callchain) | ||
385 | he_stat__add_period(he->stat_acc, period, weight); | ||
361 | 386 | ||
362 | /* | 387 | /* |
363 | * This mem info was allocated from sample__resolve_mem | 388 | * This mem info was allocated from sample__resolve_mem |
@@ -385,14 +410,17 @@ static struct hist_entry *add_hist_entry(struct hists *hists, | |||
385 | p = &(*p)->rb_right; | 410 | p = &(*p)->rb_right; |
386 | } | 411 | } |
387 | 412 | ||
388 | he = hist_entry__new(entry); | 413 | he = hist_entry__new(entry, sample_self); |
389 | if (!he) | 414 | if (!he) |
390 | return NULL; | 415 | return NULL; |
391 | 416 | ||
392 | rb_link_node(&he->rb_node_in, parent, p); | 417 | rb_link_node(&he->rb_node_in, parent, p); |
393 | rb_insert_color(&he->rb_node_in, hists->entries_in); | 418 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
394 | out: | 419 | out: |
395 | he_stat__add_cpumode_period(&he->stat, al->cpumode, period); | 420 | if (sample_self) |
421 | he_stat__add_cpumode_period(&he->stat, al->cpumode, period); | ||
422 | if (symbol_conf.cumulate_callchain) | ||
423 | he_stat__add_cpumode_period(he->stat_acc, al->cpumode, period); | ||
396 | return he; | 424 | return he; |
397 | } | 425 | } |
398 | 426 | ||
@@ -401,7 +429,8 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
401 | struct symbol *sym_parent, | 429 | struct symbol *sym_parent, |
402 | struct branch_info *bi, | 430 | struct branch_info *bi, |
403 | struct mem_info *mi, | 431 | struct mem_info *mi, |
404 | u64 period, u64 weight, u64 transaction) | 432 | u64 period, u64 weight, u64 transaction, |
433 | bool sample_self) | ||
405 | { | 434 | { |
406 | struct hist_entry entry = { | 435 | struct hist_entry entry = { |
407 | .thread = al->thread, | 436 | .thread = al->thread, |
@@ -426,7 +455,429 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
426 | .transaction = transaction, | 455 | .transaction = transaction, |
427 | }; | 456 | }; |
428 | 457 | ||
429 | return add_hist_entry(hists, &entry, al); | 458 | return add_hist_entry(hists, &entry, al, sample_self); |
459 | } | ||
460 | |||
461 | static int | ||
462 | iter_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, | ||
463 | struct addr_location *al __maybe_unused) | ||
464 | { | ||
465 | return 0; | ||
466 | } | ||
467 | |||
468 | static int | ||
469 | iter_add_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, | ||
470 | struct addr_location *al __maybe_unused) | ||
471 | { | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | static int | ||
476 | iter_prepare_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) | ||
477 | { | ||
478 | struct perf_sample *sample = iter->sample; | ||
479 | struct mem_info *mi; | ||
480 | |||
481 | mi = sample__resolve_mem(sample, al); | ||
482 | if (mi == NULL) | ||
483 | return -ENOMEM; | ||
484 | |||
485 | iter->priv = mi; | ||
486 | return 0; | ||
487 | } | ||
488 | |||
489 | static int | ||
490 | iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) | ||
491 | { | ||
492 | u64 cost; | ||
493 | struct mem_info *mi = iter->priv; | ||
494 | struct hist_entry *he; | ||
495 | |||
496 | if (mi == NULL) | ||
497 | return -EINVAL; | ||
498 | |||
499 | cost = iter->sample->weight; | ||
500 | if (!cost) | ||
501 | cost = 1; | ||
502 | |||
503 | /* | ||
504 | * must pass period=weight in order to get the correct | ||
505 | * sorting from hists__collapse_resort() which is solely | ||
506 | * based on periods. We want sorting be done on nr_events * weight | ||
507 | * and this is indirectly achieved by passing period=weight here | ||
508 | * and the he_stat__add_period() function. | ||
509 | */ | ||
510 | he = __hists__add_entry(&iter->evsel->hists, al, iter->parent, NULL, mi, | ||
511 | cost, cost, 0, true); | ||
512 | if (!he) | ||
513 | return -ENOMEM; | ||
514 | |||
515 | iter->he = he; | ||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | static int | ||
520 | iter_finish_mem_entry(struct hist_entry_iter *iter, | ||
521 | struct addr_location *al __maybe_unused) | ||
522 | { | ||
523 | struct perf_evsel *evsel = iter->evsel; | ||
524 | struct hist_entry *he = iter->he; | ||
525 | int err = -EINVAL; | ||
526 | |||
527 | if (he == NULL) | ||
528 | goto out; | ||
529 | |||
530 | hists__inc_nr_samples(&evsel->hists, he->filtered); | ||
531 | |||
532 | err = hist_entry__append_callchain(he, iter->sample); | ||
533 | |||
534 | out: | ||
535 | /* | ||
536 | * We don't need to free iter->priv (mem_info) here since | ||
537 | * the mem info was either already freed in add_hist_entry() or | ||
538 | * passed to a new hist entry by hist_entry__new(). | ||
539 | */ | ||
540 | iter->priv = NULL; | ||
541 | |||
542 | iter->he = NULL; | ||
543 | return err; | ||
544 | } | ||
545 | |||
546 | static int | ||
547 | iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) | ||
548 | { | ||
549 | struct branch_info *bi; | ||
550 | struct perf_sample *sample = iter->sample; | ||
551 | |||
552 | bi = sample__resolve_bstack(sample, al); | ||
553 | if (!bi) | ||
554 | return -ENOMEM; | ||
555 | |||
556 | iter->curr = 0; | ||
557 | iter->total = sample->branch_stack->nr; | ||
558 | |||
559 | iter->priv = bi; | ||
560 | return 0; | ||
561 | } | ||
562 | |||
563 | static int | ||
564 | iter_add_single_branch_entry(struct hist_entry_iter *iter __maybe_unused, | ||
565 | struct addr_location *al __maybe_unused) | ||
566 | { | ||
567 | /* to avoid calling callback function */ | ||
568 | iter->he = NULL; | ||
569 | |||
570 | return 0; | ||
571 | } | ||
572 | |||
573 | static int | ||
574 | iter_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) | ||
575 | { | ||
576 | struct branch_info *bi = iter->priv; | ||
577 | int i = iter->curr; | ||
578 | |||
579 | if (bi == NULL) | ||
580 | return 0; | ||
581 | |||
582 | if (iter->curr >= iter->total) | ||
583 | return 0; | ||
584 | |||
585 | al->map = bi[i].to.map; | ||
586 | al->sym = bi[i].to.sym; | ||
587 | al->addr = bi[i].to.addr; | ||
588 | return 1; | ||
589 | } | ||
590 | |||
591 | static int | ||
592 | iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) | ||
593 | { | ||
594 | struct branch_info *bi; | ||
595 | struct perf_evsel *evsel = iter->evsel; | ||
596 | struct hist_entry *he = NULL; | ||
597 | int i = iter->curr; | ||
598 | int err = 0; | ||
599 | |||
600 | bi = iter->priv; | ||
601 | |||
602 | if (iter->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) | ||
603 | goto out; | ||
604 | |||
605 | /* | ||
606 | * The report shows the percentage of total branches captured | ||
607 | * and not events sampled. Thus we use a pseudo period of 1. | ||
608 | */ | ||
609 | he = __hists__add_entry(&evsel->hists, al, iter->parent, &bi[i], NULL, | ||
610 | 1, 1, 0, true); | ||
611 | if (he == NULL) | ||
612 | return -ENOMEM; | ||
613 | |||
614 | hists__inc_nr_samples(&evsel->hists, he->filtered); | ||
615 | |||
616 | out: | ||
617 | iter->he = he; | ||
618 | iter->curr++; | ||
619 | return err; | ||
620 | } | ||
621 | |||
622 | static int | ||
623 | iter_finish_branch_entry(struct hist_entry_iter *iter, | ||
624 | struct addr_location *al __maybe_unused) | ||
625 | { | ||
626 | zfree(&iter->priv); | ||
627 | iter->he = NULL; | ||
628 | |||
629 | return iter->curr >= iter->total ? 0 : -1; | ||
630 | } | ||
631 | |||
632 | static int | ||
633 | iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, | ||
634 | struct addr_location *al __maybe_unused) | ||
635 | { | ||
636 | return 0; | ||
637 | } | ||
638 | |||
639 | static int | ||
640 | iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) | ||
641 | { | ||
642 | struct perf_evsel *evsel = iter->evsel; | ||
643 | struct perf_sample *sample = iter->sample; | ||
644 | struct hist_entry *he; | ||
645 | |||
646 | he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL, | ||
647 | sample->period, sample->weight, | ||
648 | sample->transaction, true); | ||
649 | if (he == NULL) | ||
650 | return -ENOMEM; | ||
651 | |||
652 | iter->he = he; | ||
653 | return 0; | ||
654 | } | ||
655 | |||
656 | static int | ||
657 | iter_finish_normal_entry(struct hist_entry_iter *iter, | ||
658 | struct addr_location *al __maybe_unused) | ||
659 | { | ||
660 | struct hist_entry *he = iter->he; | ||
661 | struct perf_evsel *evsel = iter->evsel; | ||
662 | struct perf_sample *sample = iter->sample; | ||
663 | |||
664 | if (he == NULL) | ||
665 | return 0; | ||
666 | |||
667 | iter->he = NULL; | ||
668 | |||
669 | hists__inc_nr_samples(&evsel->hists, he->filtered); | ||
670 | |||
671 | return hist_entry__append_callchain(he, sample); | ||
672 | } | ||
673 | |||
674 | static int | ||
675 | iter_prepare_cumulative_entry(struct hist_entry_iter *iter __maybe_unused, | ||
676 | struct addr_location *al __maybe_unused) | ||
677 | { | ||
678 | struct hist_entry **he_cache; | ||
679 | |||
680 | callchain_cursor_commit(&callchain_cursor); | ||
681 | |||
682 | /* | ||
683 | * This is for detecting cycles or recursions so that they're | ||
684 | * cumulated only one time to prevent entries more than 100% | ||
685 | * overhead. | ||
686 | */ | ||
687 | he_cache = malloc(sizeof(*he_cache) * (PERF_MAX_STACK_DEPTH + 1)); | ||
688 | if (he_cache == NULL) | ||
689 | return -ENOMEM; | ||
690 | |||
691 | iter->priv = he_cache; | ||
692 | iter->curr = 0; | ||
693 | |||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | static int | ||
698 | iter_add_single_cumulative_entry(struct hist_entry_iter *iter, | ||
699 | struct addr_location *al) | ||
700 | { | ||
701 | struct perf_evsel *evsel = iter->evsel; | ||
702 | struct perf_sample *sample = iter->sample; | ||
703 | struct hist_entry **he_cache = iter->priv; | ||
704 | struct hist_entry *he; | ||
705 | int err = 0; | ||
706 | |||
707 | he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL, | ||
708 | sample->period, sample->weight, | ||
709 | sample->transaction, true); | ||
710 | if (he == NULL) | ||
711 | return -ENOMEM; | ||
712 | |||
713 | iter->he = he; | ||
714 | he_cache[iter->curr++] = he; | ||
715 | |||
716 | callchain_append(he->callchain, &callchain_cursor, sample->period); | ||
717 | |||
718 | /* | ||
719 | * We need to re-initialize the cursor since callchain_append() | ||
720 | * advanced the cursor to the end. | ||
721 | */ | ||
722 | callchain_cursor_commit(&callchain_cursor); | ||
723 | |||
724 | hists__inc_nr_samples(&evsel->hists, he->filtered); | ||
725 | |||
726 | return err; | ||
727 | } | ||
728 | |||
729 | static int | ||
730 | iter_next_cumulative_entry(struct hist_entry_iter *iter, | ||
731 | struct addr_location *al) | ||
732 | { | ||
733 | struct callchain_cursor_node *node; | ||
734 | |||
735 | node = callchain_cursor_current(&callchain_cursor); | ||
736 | if (node == NULL) | ||
737 | return 0; | ||
738 | |||
739 | return fill_callchain_info(al, node, iter->hide_unresolved); | ||
740 | } | ||
741 | |||
742 | static int | ||
743 | iter_add_next_cumulative_entry(struct hist_entry_iter *iter, | ||
744 | struct addr_location *al) | ||
745 | { | ||
746 | struct perf_evsel *evsel = iter->evsel; | ||
747 | struct perf_sample *sample = iter->sample; | ||
748 | struct hist_entry **he_cache = iter->priv; | ||
749 | struct hist_entry *he; | ||
750 | struct hist_entry he_tmp = { | ||
751 | .cpu = al->cpu, | ||
752 | .thread = al->thread, | ||
753 | .comm = thread__comm(al->thread), | ||
754 | .ip = al->addr, | ||
755 | .ms = { | ||
756 | .map = al->map, | ||
757 | .sym = al->sym, | ||
758 | }, | ||
759 | .parent = iter->parent, | ||
760 | }; | ||
761 | int i; | ||
762 | struct callchain_cursor cursor; | ||
763 | |||
764 | callchain_cursor_snapshot(&cursor, &callchain_cursor); | ||
765 | |||
766 | callchain_cursor_advance(&callchain_cursor); | ||
767 | |||
768 | /* | ||
769 | * Check if there's duplicate entries in the callchain. | ||
770 | * It's possible that it has cycles or recursive calls. | ||
771 | */ | ||
772 | for (i = 0; i < iter->curr; i++) { | ||
773 | if (hist_entry__cmp(he_cache[i], &he_tmp) == 0) { | ||
774 | /* to avoid calling callback function */ | ||
775 | iter->he = NULL; | ||
776 | return 0; | ||
777 | } | ||
778 | } | ||
779 | |||
780 | he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL, | ||
781 | sample->period, sample->weight, | ||
782 | sample->transaction, false); | ||
783 | if (he == NULL) | ||
784 | return -ENOMEM; | ||
785 | |||
786 | iter->he = he; | ||
787 | he_cache[iter->curr++] = he; | ||
788 | |||
789 | callchain_append(he->callchain, &cursor, sample->period); | ||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int | ||
794 | iter_finish_cumulative_entry(struct hist_entry_iter *iter, | ||
795 | struct addr_location *al __maybe_unused) | ||
796 | { | ||
797 | zfree(&iter->priv); | ||
798 | iter->he = NULL; | ||
799 | |||
800 | return 0; | ||
801 | } | ||
802 | |||
803 | const struct hist_iter_ops hist_iter_mem = { | ||
804 | .prepare_entry = iter_prepare_mem_entry, | ||
805 | .add_single_entry = iter_add_single_mem_entry, | ||
806 | .next_entry = iter_next_nop_entry, | ||
807 | .add_next_entry = iter_add_next_nop_entry, | ||
808 | .finish_entry = iter_finish_mem_entry, | ||
809 | }; | ||
810 | |||
811 | const struct hist_iter_ops hist_iter_branch = { | ||
812 | .prepare_entry = iter_prepare_branch_entry, | ||
813 | .add_single_entry = iter_add_single_branch_entry, | ||
814 | .next_entry = iter_next_branch_entry, | ||
815 | .add_next_entry = iter_add_next_branch_entry, | ||
816 | .finish_entry = iter_finish_branch_entry, | ||
817 | }; | ||
818 | |||
819 | const struct hist_iter_ops hist_iter_normal = { | ||
820 | .prepare_entry = iter_prepare_normal_entry, | ||
821 | .add_single_entry = iter_add_single_normal_entry, | ||
822 | .next_entry = iter_next_nop_entry, | ||
823 | .add_next_entry = iter_add_next_nop_entry, | ||
824 | .finish_entry = iter_finish_normal_entry, | ||
825 | }; | ||
826 | |||
827 | const struct hist_iter_ops hist_iter_cumulative = { | ||
828 | .prepare_entry = iter_prepare_cumulative_entry, | ||
829 | .add_single_entry = iter_add_single_cumulative_entry, | ||
830 | .next_entry = iter_next_cumulative_entry, | ||
831 | .add_next_entry = iter_add_next_cumulative_entry, | ||
832 | .finish_entry = iter_finish_cumulative_entry, | ||
833 | }; | ||
834 | |||
835 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, | ||
836 | struct perf_evsel *evsel, struct perf_sample *sample, | ||
837 | int max_stack_depth, void *arg) | ||
838 | { | ||
839 | int err, err2; | ||
840 | |||
841 | err = sample__resolve_callchain(sample, &iter->parent, evsel, al, | ||
842 | max_stack_depth); | ||
843 | if (err) | ||
844 | return err; | ||
845 | |||
846 | iter->evsel = evsel; | ||
847 | iter->sample = sample; | ||
848 | |||
849 | err = iter->ops->prepare_entry(iter, al); | ||
850 | if (err) | ||
851 | goto out; | ||
852 | |||
853 | err = iter->ops->add_single_entry(iter, al); | ||
854 | if (err) | ||
855 | goto out; | ||
856 | |||
857 | if (iter->he && iter->add_entry_cb) { | ||
858 | err = iter->add_entry_cb(iter, al, true, arg); | ||
859 | if (err) | ||
860 | goto out; | ||
861 | } | ||
862 | |||
863 | while (iter->ops->next_entry(iter, al)) { | ||
864 | err = iter->ops->add_next_entry(iter, al); | ||
865 | if (err) | ||
866 | break; | ||
867 | |||
868 | if (iter->he && iter->add_entry_cb) { | ||
869 | err = iter->add_entry_cb(iter, al, false, arg); | ||
870 | if (err) | ||
871 | goto out; | ||
872 | } | ||
873 | } | ||
874 | |||
875 | out: | ||
876 | err2 = iter->ops->finish_entry(iter, al); | ||
877 | if (!err) | ||
878 | err = err2; | ||
879 | |||
880 | return err; | ||
430 | } | 881 | } |
431 | 882 | ||
432 | int64_t | 883 | int64_t |
@@ -469,6 +920,7 @@ void hist_entry__free(struct hist_entry *he) | |||
469 | { | 920 | { |
470 | zfree(&he->branch_info); | 921 | zfree(&he->branch_info); |
471 | zfree(&he->mem_info); | 922 | zfree(&he->mem_info); |
923 | zfree(&he->stat_acc); | ||
472 | free_srcline(he->srcline); | 924 | free_srcline(he->srcline); |
473 | free(he); | 925 | free(he); |
474 | } | 926 | } |
@@ -494,6 +946,8 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, | |||
494 | 946 | ||
495 | if (!cmp) { | 947 | if (!cmp) { |
496 | he_stat__add_stat(&iter->stat, &he->stat); | 948 | he_stat__add_stat(&iter->stat, &he->stat); |
949 | if (symbol_conf.cumulate_callchain) | ||
950 | he_stat__add_stat(iter->stat_acc, he->stat_acc); | ||
497 | 951 | ||
498 | if (symbol_conf.use_callchain) { | 952 | if (symbol_conf.use_callchain) { |
499 | callchain_cursor_reset(&callchain_cursor); | 953 | callchain_cursor_reset(&callchain_cursor); |
@@ -800,6 +1254,13 @@ void hists__inc_nr_events(struct hists *hists, u32 type) | |||
800 | events_stats__inc(&hists->stats, type); | 1254 | events_stats__inc(&hists->stats, type); |
801 | } | 1255 | } |
802 | 1256 | ||
1257 | void hists__inc_nr_samples(struct hists *hists, bool filtered) | ||
1258 | { | ||
1259 | events_stats__inc(&hists->stats, PERF_RECORD_SAMPLE); | ||
1260 | if (!filtered) | ||
1261 | hists->stats.nr_non_filtered_samples++; | ||
1262 | } | ||
1263 | |||
803 | static struct hist_entry *hists__add_dummy_entry(struct hists *hists, | 1264 | static struct hist_entry *hists__add_dummy_entry(struct hists *hists, |
804 | struct hist_entry *pair) | 1265 | struct hist_entry *pair) |
805 | { | 1266 | { |
@@ -831,7 +1292,7 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists, | |||
831 | p = &(*p)->rb_right; | 1292 | p = &(*p)->rb_right; |
832 | } | 1293 | } |
833 | 1294 | ||
834 | he = hist_entry__new(pair); | 1295 | he = hist_entry__new(pair, true); |
835 | if (he) { | 1296 | if (he) { |
836 | memset(&he->stat, 0, sizeof(he->stat)); | 1297 | memset(&he->stat, 0, sizeof(he->stat)); |
837 | he->hists = hists; | 1298 | he->hists = hists; |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a8418d19808d..d2bf03575d5f 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -96,12 +96,50 @@ struct hists { | |||
96 | u16 col_len[HISTC_NR_COLS]; | 96 | u16 col_len[HISTC_NR_COLS]; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | struct hist_entry_iter; | ||
100 | |||
101 | struct hist_iter_ops { | ||
102 | int (*prepare_entry)(struct hist_entry_iter *, struct addr_location *); | ||
103 | int (*add_single_entry)(struct hist_entry_iter *, struct addr_location *); | ||
104 | int (*next_entry)(struct hist_entry_iter *, struct addr_location *); | ||
105 | int (*add_next_entry)(struct hist_entry_iter *, struct addr_location *); | ||
106 | int (*finish_entry)(struct hist_entry_iter *, struct addr_location *); | ||
107 | }; | ||
108 | |||
109 | struct hist_entry_iter { | ||
110 | int total; | ||
111 | int curr; | ||
112 | |||
113 | bool hide_unresolved; | ||
114 | |||
115 | struct perf_evsel *evsel; | ||
116 | struct perf_sample *sample; | ||
117 | struct hist_entry *he; | ||
118 | struct symbol *parent; | ||
119 | void *priv; | ||
120 | |||
121 | const struct hist_iter_ops *ops; | ||
122 | /* user-defined callback function (optional) */ | ||
123 | int (*add_entry_cb)(struct hist_entry_iter *iter, | ||
124 | struct addr_location *al, bool single, void *arg); | ||
125 | }; | ||
126 | |||
127 | extern const struct hist_iter_ops hist_iter_normal; | ||
128 | extern const struct hist_iter_ops hist_iter_branch; | ||
129 | extern const struct hist_iter_ops hist_iter_mem; | ||
130 | extern const struct hist_iter_ops hist_iter_cumulative; | ||
131 | |||
99 | struct hist_entry *__hists__add_entry(struct hists *hists, | 132 | struct hist_entry *__hists__add_entry(struct hists *hists, |
100 | struct addr_location *al, | 133 | struct addr_location *al, |
101 | struct symbol *parent, | 134 | struct symbol *parent, |
102 | struct branch_info *bi, | 135 | struct branch_info *bi, |
103 | struct mem_info *mi, u64 period, | 136 | struct mem_info *mi, u64 period, |
104 | u64 weight, u64 transaction); | 137 | u64 weight, u64 transaction, |
138 | bool sample_self); | ||
139 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, | ||
140 | struct perf_evsel *evsel, struct perf_sample *sample, | ||
141 | int max_stack_depth, void *arg); | ||
142 | |||
105 | int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right); | 143 | int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right); |
106 | int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right); | 144 | int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right); |
107 | int hist_entry__transaction_len(void); | 145 | int hist_entry__transaction_len(void); |
@@ -119,6 +157,7 @@ u64 hists__total_period(struct hists *hists); | |||
119 | void hists__reset_stats(struct hists *hists); | 157 | void hists__reset_stats(struct hists *hists); |
120 | void hists__inc_stats(struct hists *hists, struct hist_entry *h); | 158 | void hists__inc_stats(struct hists *hists, struct hist_entry *h); |
121 | void hists__inc_nr_events(struct hists *hists, u32 type); | 159 | void hists__inc_nr_events(struct hists *hists, u32 type); |
160 | void hists__inc_nr_samples(struct hists *hists, bool filtered); | ||
122 | void events_stats__inc(struct events_stats *stats, u32 type); | 161 | void events_stats__inc(struct events_stats *stats, u32 type); |
123 | size_t events_stats__fprintf(struct events_stats *stats, FILE *fp); | 162 | size_t events_stats__fprintf(struct events_stats *stats, FILE *fp); |
124 | 163 | ||
@@ -166,6 +205,7 @@ struct perf_hpp_fmt { | |||
166 | 205 | ||
167 | struct list_head list; | 206 | struct list_head list; |
168 | struct list_head sort_list; | 207 | struct list_head sort_list; |
208 | bool elide; | ||
169 | }; | 209 | }; |
170 | 210 | ||
171 | extern struct list_head perf_hpp__list; | 211 | extern struct list_head perf_hpp__list; |
@@ -192,6 +232,7 @@ enum { | |||
192 | PERF_HPP__OVERHEAD_US, | 232 | PERF_HPP__OVERHEAD_US, |
193 | PERF_HPP__OVERHEAD_GUEST_SYS, | 233 | PERF_HPP__OVERHEAD_GUEST_SYS, |
194 | PERF_HPP__OVERHEAD_GUEST_US, | 234 | PERF_HPP__OVERHEAD_GUEST_US, |
235 | PERF_HPP__OVERHEAD_ACC, | ||
195 | PERF_HPP__SAMPLES, | 236 | PERF_HPP__SAMPLES, |
196 | PERF_HPP__PERIOD, | 237 | PERF_HPP__PERIOD, |
197 | 238 | ||
@@ -200,7 +241,11 @@ enum { | |||
200 | 241 | ||
201 | void perf_hpp__init(void); | 242 | void perf_hpp__init(void); |
202 | void perf_hpp__column_register(struct perf_hpp_fmt *format); | 243 | void perf_hpp__column_register(struct perf_hpp_fmt *format); |
244 | void perf_hpp__column_unregister(struct perf_hpp_fmt *format); | ||
203 | void perf_hpp__column_enable(unsigned col); | 245 | void perf_hpp__column_enable(unsigned col); |
246 | void perf_hpp__column_disable(unsigned col); | ||
247 | void perf_hpp__cancel_cumulate(void); | ||
248 | |||
204 | void perf_hpp__register_sort_field(struct perf_hpp_fmt *format); | 249 | void perf_hpp__register_sort_field(struct perf_hpp_fmt *format); |
205 | void perf_hpp__setup_output_field(void); | 250 | void perf_hpp__setup_output_field(void); |
206 | void perf_hpp__reset_output_field(void); | 251 | void perf_hpp__reset_output_field(void); |
@@ -208,7 +253,12 @@ void perf_hpp__append_sort_keys(void); | |||
208 | 253 | ||
209 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); | 254 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); |
210 | bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b); | 255 | bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b); |
211 | bool perf_hpp__should_skip(struct perf_hpp_fmt *format); | 256 | |
257 | static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format) | ||
258 | { | ||
259 | return format->elide; | ||
260 | } | ||
261 | |||
212 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); | 262 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); |
213 | 263 | ||
214 | typedef u64 (*hpp_field_fn)(struct hist_entry *he); | 264 | typedef u64 (*hpp_field_fn)(struct hist_entry *he); |
@@ -218,6 +268,9 @@ typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); | |||
218 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, | 268 | int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, |
219 | hpp_field_fn get_field, const char *fmt, | 269 | hpp_field_fn get_field, const char *fmt, |
220 | hpp_snprint_fn print_fn, bool fmt_percent); | 270 | hpp_snprint_fn print_fn, bool fmt_percent); |
271 | int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he, | ||
272 | hpp_field_fn get_field, const char *fmt, | ||
273 | hpp_snprint_fn print_fn, bool fmt_percent); | ||
221 | 274 | ||
222 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) | 275 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) |
223 | { | 276 | { |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 901b9bece2ee..45512baaab67 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -1061,6 +1061,7 @@ static struct hpp_dimension hpp_sort_dimensions[] = { | |||
1061 | DIM(PERF_HPP__OVERHEAD_US, "overhead_us"), | 1061 | DIM(PERF_HPP__OVERHEAD_US, "overhead_us"), |
1062 | DIM(PERF_HPP__OVERHEAD_GUEST_SYS, "overhead_guest_sys"), | 1062 | DIM(PERF_HPP__OVERHEAD_GUEST_SYS, "overhead_guest_sys"), |
1063 | DIM(PERF_HPP__OVERHEAD_GUEST_US, "overhead_guest_us"), | 1063 | DIM(PERF_HPP__OVERHEAD_GUEST_US, "overhead_guest_us"), |
1064 | DIM(PERF_HPP__OVERHEAD_ACC, "overhead_children"), | ||
1064 | DIM(PERF_HPP__SAMPLES, "sample"), | 1065 | DIM(PERF_HPP__SAMPLES, "sample"), |
1065 | DIM(PERF_HPP__PERIOD, "period"), | 1066 | DIM(PERF_HPP__PERIOD, "period"), |
1066 | }; | 1067 | }; |
@@ -1156,6 +1157,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd) | |||
1156 | 1157 | ||
1157 | INIT_LIST_HEAD(&hse->hpp.list); | 1158 | INIT_LIST_HEAD(&hse->hpp.list); |
1158 | INIT_LIST_HEAD(&hse->hpp.sort_list); | 1159 | INIT_LIST_HEAD(&hse->hpp.sort_list); |
1160 | hse->hpp.elide = false; | ||
1159 | 1161 | ||
1160 | return hse; | 1162 | return hse; |
1161 | } | 1163 | } |
@@ -1363,27 +1365,64 @@ static int __setup_sorting(void) | |||
1363 | return ret; | 1365 | return ret; |
1364 | } | 1366 | } |
1365 | 1367 | ||
1366 | bool perf_hpp__should_skip(struct perf_hpp_fmt *format) | 1368 | void perf_hpp__set_elide(int idx, bool elide) |
1367 | { | 1369 | { |
1368 | if (perf_hpp__is_sort_entry(format)) { | 1370 | struct perf_hpp_fmt *fmt; |
1369 | struct hpp_sort_entry *hse; | 1371 | struct hpp_sort_entry *hse; |
1372 | |||
1373 | perf_hpp__for_each_format(fmt) { | ||
1374 | if (!perf_hpp__is_sort_entry(fmt)) | ||
1375 | continue; | ||
1370 | 1376 | ||
1371 | hse = container_of(format, struct hpp_sort_entry, hpp); | 1377 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
1372 | return hse->se->elide; | 1378 | if (hse->se->se_width_idx == idx) { |
1379 | fmt->elide = elide; | ||
1380 | break; | ||
1381 | } | ||
1373 | } | 1382 | } |
1374 | return false; | ||
1375 | } | 1383 | } |
1376 | 1384 | ||
1377 | static void sort_entry__setup_elide(struct sort_entry *se, | 1385 | static bool __get_elide(struct strlist *list, const char *list_name, FILE *fp) |
1378 | struct strlist *list, | ||
1379 | const char *list_name, FILE *fp) | ||
1380 | { | 1386 | { |
1381 | if (list && strlist__nr_entries(list) == 1) { | 1387 | if (list && strlist__nr_entries(list) == 1) { |
1382 | if (fp != NULL) | 1388 | if (fp != NULL) |
1383 | fprintf(fp, "# %s: %s\n", list_name, | 1389 | fprintf(fp, "# %s: %s\n", list_name, |
1384 | strlist__entry(list, 0)->s); | 1390 | strlist__entry(list, 0)->s); |
1385 | se->elide = true; | 1391 | return true; |
1386 | } | 1392 | } |
1393 | return false; | ||
1394 | } | ||
1395 | |||
1396 | static bool get_elide(int idx, FILE *output) | ||
1397 | { | ||
1398 | switch (idx) { | ||
1399 | case HISTC_SYMBOL: | ||
1400 | return __get_elide(symbol_conf.sym_list, "symbol", output); | ||
1401 | case HISTC_DSO: | ||
1402 | return __get_elide(symbol_conf.dso_list, "dso", output); | ||
1403 | case HISTC_COMM: | ||
1404 | return __get_elide(symbol_conf.comm_list, "comm", output); | ||
1405 | default: | ||
1406 | break; | ||
1407 | } | ||
1408 | |||
1409 | if (sort__mode != SORT_MODE__BRANCH) | ||
1410 | return false; | ||
1411 | |||
1412 | switch (idx) { | ||
1413 | case HISTC_SYMBOL_FROM: | ||
1414 | return __get_elide(symbol_conf.sym_from_list, "sym_from", output); | ||
1415 | case HISTC_SYMBOL_TO: | ||
1416 | return __get_elide(symbol_conf.sym_to_list, "sym_to", output); | ||
1417 | case HISTC_DSO_FROM: | ||
1418 | return __get_elide(symbol_conf.dso_from_list, "dso_from", output); | ||
1419 | case HISTC_DSO_TO: | ||
1420 | return __get_elide(symbol_conf.dso_to_list, "dso_to", output); | ||
1421 | default: | ||
1422 | break; | ||
1423 | } | ||
1424 | |||
1425 | return false; | ||
1387 | } | 1426 | } |
1388 | 1427 | ||
1389 | void sort__setup_elide(FILE *output) | 1428 | void sort__setup_elide(FILE *output) |
@@ -1391,39 +1430,12 @@ void sort__setup_elide(FILE *output) | |||
1391 | struct perf_hpp_fmt *fmt; | 1430 | struct perf_hpp_fmt *fmt; |
1392 | struct hpp_sort_entry *hse; | 1431 | struct hpp_sort_entry *hse; |
1393 | 1432 | ||
1394 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | 1433 | perf_hpp__for_each_format(fmt) { |
1395 | "dso", output); | 1434 | if (!perf_hpp__is_sort_entry(fmt)) |
1396 | sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, | 1435 | continue; |
1397 | "comm", output); | 1436 | |
1398 | sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, | 1437 | hse = container_of(fmt, struct hpp_sort_entry, hpp); |
1399 | "symbol", output); | 1438 | fmt->elide = get_elide(hse->se->se_width_idx, output); |
1400 | |||
1401 | if (sort__mode == SORT_MODE__BRANCH) { | ||
1402 | sort_entry__setup_elide(&sort_dso_from, | ||
1403 | symbol_conf.dso_from_list, | ||
1404 | "dso_from", output); | ||
1405 | sort_entry__setup_elide(&sort_dso_to, | ||
1406 | symbol_conf.dso_to_list, | ||
1407 | "dso_to", output); | ||
1408 | sort_entry__setup_elide(&sort_sym_from, | ||
1409 | symbol_conf.sym_from_list, | ||
1410 | "sym_from", output); | ||
1411 | sort_entry__setup_elide(&sort_sym_to, | ||
1412 | symbol_conf.sym_to_list, | ||
1413 | "sym_to", output); | ||
1414 | } else if (sort__mode == SORT_MODE__MEMORY) { | ||
1415 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | ||
1416 | "symbol_daddr", output); | ||
1417 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | ||
1418 | "dso_daddr", output); | ||
1419 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | ||
1420 | "mem", output); | ||
1421 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | ||
1422 | "local_weight", output); | ||
1423 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | ||
1424 | "tlb", output); | ||
1425 | sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, | ||
1426 | "snoop", output); | ||
1427 | } | 1439 | } |
1428 | 1440 | ||
1429 | /* | 1441 | /* |
@@ -1434,8 +1446,7 @@ void sort__setup_elide(FILE *output) | |||
1434 | if (!perf_hpp__is_sort_entry(fmt)) | 1446 | if (!perf_hpp__is_sort_entry(fmt)) |
1435 | continue; | 1447 | continue; |
1436 | 1448 | ||
1437 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | 1449 | if (!fmt->elide) |
1438 | if (!hse->se->elide) | ||
1439 | return; | 1450 | return; |
1440 | } | 1451 | } |
1441 | 1452 | ||
@@ -1443,8 +1454,7 @@ void sort__setup_elide(FILE *output) | |||
1443 | if (!perf_hpp__is_sort_entry(fmt)) | 1454 | if (!perf_hpp__is_sort_entry(fmt)) |
1444 | continue; | 1455 | continue; |
1445 | 1456 | ||
1446 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | 1457 | fmt->elide = false; |
1447 | hse->se->elide = false; | ||
1448 | } | 1458 | } |
1449 | } | 1459 | } |
1450 | 1460 | ||
@@ -1581,6 +1591,9 @@ void reset_output_field(void) | |||
1581 | sort__has_sym = 0; | 1591 | sort__has_sym = 0; |
1582 | sort__has_dso = 0; | 1592 | sort__has_dso = 0; |
1583 | 1593 | ||
1594 | field_order = NULL; | ||
1595 | sort_order = NULL; | ||
1596 | |||
1584 | reset_dimensions(); | 1597 | reset_dimensions(); |
1585 | perf_hpp__reset_output_field(); | 1598 | perf_hpp__reset_output_field(); |
1586 | } | 1599 | } |
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 5f38d925e92f..5bf0098d6b06 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | #include "parse-options.h" | 21 | #include "parse-options.h" |
22 | #include "parse-events.h" | 22 | #include "parse-events.h" |
23 | 23 | #include "hist.h" | |
24 | #include "thread.h" | 24 | #include "thread.h" |
25 | 25 | ||
26 | extern regex_t parent_regex; | 26 | extern regex_t parent_regex; |
@@ -82,6 +82,7 @@ struct hist_entry { | |||
82 | struct list_head head; | 82 | struct list_head head; |
83 | } pairs; | 83 | } pairs; |
84 | struct he_stat stat; | 84 | struct he_stat stat; |
85 | struct he_stat *stat_acc; | ||
85 | struct map_symbol ms; | 86 | struct map_symbol ms; |
86 | struct thread *thread; | 87 | struct thread *thread; |
87 | struct comm *comm; | 88 | struct comm *comm; |
@@ -130,6 +131,21 @@ static inline void hist_entry__add_pair(struct hist_entry *pair, | |||
130 | list_add_tail(&pair->pairs.node, &he->pairs.head); | 131 | list_add_tail(&pair->pairs.node, &he->pairs.head); |
131 | } | 132 | } |
132 | 133 | ||
134 | static inline float hist_entry__get_percent_limit(struct hist_entry *he) | ||
135 | { | ||
136 | u64 period = he->stat.period; | ||
137 | u64 total_period = hists__total_period(he->hists); | ||
138 | |||
139 | if (unlikely(total_period == 0)) | ||
140 | return 0; | ||
141 | |||
142 | if (symbol_conf.cumulate_callchain) | ||
143 | period = he->stat_acc->period; | ||
144 | |||
145 | return period * 100.0 / total_period; | ||
146 | } | ||
147 | |||
148 | |||
133 | enum sort_mode { | 149 | enum sort_mode { |
134 | SORT_MODE__NORMAL, | 150 | SORT_MODE__NORMAL, |
135 | SORT_MODE__BRANCH, | 151 | SORT_MODE__BRANCH, |
@@ -186,7 +202,6 @@ struct sort_entry { | |||
186 | int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, | 202 | int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, |
187 | unsigned int width); | 203 | unsigned int width); |
188 | u8 se_width_idx; | 204 | u8 se_width_idx; |
189 | bool elide; | ||
190 | }; | 205 | }; |
191 | 206 | ||
192 | extern struct sort_entry sort_thread; | 207 | extern struct sort_entry sort_thread; |
@@ -197,6 +212,7 @@ int setup_output_field(void); | |||
197 | void reset_output_field(void); | 212 | void reset_output_field(void); |
198 | extern int sort_dimension__add(const char *); | 213 | extern int sort_dimension__add(const char *); |
199 | void sort__setup_elide(FILE *fp); | 214 | void sort__setup_elide(FILE *fp); |
215 | void perf_hpp__set_elide(int idx, bool elide); | ||
200 | 216 | ||
201 | int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); | 217 | int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); |
202 | 218 | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 95e249779931..7b9096f29cdb 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -29,11 +29,12 @@ int vmlinux_path__nr_entries; | |||
29 | char **vmlinux_path; | 29 | char **vmlinux_path; |
30 | 30 | ||
31 | struct symbol_conf symbol_conf = { | 31 | struct symbol_conf symbol_conf = { |
32 | .use_modules = true, | 32 | .use_modules = true, |
33 | .try_vmlinux_path = true, | 33 | .try_vmlinux_path = true, |
34 | .annotate_src = true, | 34 | .annotate_src = true, |
35 | .demangle = true, | 35 | .demangle = true, |
36 | .symfs = "", | 36 | .cumulate_callchain = true, |
37 | .symfs = "", | ||
37 | }; | 38 | }; |
38 | 39 | ||
39 | static enum dso_binary_type binary_type_symtab[] = { | 40 | static enum dso_binary_type binary_type_symtab[] = { |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 33ede53fa6b9..615c752dd767 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -109,6 +109,7 @@ struct symbol_conf { | |||
109 | show_nr_samples, | 109 | show_nr_samples, |
110 | show_total_period, | 110 | show_total_period, |
111 | use_callchain, | 111 | use_callchain, |
112 | cumulate_callchain, | ||
112 | exclude_other, | 113 | exclude_other, |
113 | show_cpu_utilization, | 114 | show_cpu_utilization, |
114 | initialized, | 115 | initialized, |