Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
bf9e1876 IM |
2 | /* |
3 | * builtin-report.c | |
4 | * | |
5 | * Builtin report command: Analyze the perf.data input file, | |
6 | * look up and read DSOs and symbol information and display | |
7 | * a histogram of results, along various sorting keys. | |
8 | */ | |
16f762a2 | 9 | #include "builtin.h" |
53cb8bc2 | 10 | |
41840d21 | 11 | #include "util/config.h" |
bf9e1876 | 12 | |
78f7defe | 13 | #include "util/annotate.h" |
8fc0321f | 14 | #include "util/color.h" |
4a3cec84 | 15 | #include "util/dso.h" |
5da50258 | 16 | #include <linux/list.h> |
43cbcd8a | 17 | #include <linux/rbtree.h> |
930f8b34 | 18 | #include <linux/err.h> |
7f7c536f | 19 | #include <linux/zalloc.h> |
1101f69a | 20 | #include "util/map.h" |
a2928c42 | 21 | #include "util/symbol.h" |
d3300a3c ACM |
22 | #include "util/map_symbol.h" |
23 | #include "util/mem-events.h" | |
24 | #include "util/branch.h" | |
f55c5552 | 25 | #include "util/callchain.h" |
8d513270 | 26 | #include "util/values.h" |
8fa66bdc | 27 | |
53cb8bc2 | 28 | #include "perf.h" |
8f28827a | 29 | #include "util/debug.h" |
e248de33 ACM |
30 | #include "util/evlist.h" |
31 | #include "util/evsel.h" | |
ef4b1a53 | 32 | #include "util/evswitch.h" |
7c6a1c65 | 33 | #include "util/header.h" |
ad3003a6 | 34 | #include "util/mem-info.h" |
94c744b6 | 35 | #include "util/session.h" |
97b9d866 | 36 | #include "util/srcline.h" |
45694aa7 | 37 | #include "util/tool.h" |
53cb8bc2 | 38 | |
4b6ab94e | 39 | #include <subcmd/parse-options.h> |
34b7b0f9 | 40 | #include <subcmd/exec-cmd.h> |
53cb8bc2 IM |
41 | #include "util/parse-events.h" |
42 | ||
6baa0a5a | 43 | #include "util/thread.h" |
dd68ada2 | 44 | #include "util/sort.h" |
3d1d07ec | 45 | #include "util/hist.h" |
f5fc1412 | 46 | #include "util/data.h" |
68e94f4e | 47 | #include "arch/common.h" |
46690a80 | 48 | #include "util/time-utils.h" |
520a2ebc | 49 | #include "util/auxtrace.h" |
58db1d6e | 50 | #include "util/units.h" |
fb71c86c | 51 | #include "util/util.h" // perf_tip() |
8520a98d | 52 | #include "ui/ui.h" |
171f7474 | 53 | #include "ui/progress.h" |
6f7164fa | 54 | #include "util/block-info.h" |
520a2ebc | 55 | |
fc67297b | 56 | #include <dlfcn.h> |
a43783ae | 57 | #include <errno.h> |
fd20e811 | 58 | #include <inttypes.h> |
1eae20c1 | 59 | #include <regex.h> |
3052ba56 | 60 | #include <linux/ctype.h> |
9607ad3a | 61 | #include <signal.h> |
5d67be97 | 62 | #include <linux/bitmap.h> |
2f1e20fe | 63 | #include <linux/list_sort.h> |
8520a98d | 64 | #include <linux/string.h> |
531d2410 | 65 | #include <linux/stringify.h> |
2a1292cb | 66 | #include <linux/time64.h> |
7a8ef4c4 ACM |
67 | #include <sys/types.h> |
68 | #include <sys/stat.h> | |
69 | #include <unistd.h> | |
6439d7d1 | 70 | #include <linux/mman.h> |
5d67be97 | 71 | |
378ef0f5 | 72 | #ifdef HAVE_LIBTRACEEVENT |
35de42cd | 73 | #include <event-parse.h> |
378ef0f5 IR |
74 | #endif |
75 | ||
28b21393 | 76 | struct report { |
45694aa7 | 77 | struct perf_tool tool; |
d20deb64 | 78 | struct perf_session *session; |
ef4b1a53 | 79 | struct evswitch evswitch; |
3402ae0a IR |
80 | #ifdef HAVE_SLANG_SUPPORT |
81 | bool use_tui; | |
82 | #endif | |
557cc18e | 83 | #ifdef HAVE_GTK2_SUPPORT |
3402ae0a | 84 | bool use_gtk; |
557cc18e | 85 | #endif |
3402ae0a | 86 | bool use_stdio; |
fa372aae ACM |
87 | bool show_full_info; |
88 | bool show_threads; | |
89 | bool inverted_callchain; | |
f4f7e28d | 90 | bool mem_mode; |
a4a4d0a7 | 91 | bool stats_mode; |
930f8b34 | 92 | bool tasks_mode; |
6439d7d1 | 93 | bool mmaps_mode; |
5cfe2c82 JO |
94 | bool header; |
95 | bool header_only; | |
98df858e | 96 | bool nonany_branch_mode; |
57b5de46 | 97 | bool group_set; |
b1d1429b | 98 | bool stitch_lbr; |
2e989f82 | 99 | bool disable_order; |
2775de0b | 100 | bool skip_empty; |
81e57dee | 101 | bool data_type; |
91e95617 | 102 | int max_stack; |
fa372aae ACM |
103 | struct perf_read_values show_threads_values; |
104 | const char *pretty_printing_style; | |
fa372aae | 105 | const char *cpu_list; |
b14ffaca | 106 | const char *symbol_filter_str; |
46690a80 | 107 | const char *time_str; |
0a3cc3ae JY |
108 | struct perf_time_interval *ptime_range; |
109 | int range_size; | |
5b969bc7 | 110 | int range_num; |
064f1981 | 111 | float min_percent; |
58c311da | 112 | u64 nr_entries; |
94786b67 | 113 | u64 queue_size; |
6f7164fa | 114 | u64 total_cycles; |
2570c02c DV |
115 | u64 total_samples; |
116 | u64 singlethreaded_samples; | |
21394d94 | 117 | int socket_filter; |
fa372aae | 118 | DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
2d78b189 | 119 | struct branch_type_stat brtype_stat; |
ec6ae74f | 120 | bool symbol_ipc; |
6f7164fa JY |
121 | bool total_cycles_mode; |
122 | struct block_report *block_reports; | |
cca0cc76 | 123 | int nr_block_reports; |
d20deb64 | 124 | }; |
5d67be97 | 125 | |
28b21393 | 126 | static int report__config(const char *var, const char *value, void *cb) |
00c7e1f1 | 127 | { |
94786b67 JO |
128 | struct report *rep = cb; |
129 | ||
00c7e1f1 NK |
130 | if (!strcmp(var, "report.group")) { |
131 | symbol_conf.event_group = perf_config_bool(var, value); | |
132 | return 0; | |
133 | } | |
eec574e6 | 134 | if (!strcmp(var, "report.percent-limit")) { |
2665b452 NK |
135 | double pcnt = strtof(value, NULL); |
136 | ||
137 | rep->min_percent = pcnt; | |
138 | callchain_param.min_percent = pcnt; | |
eec574e6 NK |
139 | return 0; |
140 | } | |
8d8e645c NK |
141 | if (!strcmp(var, "report.children")) { |
142 | symbol_conf.cumulate_callchain = perf_config_bool(var, value); | |
143 | return 0; | |
144 | } | |
25ce4bb8 ACM |
145 | if (!strcmp(var, "report.queue-size")) |
146 | return perf_config_u64(&rep->queue_size, var, value); | |
147 | ||
fa1f4565 ACM |
148 | if (!strcmp(var, "report.sort_order")) { |
149 | default_sort_order = strdup(value); | |
8f08c363 IR |
150 | if (!default_sort_order) { |
151 | pr_err("Not enough memory for report.sort_order\n"); | |
152 | return -1; | |
153 | } | |
fa1f4565 ACM |
154 | return 0; |
155 | } | |
00c7e1f1 | 156 | |
8f08cf33 NK |
157 | if (!strcmp(var, "report.skip-empty")) { |
158 | rep->skip_empty = perf_config_bool(var, value); | |
159 | return 0; | |
160 | } | |
161 | ||
8f08c363 | 162 | pr_debug("%s variable unknown, ignoring...", var); |
b8cbb349 | 163 | return 0; |
00c7e1f1 NK |
164 | } |
165 | ||
9d3c02d7 NK |
166 | static int hist_iter__report_callback(struct hist_entry_iter *iter, |
167 | struct addr_location *al, bool single, | |
168 | void *arg) | |
169 | { | |
170 | int err = 0; | |
171 | struct report *rep = arg; | |
172 | struct hist_entry *he = iter->he; | |
32dcd021 | 173 | struct evsel *evsel = iter->evsel; |
bab89f6a | 174 | struct perf_sample *sample = iter->sample; |
9d3c02d7 NK |
175 | struct mem_info *mi; |
176 | struct branch_info *bi; | |
177 | ||
6cdd977e | 178 | if (!ui__has_annotation() && !rep->symbol_ipc) |
9d3c02d7 NK |
179 | return 0; |
180 | ||
181 | if (sort__mode == SORT_MODE__BRANCH) { | |
182 | bi = he->branch_info; | |
e345f3bd | 183 | err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); |
9d3c02d7 NK |
184 | if (err) |
185 | goto out; | |
186 | ||
e345f3bd | 187 | err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); |
9d3c02d7 NK |
188 | |
189 | } else if (rep->mem_mode) { | |
190 | mi = he->mem_info; | |
1a8c2e01 | 191 | err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel); |
9d3c02d7 NK |
192 | if (err) |
193 | goto out; | |
194 | ||
e345f3bd | 195 | err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); |
9d3c02d7 NK |
196 | |
197 | } else if (symbol_conf.cumulate_callchain) { | |
198 | if (single) | |
e345f3bd | 199 | err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); |
9d3c02d7 | 200 | } else { |
e345f3bd | 201 | err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr); |
9d3c02d7 NK |
202 | } |
203 | ||
204 | out: | |
205 | return err; | |
f4f7e28d SE |
206 | } |
207 | ||
2d78b189 JY |
208 | static int hist_iter__branch_callback(struct hist_entry_iter *iter, |
209 | struct addr_location *al __maybe_unused, | |
210 | bool single __maybe_unused, | |
211 | void *arg) | |
212 | { | |
213 | struct hist_entry *he = iter->he; | |
214 | struct report *rep = arg; | |
c3b10649 | 215 | struct branch_info *bi = he->branch_info; |
40c39e30 | 216 | struct perf_sample *sample = iter->sample; |
32dcd021 | 217 | struct evsel *evsel = iter->evsel; |
40c39e30 JY |
218 | int err; |
219 | ||
c3b10649 JY |
220 | branch_type_count(&rep->brtype_stat, &bi->flags, |
221 | bi->from.addr, bi->to.addr); | |
222 | ||
ec6ae74f | 223 | if (!ui__has_annotation() && !rep->symbol_ipc) |
40c39e30 JY |
224 | return 0; |
225 | ||
e345f3bd | 226 | err = addr_map_symbol__inc_samples(&bi->from, sample, evsel); |
40c39e30 JY |
227 | if (err) |
228 | goto out; | |
229 | ||
e345f3bd | 230 | err = addr_map_symbol__inc_samples(&bi->to, sample, evsel); |
40c39e30 | 231 | |
40c39e30 JY |
232 | out: |
233 | return err; | |
2d78b189 JY |
234 | } |
235 | ||
57b5de46 | 236 | static void setup_forced_leader(struct report *report, |
63503dba | 237 | struct evlist *evlist) |
57b5de46 | 238 | { |
a26bb0ba | 239 | if (report->group_set) |
64b4778b | 240 | evlist__force_leader(evlist); |
57b5de46 JO |
241 | } |
242 | ||
89f1688a JO |
243 | static int process_feature_event(struct perf_session *session, |
244 | union perf_event *event) | |
57b5de46 | 245 | { |
89f1688a | 246 | struct report *rep = container_of(session->tool, struct report, tool); |
57b5de46 JO |
247 | |
248 | if (event->feat.feat_id < HEADER_LAST_FEATURE) | |
89f1688a | 249 | return perf_event__process_feature(session, event); |
57b5de46 JO |
250 | |
251 | if (event->feat.feat_id != HEADER_LAST_FEATURE) { | |
1b8896fb | 252 | pr_err("failed: wrong feature ID: %" PRI_lu64 "\n", |
57b5de46 JO |
253 | event->feat.feat_id); |
254 | return -1; | |
03de8656 NK |
255 | } else if (rep->header_only) { |
256 | session_done = 1; | |
57b5de46 JO |
257 | } |
258 | ||
259 | /* | |
92ead7ee RB |
260 | * (feat_id = HEADER_LAST_FEATURE) is the end marker which |
261 | * means all features are received, now we can force the | |
57b5de46 JO |
262 | * group if needed. |
263 | */ | |
264 | setup_forced_leader(rep, session->evlist); | |
265 | return 0; | |
266 | } | |
267 | ||
30f29bae | 268 | static int process_sample_event(const struct perf_tool *tool, |
d20deb64 | 269 | union perf_event *event, |
8115d60c | 270 | struct perf_sample *sample, |
32dcd021 | 271 | struct evsel *evsel, |
743eb868 | 272 | struct machine *machine) |
75051724 | 273 | { |
28b21393 | 274 | struct report *rep = container_of(tool, struct report, tool); |
1ed091c4 | 275 | struct addr_location al; |
69bcb019 | 276 | struct hist_entry_iter iter = { |
063bd936 NK |
277 | .evsel = evsel, |
278 | .sample = sample, | |
b49a8fe5 | 279 | .hide_unresolved = symbol_conf.hide_unresolved, |
063bd936 | 280 | .add_entry_cb = hist_iter__report_callback, |
69bcb019 | 281 | }; |
b91fc39f | 282 | int ret = 0; |
180f95e2 | 283 | |
5b969bc7 JY |
284 | if (perf_time__ranges_skip_sample(rep->ptime_range, rep->range_num, |
285 | sample->time)) { | |
46690a80 | 286 | return 0; |
5b969bc7 | 287 | } |
46690a80 | 288 | |
ef4b1a53 ACM |
289 | if (evswitch__discard(&rep->evswitch, evsel)) |
290 | return 0; | |
291 | ||
0dd5041c | 292 | addr_location__init(&al); |
bb3eb566 | 293 | if (machine__resolve(machine, &al, sample) < 0) { |
a4210141 NK |
294 | pr_debug("problem processing %d event, skipping it.\n", |
295 | event->header.type); | |
0dd5041c IR |
296 | ret = -1; |
297 | goto out_put; | |
75051724 | 298 | } |
e7fb08b1 | 299 | |
b1d1429b | 300 | if (rep->stitch_lbr) |
ee84a303 | 301 | thread__set_lbr_stitch_enable(al.thread, true); |
b1d1429b | 302 | |
b49a8fe5 | 303 | if (symbol_conf.hide_unresolved && al.sym == NULL) |
b91fc39f | 304 | goto out_put; |
7bec7a91 | 305 | |
fa372aae | 306 | if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) |
b91fc39f | 307 | goto out_put; |
5d67be97 | 308 | |
f86225db AH |
309 | if (sort__mode == SORT_MODE__BRANCH) { |
310 | /* | |
311 | * A non-synthesized event might not have a branch stack if | |
312 | * branch stacks have been synthesized (using itrace options). | |
313 | */ | |
314 | if (!sample->branch_stack) | |
315 | goto out_put; | |
2d78b189 JY |
316 | |
317 | iter.add_entry_cb = hist_iter__branch_callback; | |
69bcb019 | 318 | iter.ops = &hist_iter_branch; |
f86225db | 319 | } else if (rep->mem_mode) { |
69bcb019 | 320 | iter.ops = &hist_iter_mem; |
f86225db | 321 | } else if (symbol_conf.cumulate_callchain) { |
7a13aa28 | 322 | iter.ops = &hist_iter_cumulative; |
f86225db | 323 | } else { |
69bcb019 | 324 | iter.ops = &hist_iter_normal; |
f86225db | 325 | } |
69bcb019 NK |
326 | |
327 | if (al.map != NULL) | |
ee756ef7 | 328 | dso__set_hit(map__dso(al.map)); |
69bcb019 | 329 | |
6f7164fa | 330 | if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) { |
bdd1666b | 331 | hist__account_cycles(sample->branch_stack, &al, sample, |
6f7164fa | 332 | rep->nonany_branch_mode, |
1f2b7fbb | 333 | &rep->total_cycles, evsel); |
bdd1666b JY |
334 | } |
335 | ||
2570c02c DV |
336 | rep->total_samples++; |
337 | if (al.parallelism == 1) | |
338 | rep->singlethreaded_samples++; | |
339 | ||
063bd936 | 340 | ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep); |
69bcb019 NK |
341 | if (ret < 0) |
342 | pr_debug("problem adding hist entry, skipping event\n"); | |
b91fc39f | 343 | out_put: |
0dd5041c | 344 | addr_location__exit(&al); |
27a0dcb7 | 345 | return ret; |
75051724 | 346 | } |
3502973d | 347 | |
30f29bae | 348 | static int process_read_event(const struct perf_tool *tool, |
d20deb64 | 349 | union perf_event *event, |
1d037ca1 | 350 | struct perf_sample *sample __maybe_unused, |
32dcd021 | 351 | struct evsel *evsel, |
1d037ca1 | 352 | struct machine *machine __maybe_unused) |
e9ea2fde | 353 | { |
28b21393 | 354 | struct report *rep = container_of(tool, struct report, tool); |
743eb868 | 355 | |
fa372aae | 356 | if (rep->show_threads) { |
89973506 | 357 | int err = perf_read_values_add_value(&rep->show_threads_values, |
8d513270 | 358 | event->read.pid, event->read.tid, |
2f4847b5 | 359 | evsel, |
8d513270 | 360 | event->read.value); |
89973506 ACM |
361 | |
362 | if (err) | |
363 | return err; | |
8d513270 BG |
364 | } |
365 | ||
e9ea2fde PZ |
366 | return 0; |
367 | } | |
368 | ||
300aa941 | 369 | /* For pipe mode, sample_type is not currently set */ |
28b21393 | 370 | static int report__setup_sample_type(struct report *rep) |
d80d338d | 371 | { |
c824c433 | 372 | struct perf_session *session = rep->session; |
b3c2cc2b | 373 | u64 sample_type = evlist__combined_sample_type(session->evlist); |
8ceb41d7 | 374 | bool is_pipe = perf_data__is_pipe(session->data); |
ccb17cae | 375 | struct evsel *evsel; |
d20deb64 | 376 | |
d062ac16 | 377 | if (session->itrace_synth_opts->callchain || |
1c5c25b3 | 378 | session->itrace_synth_opts->add_callchain || |
d062ac16 AH |
379 | (!is_pipe && |
380 | perf_header__has_feat(&session->header, HEADER_AUXTRACE) && | |
381 | !session->itrace_synth_opts->set)) | |
382 | sample_type |= PERF_SAMPLE_CALLCHAIN; | |
383 | ||
ec90e42c AH |
384 | if (session->itrace_synth_opts->last_branch || |
385 | session->itrace_synth_opts->add_last_branch) | |
c7eced63 AH |
386 | sample_type |= PERF_SAMPLE_BRANCH_STACK; |
387 | ||
cc9784bd | 388 | if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) { |
de7e6a7c | 389 | if (perf_hpp_list.parent) { |
3780f488 | 390 | ui__error("Selected --sort parent, but no " |
00894ce9 ACM |
391 | "callchain data. Did you call " |
392 | "'perf record' without -g?\n"); | |
d549c769 | 393 | return -EINVAL; |
91b4eaea | 394 | } |
b49a821e JY |
395 | if (symbol_conf.use_callchain && |
396 | !symbol_conf.show_branchflag_count) { | |
397 | ui__error("Selected -g or --branch-history.\n" | |
398 | "But no callchain or branch data.\n" | |
399 | "Did you call 'perf record' without -g or -b?\n"); | |
016e92fb | 400 | return -1; |
91b4eaea | 401 | } |
1cc83815 | 402 | } else if (!callchain_param.enabled && |
fa372aae | 403 | callchain_param.mode != CHAIN_NONE && |
b9a63b9b | 404 | !symbol_conf.use_callchain) { |
d599db3f | 405 | symbol_conf.use_callchain = true; |
16537f13 | 406 | if (callchain_register_param(&callchain_param) < 0) { |
3780f488 | 407 | ui__error("Can't register callchain params.\n"); |
d549c769 | 408 | return -EINVAL; |
b1a88349 | 409 | } |
f5970550 PZ |
410 | } |
411 | ||
793aaaab NK |
412 | if (symbol_conf.cumulate_callchain) { |
413 | /* Silently ignore if callchain is missing */ | |
414 | if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) { | |
415 | symbol_conf.cumulate_callchain = false; | |
dbd11b6b | 416 | perf_hpp__cancel_cumulate(session->evlist); |
793aaaab NK |
417 | } |
418 | } | |
419 | ||
55369fc1 | 420 | if (sort__mode == SORT_MODE__BRANCH) { |
cc9784bd | 421 | if (!is_pipe && |
7f3be652 | 422 | !(sample_type & PERF_SAMPLE_BRANCH_STACK)) { |
3780f488 NK |
423 | ui__error("Selected -b but no branch data. " |
424 | "Did you call perf record without -b?\n"); | |
b50311dc RAV |
425 | return -1; |
426 | } | |
427 | } | |
428 | ||
bb30acae | 429 | if (sort__mode == SORT_MODE__MEMORY) { |
ccb17cae LY |
430 | /* |
431 | * FIXUP: prior to kernel 5.18, Arm SPE missed to set | |
432 | * PERF_SAMPLE_DATA_SRC bit in sample type. For backward | |
433 | * compatibility, set the bit if it's an old perf data file. | |
434 | */ | |
435 | evlist__for_each_entry(session->evlist, evsel) { | |
45b4f402 | 436 | if (strstr(evsel__name(evsel), "arm_spe") && |
ccb17cae LY |
437 | !(sample_type & PERF_SAMPLE_DATA_SRC)) { |
438 | evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC; | |
439 | sample_type |= PERF_SAMPLE_DATA_SRC; | |
440 | } | |
441 | } | |
442 | ||
bb30acae RB |
443 | if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) { |
444 | ui__error("Selected --mem-mode but no mem data. " | |
445 | "Did you call perf record without -d?\n"); | |
446 | return -1; | |
447 | } | |
448 | } | |
449 | ||
aa8db3e4 | 450 | callchain_param_setup(sample_type, perf_env__arch(&rep->session->header.env)); |
98df858e | 451 | |
b1d1429b KL |
452 | if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) { |
453 | ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" | |
454 | "Please apply --call-graph lbr when recording.\n"); | |
455 | rep->stitch_lbr = false; | |
456 | } | |
457 | ||
98df858e | 458 | /* ??? handle more cases than just ANY? */ |
92c7d7cd | 459 | if (!(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_ANY)) |
98df858e AK |
460 | rep->nonany_branch_mode = true; |
461 | ||
8838abf6 | 462 | #if !defined(HAVE_LIBUNWIND_SUPPORT) && !defined(HAVE_LIBDW_SUPPORT) |
800d3f56 | 463 | if (dwarf_callchain_users) { |
c3314a74 JY |
464 | ui__warning("Please install libunwind or libdw " |
465 | "development packages during the perf build.\n"); | |
800d3f56 JY |
466 | } |
467 | #endif | |
468 | ||
016e92fb FW |
469 | return 0; |
470 | } | |
6142f9ec | 471 | |
1d037ca1 | 472 | static void sig_handler(int sig __maybe_unused) |
46656ac7 TZ |
473 | { |
474 | session_done = 1; | |
475 | } | |
476 | ||
28b21393 | 477 | static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report *rep, |
c82ee828 ACM |
478 | const char *evname, FILE *fp) |
479 | { | |
480 | size_t ret; | |
481 | char unit; | |
0f0abbac | 482 | unsigned long nr_samples = hists->stats.nr_samples; |
c824c433 | 483 | u64 nr_events = hists->stats.total_period; |
32dcd021 | 484 | struct evsel *evsel = hists_to_evsel(hists); |
717e263f NK |
485 | char buf[512]; |
486 | size_t size = sizeof(buf); | |
84734b06 | 487 | int socked_id = hists->socket_filter; |
717e263f | 488 | |
27fafab5 NK |
489 | if (quiet) |
490 | return 0; | |
491 | ||
f2148330 NK |
492 | if (symbol_conf.filter_relative) { |
493 | nr_samples = hists->stats.nr_non_filtered_samples; | |
494 | nr_events = hists->stats.total_non_filtered_period; | |
495 | } | |
496 | ||
c754c382 | 497 | if (evsel__is_group_event(evsel)) { |
32dcd021 | 498 | struct evsel *pos; |
717e263f | 499 | |
347c751a | 500 | evsel__group_desc(evsel, buf, size); |
717e263f NK |
501 | evname = buf; |
502 | ||
503 | for_each_group_member(pos, evsel) { | |
4ea062ed ACM |
504 | const struct hists *pos_hists = evsel__hists(pos); |
505 | ||
f2148330 | 506 | if (symbol_conf.filter_relative) { |
4ea062ed ACM |
507 | nr_samples += pos_hists->stats.nr_non_filtered_samples; |
508 | nr_events += pos_hists->stats.total_non_filtered_period; | |
f2148330 | 509 | } else { |
0f0abbac | 510 | nr_samples += pos_hists->stats.nr_samples; |
4ea062ed | 511 | nr_events += pos_hists->stats.total_period; |
f2148330 | 512 | } |
717e263f NK |
513 | } |
514 | } | |
c82ee828 | 515 | |
cc686280 AR |
516 | nr_samples = convert_unit(nr_samples, &unit); |
517 | ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit); | |
8ef278bb JO |
518 | if (evname != NULL) { |
519 | ret += fprintf(fp, " of event%s '%s'", | |
5643b1a5 | 520 | evsel->core.nr_members > 1 ? "s" : "", evname); |
8ef278bb | 521 | } |
cc686280 | 522 | |
7425664b JY |
523 | if (rep->time_str) |
524 | ret += fprintf(fp, " (time slices: %s)", rep->time_str); | |
525 | ||
11b6e548 | 526 | if (symbol_conf.show_ref_callgraph && evname && strstr(evname, "call-graph=no")) { |
9e207ddf KL |
527 | ret += fprintf(fp, ", show reference callgraph"); |
528 | } | |
529 | ||
f4f7e28d SE |
530 | if (rep->mem_mode) { |
531 | ret += fprintf(fp, "\n# Total weight : %" PRIu64, nr_events); | |
7a6710d0 NK |
532 | if (sort_order || !field_order) { |
533 | ret += fprintf(fp, "\n# Sort order : %s", | |
534 | sort_order ? : default_mem_sort_order); | |
535 | } | |
f4f7e28d SE |
536 | } else |
537 | ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events); | |
21394d94 | 538 | |
84734b06 KL |
539 | if (socked_id > -1) |
540 | ret += fprintf(fp, "\n# Processor Socket: %d", socked_id); | |
21394d94 | 541 | |
c82ee828 ACM |
542 | return ret + fprintf(fp, "\n#\n"); |
543 | } | |
544 | ||
f4bd0b4a | 545 | static int evlist__tui_block_hists_browse(struct evlist *evlist, struct report *rep) |
7fa46cbf JY |
546 | { |
547 | struct evsel *pos; | |
548 | int i = 0, ret; | |
549 | ||
550 | evlist__for_each_entry(evlist, pos) { | |
551 | ret = report__browse_block_hists(&rep->block_reports[i++].hist, | |
848a5e50 | 552 | rep->min_percent, pos, |
22197fb2 | 553 | &rep->session->header.env); |
7fa46cbf JY |
554 | if (ret != 0) |
555 | return ret; | |
556 | } | |
557 | ||
558 | return 0; | |
559 | } | |
560 | ||
f4bd0b4a | 561 | static int evlist__tty_browse_hists(struct evlist *evlist, struct report *rep, const char *help) |
d67f088e | 562 | { |
32dcd021 | 563 | struct evsel *pos; |
6f7164fa | 564 | int i = 0; |
d67f088e | 565 | |
27fafab5 NK |
566 | if (!quiet) { |
567 | fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", | |
568 | evlist->stats.total_lost_samples); | |
569 | } | |
570 | ||
e5cadb93 | 571 | evlist__for_each_entry(evlist, pos) { |
4ea062ed | 572 | struct hists *hists = evsel__hists(pos); |
8ab2e96d | 573 | const char *evname = evsel__name(pos); |
d67f088e | 574 | |
3ef44458 | 575 | i++; |
c754c382 | 576 | if (symbol_conf.event_group && !evsel__is_group_leader(pos)) |
fc24d7c2 NK |
577 | continue; |
578 | ||
2775de0b NK |
579 | if (rep->skip_empty && !hists->stats.nr_samples) |
580 | continue; | |
581 | ||
28b21393 | 582 | hists__fprintf_nr_sample_events(hists, rep, evname, stdout); |
6f7164fa JY |
583 | |
584 | if (rep->total_cycles_mode) { | |
20d6f555 KL |
585 | char *buf; |
586 | ||
587 | if (!annotation_br_cntr_abbr_list(&buf, pos, true)) { | |
588 | fprintf(stdout, "%s", buf); | |
589 | fprintf(stdout, "#\n"); | |
590 | free(buf); | |
591 | } | |
3ef44458 | 592 | report__browse_block_hists(&rep->block_reports[i - 1].hist, |
22197fb2 | 593 | rep->min_percent, pos, NULL); |
6f7164fa JY |
594 | continue; |
595 | } | |
596 | ||
27fafab5 | 597 | hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout, |
e9de7e2f ACM |
598 | !(symbol_conf.use_callchain || |
599 | symbol_conf.show_branchflag_count)); | |
d67f088e | 600 | fprintf(stdout, "\n\n"); |
d67f088e ACM |
601 | } |
602 | ||
8b53dbef | 603 | if (!quiet) |
d67f088e ACM |
604 | fprintf(stdout, "#\n# (%s)\n#\n", help); |
605 | ||
021162cf NK |
606 | if (rep->show_threads) { |
607 | bool style = !strcmp(rep->pretty_printing_style, "raw"); | |
608 | perf_read_values_display(stdout, &rep->show_threads_values, | |
609 | style); | |
610 | perf_read_values_destroy(&rep->show_threads_values); | |
d67f088e ACM |
611 | } |
612 | ||
2d78b189 JY |
613 | if (sort__mode == SORT_MODE__BRANCH) |
614 | branch_type_stat_display(stdout, &rep->brtype_stat); | |
615 | ||
d67f088e ACM |
616 | return 0; |
617 | } | |
618 | ||
fad2918e ACM |
619 | static void report__warn_kptr_restrict(const struct report *rep) |
620 | { | |
a5e813c6 | 621 | struct map *kernel_map = machine__kernel_map(&rep->session->machines.host); |
f6fcc143 | 622 | struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL; |
fad2918e | 623 | |
78e1bc25 | 624 | if (evlist__exclude_kernel(rep->session->evlist)) |
9c39ed90 ACM |
625 | return; |
626 | ||
fad2918e | 627 | if (kernel_map == NULL || |
ee756ef7 | 628 | (dso__hit(map__dso(kernel_map)) && |
fad2918e ACM |
629 | (kernel_kmap->ref_reloc_sym == NULL || |
630 | kernel_kmap->ref_reloc_sym->addr == 0))) { | |
631 | const char *desc = | |
632 | "As no suitable kallsyms nor vmlinux was found, kernel samples\n" | |
633 | "can't be resolved."; | |
634 | ||
e94b861a ACM |
635 | if (kernel_map && map__has_symbols(kernel_map)) { |
636 | desc = "If some relocation was applied (e.g. " | |
637 | "kexec) symbols may be misresolved."; | |
fad2918e ACM |
638 | } |
639 | ||
640 | ui__warning( | |
641 | "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n" | |
642 | "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n" | |
643 | "Samples in kernel modules can't be resolved as well.\n\n", | |
644 | desc); | |
645 | } | |
646 | } | |
647 | ||
8362951b ACM |
648 | static int report__gtk_browse_hists(struct report *rep, const char *help) |
649 | { | |
63503dba | 650 | int (*hist_browser)(struct evlist *evlist, const char *help, |
8362951b ACM |
651 | struct hist_browser_timer *timer, float min_pcnt); |
652 | ||
f4bd0b4a | 653 | hist_browser = dlsym(perf_gtk_handle, "evlist__gtk_browse_hists"); |
8362951b ACM |
654 | |
655 | if (hist_browser == NULL) { | |
656 | ui__error("GTK browser not found!\n"); | |
657 | return -1; | |
658 | } | |
659 | ||
660 | return hist_browser(rep->session->evlist, help, NULL, rep->min_percent); | |
661 | } | |
662 | ||
663 | static int report__browse_hists(struct report *rep) | |
664 | { | |
665 | int ret; | |
666 | struct perf_session *session = rep->session; | |
63503dba | 667 | struct evlist *evlist = session->evlist; |
d9fc7061 | 668 | char *help = NULL, *path = NULL; |
34b7b0f9 | 669 | |
d9fc7061 IR |
670 | path = system_path(TIPDIR); |
671 | if (perf_tip(&help, path) || help == NULL) { | |
34b7b0f9 | 672 | /* fallback for people who don't install perf ;-) */ |
d9fc7061 IR |
673 | free(path); |
674 | path = system_path(DOCDIR); | |
675 | if (perf_tip(&help, path) || help == NULL) | |
676 | help = strdup("Cannot load tips.txt file, please install perf!"); | |
34b7b0f9 | 677 | } |
d9fc7061 | 678 | free(path); |
8362951b ACM |
679 | |
680 | switch (use_browser) { | |
681 | case 1: | |
7fa46cbf | 682 | if (rep->total_cycles_mode) { |
f4bd0b4a | 683 | ret = evlist__tui_block_hists_browse(evlist, rep); |
7fa46cbf JY |
684 | break; |
685 | } | |
686 | ||
f4bd0b4a | 687 | ret = evlist__tui_browse_hists(evlist, help, NULL, rep->min_percent, |
22197fb2 | 688 | &session->header.env, true); |
8362951b ACM |
689 | /* |
690 | * Usually "ret" is the last pressed key, and we only | |
691 | * care if the key notifies us to switch data file. | |
692 | */ | |
5e3b810a | 693 | if (ret != K_SWITCH_INPUT_DATA && ret != K_RELOAD) |
8362951b ACM |
694 | ret = 0; |
695 | break; | |
696 | case 2: | |
697 | ret = report__gtk_browse_hists(rep, help); | |
698 | break; | |
699 | default: | |
f4bd0b4a | 700 | ret = evlist__tty_browse_hists(evlist, rep, help); |
8362951b ACM |
701 | break; |
702 | } | |
d9fc7061 | 703 | free(help); |
8362951b ACM |
704 | return ret; |
705 | } | |
706 | ||
5b2ea6f2 | 707 | static int report__collapse_hists(struct report *rep) |
f6d8b057 | 708 | { |
a6e4a4a1 NK |
709 | struct perf_session *session = rep->session; |
710 | struct evlist *evlist = session->evlist; | |
f6d8b057 | 711 | struct ui_progress prog; |
32dcd021 | 712 | struct evsel *pos; |
5b2ea6f2 | 713 | int ret = 0; |
f6d8b057 | 714 | |
a6e4a4a1 NK |
715 | /* |
716 | * The pipe data needs to setup hierarchy hpp formats now, because it | |
717 | * cannot know about evsels in the data before reading the data. The | |
718 | * normal file data saves the event (attribute) info in the header | |
719 | * section, but pipe does not have the luxury. | |
720 | */ | |
721 | if (perf_data__is_pipe(session->data)) { | |
722 | if (perf_hpp__setup_hists_formats(&perf_hpp_list, evlist) < 0) { | |
0e0f03d7 | 723 | ui__error("Failed to setup hierarchy output formats\n"); |
a6e4a4a1 NK |
724 | return -1; |
725 | } | |
726 | } | |
727 | ||
58c311da | 728 | ui_progress__init(&prog, rep->nr_entries, "Merging related events..."); |
f6d8b057 | 729 | |
e5cadb93 | 730 | evlist__for_each_entry(rep->session->evlist, pos) { |
4ea062ed | 731 | struct hists *hists = evsel__hists(pos); |
f6d8b057 | 732 | |
38fe0e01 | 733 | if (pos->core.idx == 0) |
f6d8b057 ACM |
734 | hists->symbol_filter_str = rep->symbol_filter_str; |
735 | ||
21394d94 KL |
736 | hists->socket_filter = rep->socket_filter; |
737 | ||
5b2ea6f2 NK |
738 | ret = hists__collapse_resort(hists, &prog); |
739 | if (ret < 0) | |
740 | break; | |
f6d8b057 ACM |
741 | |
742 | /* Non-group events are considered as leader */ | |
c754c382 | 743 | if (symbol_conf.event_group && !evsel__is_group_leader(pos)) { |
fba7c866 | 744 | struct hists *leader_hists = evsel__hists(evsel__leader(pos)); |
f6d8b057 ACM |
745 | |
746 | hists__match(leader_hists, hists); | |
747 | hists__link(leader_hists, hists); | |
748 | } | |
749 | } | |
750 | ||
751 | ui_progress__finish(); | |
5b2ea6f2 | 752 | return ret; |
f6d8b057 ACM |
753 | } |
754 | ||
dbd2a1d5 JO |
755 | static int hists__resort_cb(struct hist_entry *he, void *arg) |
756 | { | |
757 | struct report *rep = arg; | |
758 | struct symbol *sym = he->ms.sym; | |
759 | ||
760 | if (rep->symbol_ipc && sym && !sym->annotate2) { | |
32dcd021 | 761 | struct evsel *evsel = hists_to_evsel(he->hists); |
dbd2a1d5 | 762 | |
41fd3cac | 763 | symbol__annotate2(&he->ms, evsel, NULL); |
dbd2a1d5 JO |
764 | } |
765 | ||
766 | return 0; | |
767 | } | |
768 | ||
740b97f9 NK |
769 | static void report__output_resort(struct report *rep) |
770 | { | |
771 | struct ui_progress prog; | |
32dcd021 | 772 | struct evsel *pos; |
740b97f9 NK |
773 | |
774 | ui_progress__init(&prog, rep->nr_entries, "Sorting events for output..."); | |
775 | ||
dbd2a1d5 | 776 | evlist__for_each_entry(rep->session->evlist, pos) { |
10c513f7 | 777 | evsel__output_resort_cb(pos, &prog, hists__resort_cb, rep); |
dbd2a1d5 | 778 | } |
740b97f9 NK |
779 | |
780 | ui_progress__finish(); | |
781 | } | |
782 | ||
30f29bae | 783 | static int count_sample_event(const struct perf_tool *tool __maybe_unused, |
55f75444 NK |
784 | union perf_event *event __maybe_unused, |
785 | struct perf_sample *sample __maybe_unused, | |
786 | struct evsel *evsel, | |
787 | struct machine *machine __maybe_unused) | |
788 | { | |
789 | struct hists *hists = evsel__hists(evsel); | |
790 | ||
791 | hists__inc_nr_events(hists); | |
792 | return 0; | |
793 | } | |
794 | ||
30f29bae | 795 | static int count_lost_samples_event(const struct perf_tool *tool, |
d7ba22d4 NK |
796 | union perf_event *event, |
797 | struct perf_sample *sample, | |
798 | struct machine *machine __maybe_unused) | |
799 | { | |
800 | struct report *rep = container_of(tool, struct report, tool); | |
801 | struct evsel *evsel; | |
802 | ||
803 | evsel = evlist__id2evsel(rep->session->evlist, sample->id); | |
804 | if (evsel) { | |
1a5474a7 NK |
805 | struct hists *hists = evsel__hists(evsel); |
806 | u32 count = event->lost_samples.lost; | |
807 | ||
808 | if (event->header.misc & PERF_RECORD_MISC_LOST_SAMPLES_BPF) | |
809 | hists__inc_nr_dropped_samples(hists, count); | |
810 | else | |
811 | hists__inc_nr_lost_samples(hists, count); | |
d7ba22d4 NK |
812 | } |
813 | return 0; | |
814 | } | |
815 | ||
30f29bae | 816 | static int process_attr(const struct perf_tool *tool __maybe_unused, |
892ba7f1 NK |
817 | union perf_event *event, |
818 | struct evlist **pevlist); | |
819 | ||
a4a4d0a7 JO |
820 | static void stats_setup(struct report *rep) |
821 | { | |
113f614c | 822 | perf_tool__init(&rep->tool, /*ordered_events=*/false); |
892ba7f1 | 823 | rep->tool.attr = process_attr; |
55f75444 | 824 | rep->tool.sample = count_sample_event; |
d7ba22d4 | 825 | rep->tool.lost_samples = count_lost_samples_event; |
8b48f8ba | 826 | rep->tool.event_update = perf_event__process_event_update; |
a4a4d0a7 JO |
827 | rep->tool.no_warn = true; |
828 | } | |
829 | ||
830 | static int stats_print(struct report *rep) | |
831 | { | |
832 | struct perf_session *session = rep->session; | |
833 | ||
411ee135 NK |
834 | perf_session__fprintf_nr_events(session, stdout); |
835 | evlist__fprintf_nr_events(session->evlist, stdout); | |
a4a4d0a7 JO |
836 | return 0; |
837 | } | |
838 | ||
930f8b34 JO |
839 | static void tasks_setup(struct report *rep) |
840 | { | |
113f614c | 841 | perf_tool__init(&rep->tool, /*ordered_events=*/true); |
6439d7d1 ACM |
842 | if (rep->mmaps_mode) { |
843 | rep->tool.mmap = perf_event__process_mmap; | |
844 | rep->tool.mmap2 = perf_event__process_mmap2; | |
845 | } | |
892ba7f1 | 846 | rep->tool.attr = process_attr; |
930f8b34 JO |
847 | rep->tool.comm = perf_event__process_comm; |
848 | rep->tool.exit = perf_event__process_exit; | |
849 | rep->tool.fork = perf_event__process_fork; | |
850 | rep->tool.no_warn = true; | |
851 | } | |
852 | ||
431be14b IR |
853 | struct maps__fprintf_task_args { |
854 | int indent; | |
855 | FILE *fp; | |
856 | size_t printed; | |
857 | }; | |
858 | ||
859 | static int maps__fprintf_task_cb(struct map *map, void *data) | |
6439d7d1 | 860 | { |
431be14b IR |
861 | struct maps__fprintf_task_args *args = data; |
862 | const struct dso *dso = map__dso(map); | |
863 | u32 prot = map__prot(map); | |
864 | int ret; | |
ff583dc4 | 865 | |
431be14b IR |
866 | ret = fprintf(args->fp, |
867 | "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n", | |
868 | args->indent, "", map__start(map), map__end(map), | |
869 | prot & PROT_READ ? 'r' : '-', | |
870 | prot & PROT_WRITE ? 'w' : '-', | |
871 | prot & PROT_EXEC ? 'x' : '-', | |
872 | map__flags(map) ? 's' : 'p', | |
873 | map__pgoff(map), | |
ee756ef7 | 874 | dso__id_const(dso)->ino, dso__name(dso)); |
6439d7d1 | 875 | |
431be14b IR |
876 | if (ret < 0) |
877 | return ret; | |
878 | ||
879 | args->printed += ret; | |
880 | return 0; | |
881 | } | |
882 | ||
883 | static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp) | |
884 | { | |
885 | struct maps__fprintf_task_args args = { | |
886 | .indent = indent, | |
887 | .fp = fp, | |
888 | .printed = 0, | |
889 | }; | |
890 | ||
891 | maps__for_each_map(maps, maps__fprintf_task_cb, &args); | |
6439d7d1 | 892 | |
431be14b | 893 | return args.printed; |
6439d7d1 ACM |
894 | } |
895 | ||
2f1e20fe | 896 | static int thread_level(struct machine *machine, const struct thread *thread) |
930f8b34 | 897 | { |
2f1e20fe IR |
898 | struct thread *parent_thread; |
899 | int res; | |
6439d7d1 | 900 | |
2f1e20fe IR |
901 | if (thread__tid(thread) <= 0) |
902 | return 0; | |
930f8b34 | 903 | |
2f1e20fe IR |
904 | if (thread__ppid(thread) <= 0) |
905 | return 1; | |
930f8b34 | 906 | |
2f1e20fe IR |
907 | parent_thread = machine__find_thread(machine, -1, thread__ppid(thread)); |
908 | if (!parent_thread) { | |
909 | pr_err("Missing parent thread of %d\n", thread__tid(thread)); | |
910 | return 0; | |
930f8b34 | 911 | } |
2f1e20fe IR |
912 | res = 1 + thread_level(machine, parent_thread); |
913 | thread__put(parent_thread); | |
914 | return res; | |
930f8b34 JO |
915 | } |
916 | ||
2f1e20fe | 917 | static void task__print_level(struct machine *machine, struct thread *thread, FILE *fp) |
930f8b34 | 918 | { |
2f1e20fe IR |
919 | int level = thread_level(machine, thread); |
920 | int comm_indent = fprintf(fp, " %8d %8d %8d |%*s", | |
921 | thread__pid(thread), thread__tid(thread), | |
922 | thread__ppid(thread), level, ""); | |
930f8b34 | 923 | |
2f1e20fe | 924 | fprintf(fp, "%s\n", thread__comm_str(thread)); |
930f8b34 | 925 | |
2f1e20fe IR |
926 | maps__fprintf_task(thread__maps(thread), comm_indent, fp); |
927 | } | |
930f8b34 | 928 | |
2f1e20fe IR |
929 | /* |
930 | * Sort two thread list nodes such that they form a tree. The first node is the | |
931 | * root of the tree, its children are ordered numerically after it. If a child | |
932 | * has children itself then they appear immediately after their parent. For | |
933 | * example, the 4 threads in the order they'd appear in the list: | |
934 | * - init with a TID 1 and a parent of 0 | |
935 | * - systemd with a TID 3000 and a parent of init/1 | |
936 | * - systemd child thread with TID 4000, the parent is 3000 | |
937 | * - NetworkManager is a child of init with a TID of 3500. | |
938 | */ | |
939 | static int task_list_cmp(void *priv, const struct list_head *la, const struct list_head *lb) | |
940 | { | |
941 | struct machine *machine = priv; | |
942 | struct thread_list *task_a = list_entry(la, struct thread_list, list); | |
943 | struct thread_list *task_b = list_entry(lb, struct thread_list, list); | |
944 | struct thread *a = task_a->thread; | |
945 | struct thread *b = task_b->thread; | |
946 | int level_a, level_b, res; | |
947 | ||
948 | /* Same thread? */ | |
949 | if (thread__tid(a) == thread__tid(b)) | |
950 | return 0; | |
930f8b34 | 951 | |
2f1e20fe IR |
952 | /* Compare a and b to root. */ |
953 | if (thread__tid(a) == 0) | |
954 | return -1; | |
930f8b34 | 955 | |
2f1e20fe IR |
956 | if (thread__tid(b) == 0) |
957 | return 1; | |
930f8b34 | 958 | |
2f1e20fe IR |
959 | /* If parents match sort by tid. */ |
960 | if (thread__ppid(a) == thread__ppid(b)) | |
961 | return thread__tid(a) < thread__tid(b) ? -1 : 1; | |
930f8b34 JO |
962 | |
963 | /* | |
2f1e20fe IR |
964 | * Find a and b such that if they are a child of each other a and b's |
965 | * tid's match, otherwise a and b have a common parent and distinct | |
966 | * tid's to sort by. First make the depths of the threads match. | |
930f8b34 | 967 | */ |
2f1e20fe IR |
968 | level_a = thread_level(machine, a); |
969 | level_b = thread_level(machine, b); | |
970 | a = thread__get(a); | |
971 | b = thread__get(b); | |
972 | for (int i = level_a; i > level_b; i--) { | |
973 | struct thread *parent = machine__find_thread(machine, -1, thread__ppid(a)); | |
974 | ||
975 | thread__put(a); | |
976 | if (!parent) { | |
977 | pr_err("Missing parent thread of %d\n", thread__tid(a)); | |
978 | thread__put(b); | |
979 | return -1; | |
980 | } | |
981 | a = parent; | |
982 | } | |
983 | for (int i = level_b; i > level_a; i--) { | |
984 | struct thread *parent = machine__find_thread(machine, -1, thread__ppid(b)); | |
985 | ||
986 | thread__put(b); | |
987 | if (!parent) { | |
988 | pr_err("Missing parent thread of %d\n", thread__tid(b)); | |
989 | thread__put(a); | |
990 | return 1; | |
991 | } | |
992 | b = parent; | |
993 | } | |
994 | /* Search up to a common parent. */ | |
995 | while (thread__ppid(a) != thread__ppid(b)) { | |
996 | struct thread *parent; | |
997 | ||
998 | parent = machine__find_thread(machine, -1, thread__ppid(a)); | |
999 | thread__put(a); | |
1000 | if (!parent) | |
1001 | pr_err("Missing parent thread of %d\n", thread__tid(a)); | |
1002 | a = parent; | |
1003 | parent = machine__find_thread(machine, -1, thread__ppid(b)); | |
1004 | thread__put(b); | |
1005 | if (!parent) | |
1006 | pr_err("Missing parent thread of %d\n", thread__tid(b)); | |
1007 | b = parent; | |
1008 | if (!a || !b) { | |
1009 | /* Handle missing parent (unexpected) with some sanity. */ | |
1010 | thread__put(a); | |
1011 | thread__put(b); | |
1012 | return !a && !b ? 0 : (!a ? -1 : 1); | |
930f8b34 | 1013 | } |
930f8b34 | 1014 | } |
2f1e20fe IR |
1015 | if (thread__tid(a) == thread__tid(b)) { |
1016 | /* a is a child of b or vice-versa, deeper levels appear later. */ | |
1017 | res = level_a < level_b ? -1 : (level_a > level_b ? 1 : 0); | |
1018 | } else { | |
1019 | /* Sort by tid now the parent is the same. */ | |
1020 | res = thread__tid(a) < thread__tid(b) ? -1 : 1; | |
1021 | } | |
1022 | thread__put(a); | |
1023 | thread__put(b); | |
1024 | return res; | |
1025 | } | |
1026 | ||
1027 | static int tasks_print(struct report *rep, FILE *fp) | |
1028 | { | |
1029 | struct machine *machine = &rep->session->machines.host; | |
1030 | LIST_HEAD(tasks); | |
1031 | int ret; | |
930f8b34 | 1032 | |
2f1e20fe IR |
1033 | ret = machine__thread_list(machine, &tasks); |
1034 | if (!ret) { | |
1035 | struct thread_list *task; | |
930f8b34 | 1036 | |
2f1e20fe | 1037 | list_sort(machine, &tasks, task_list_cmp); |
930f8b34 | 1038 | |
2f1e20fe IR |
1039 | fprintf(fp, "# %8s %8s %8s %s\n", "pid", "tid", "ppid", "comm"); |
1040 | ||
1041 | list_for_each_entry(task, &tasks, list) | |
1042 | task__print_level(machine, task->thread, fp); | |
1043 | } | |
1044 | thread_list__delete(&tasks); | |
1045 | return ret; | |
930f8b34 JO |
1046 | } |
1047 | ||
28b21393 | 1048 | static int __cmd_report(struct report *rep) |
016e92fb | 1049 | { |
f6d8b057 | 1050 | int ret; |
993ac88d | 1051 | struct perf_session *session = rep->session; |
32dcd021 | 1052 | struct evsel *pos; |
8ceb41d7 | 1053 | struct perf_data *data = session->data; |
8fa66bdc | 1054 | |
46656ac7 TZ |
1055 | signal(SIGINT, sig_handler); |
1056 | ||
fa372aae ACM |
1057 | if (rep->cpu_list) { |
1058 | ret = perf_session__cpu_bitmap(session, rep->cpu_list, | |
1059 | rep->cpu_bitmap); | |
25b1606b NK |
1060 | if (ret) { |
1061 | ui__error("failed to set cpu bitmap\n"); | |
d4ae0a6f | 1062 | return ret; |
25b1606b | 1063 | } |
644e0840 | 1064 | session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap; |
5d67be97 AB |
1065 | } |
1066 | ||
89973506 ACM |
1067 | if (rep->show_threads) { |
1068 | ret = perf_read_values_init(&rep->show_threads_values); | |
1069 | if (ret) | |
1070 | return ret; | |
1071 | } | |
f5970550 | 1072 | |
28b21393 | 1073 | ret = report__setup_sample_type(rep); |
25b1606b NK |
1074 | if (ret) { |
1075 | /* report__setup_sample_type() already showed error message */ | |
d4ae0a6f | 1076 | return ret; |
25b1606b | 1077 | } |
d549c769 | 1078 | |
a4a4d0a7 JO |
1079 | if (rep->stats_mode) |
1080 | stats_setup(rep); | |
1081 | ||
930f8b34 JO |
1082 | if (rep->tasks_mode) |
1083 | tasks_setup(rep); | |
1084 | ||
b7b61cbe | 1085 | ret = perf_session__process_events(session); |
25b1606b NK |
1086 | if (ret) { |
1087 | ui__error("failed to process sample\n"); | |
d4ae0a6f | 1088 | return ret; |
25b1606b | 1089 | } |
97b07b69 | 1090 | |
2570c02c DV |
1091 | /* Don't show Latency column for non-parallel profiles by default. */ |
1092 | if (!symbol_conf.prefer_latency && rep->total_samples && | |
1093 | rep->singlethreaded_samples * 100 / rep->total_samples >= 99) | |
b09124e2 | 1094 | perf_hpp__cancel_latency(session->evlist); |
2570c02c | 1095 | |
d5a8bd0f JY |
1096 | evlist__check_mem_load_aux(session->evlist); |
1097 | ||
a4a4d0a7 JO |
1098 | if (rep->stats_mode) |
1099 | return stats_print(rep); | |
1100 | ||
930f8b34 JO |
1101 | if (rep->tasks_mode) |
1102 | return tasks_print(rep, stdout); | |
1103 | ||
fad2918e | 1104 | report__warn_kptr_restrict(rep); |
ec80fde7 | 1105 | |
e5cadb93 | 1106 | evlist__for_each_entry(session->evlist, pos) |
590cd344 NK |
1107 | rep->nr_entries += evsel__hists(pos)->nr_entries; |
1108 | ||
150e465a NK |
1109 | if (use_browser == 0) { |
1110 | if (verbose > 3) | |
1111 | perf_session__fprintf(session, stdout); | |
9ac99545 | 1112 | |
150e465a NK |
1113 | if (verbose > 2) |
1114 | perf_session__fprintf_dsos(session, stdout); | |
16f762a2 | 1115 | |
150e465a | 1116 | if (dump_trace) { |
2eae307e | 1117 | stats_print(rep); |
150e465a NK |
1118 | return 0; |
1119 | } | |
71ad0f5e JO |
1120 | } |
1121 | ||
5b2ea6f2 NK |
1122 | ret = report__collapse_hists(rep); |
1123 | if (ret) { | |
1124 | ui__error("failed to process hist entry\n"); | |
1125 | return ret; | |
1126 | } | |
e248de33 | 1127 | |
33e940a2 ACM |
1128 | if (session_done()) |
1129 | return 0; | |
1130 | ||
740b97f9 NK |
1131 | /* |
1132 | * recalculate number of entries after collapsing since it | |
1133 | * might be changed during the collapse phase. | |
1134 | */ | |
1135 | rep->nr_entries = 0; | |
e5cadb93 | 1136 | evlist__for_each_entry(session->evlist, pos) |
740b97f9 NK |
1137 | rep->nr_entries += evsel__hists(pos)->nr_entries; |
1138 | ||
58c311da | 1139 | if (rep->nr_entries == 0) { |
2d4f2799 | 1140 | ui__error("The %s data has no samples!\n", data->path); |
d4ae0a6f | 1141 | return 0; |
cbbc79a5 EM |
1142 | } |
1143 | ||
740b97f9 | 1144 | report__output_resort(rep); |
6e1f601a | 1145 | |
6f7164fa | 1146 | if (rep->total_cycles_mode) { |
20d6f555 KL |
1147 | int nr_hpps = 4; |
1148 | int block_hpps[PERF_HPP_REPORT__BLOCK_MAX_INDEX] = { | |
cca0cc76 JY |
1149 | PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT, |
1150 | PERF_HPP_REPORT__BLOCK_LBR_CYCLES, | |
1151 | PERF_HPP_REPORT__BLOCK_CYCLES_PCT, | |
1152 | PERF_HPP_REPORT__BLOCK_AVG_CYCLES, | |
cca0cc76 JY |
1153 | }; |
1154 | ||
20d6f555 KL |
1155 | if (session->evlist->nr_br_cntr > 0) |
1156 | block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_BRANCH_COUNTER; | |
1157 | ||
1158 | block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_RANGE; | |
1159 | block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_DSO; | |
1160 | ||
6f7164fa | 1161 | rep->block_reports = block_info__create_report(session->evlist, |
cca0cc76 | 1162 | rep->total_cycles, |
20d6f555 | 1163 | block_hpps, nr_hpps, |
cca0cc76 | 1164 | &rep->nr_block_reports); |
6f7164fa JY |
1165 | if (!rep->block_reports) |
1166 | return -1; | |
1167 | } | |
1168 | ||
8362951b | 1169 | return report__browse_hists(rep); |
8fa66bdc ACM |
1170 | } |
1171 | ||
4eb3e478 | 1172 | static int |
cff6bb46 | 1173 | report_parse_callchain_opt(const struct option *opt, const char *arg, int unset) |
4eb3e478 | 1174 | { |
1cc83815 | 1175 | struct callchain_param *callchain = opt->value; |
c20ab37e | 1176 | |
1cc83815 | 1177 | callchain->enabled = !unset; |
b9a63b9b ACM |
1178 | /* |
1179 | * --no-call-graph | |
1180 | */ | |
1181 | if (unset) { | |
1cc83815 ACM |
1182 | symbol_conf.use_callchain = false; |
1183 | callchain->mode = CHAIN_NONE; | |
b9a63b9b ACM |
1184 | return 0; |
1185 | } | |
1186 | ||
cff6bb46 | 1187 | return parse_callchain_report_opt(arg); |
4eb3e478 FW |
1188 | } |
1189 | ||
2a1292cb AK |
1190 | static int |
1191 | parse_time_quantum(const struct option *opt, const char *arg, | |
1192 | int unset __maybe_unused) | |
1193 | { | |
1194 | unsigned long *time_q = opt->value; | |
1195 | char *end; | |
1196 | ||
1197 | *time_q = strtoul(arg, &end, 0); | |
1198 | if (end == arg) | |
1199 | goto parse_err; | |
1200 | if (*time_q == 0) { | |
1201 | pr_err("time quantum cannot be 0"); | |
1202 | return -1; | |
1203 | } | |
526bbbdd | 1204 | end = skip_spaces(end); |
2a1292cb AK |
1205 | if (*end == 0) |
1206 | return 0; | |
1207 | if (!strcmp(end, "s")) { | |
1208 | *time_q *= NSEC_PER_SEC; | |
1209 | return 0; | |
1210 | } | |
1211 | if (!strcmp(end, "ms")) { | |
1212 | *time_q *= NSEC_PER_MSEC; | |
1213 | return 0; | |
1214 | } | |
1215 | if (!strcmp(end, "us")) { | |
1216 | *time_q *= NSEC_PER_USEC; | |
1217 | return 0; | |
1218 | } | |
1219 | if (!strcmp(end, "ns")) | |
1220 | return 0; | |
1221 | parse_err: | |
1222 | pr_err("Cannot parse time quantum `%s'\n", arg); | |
1223 | return -1; | |
1224 | } | |
1225 | ||
b21484f1 GP |
1226 | int |
1227 | report_parse_ignore_callees_opt(const struct option *opt __maybe_unused, | |
1228 | const char *arg, int unset __maybe_unused) | |
1229 | { | |
1230 | if (arg) { | |
1231 | int err = regcomp(&ignore_callees_regex, arg, REG_EXTENDED); | |
1232 | if (err) { | |
1233 | char buf[BUFSIZ]; | |
1234 | regerror(err, &ignore_callees_regex, buf, sizeof(buf)); | |
1235 | pr_err("Invalid --ignore-callees regex: %s\n%s", arg, buf); | |
1236 | return -1; | |
1237 | } | |
1238 | have_ignore_callees = 1; | |
1239 | } | |
1240 | ||
1241 | return 0; | |
1242 | } | |
1243 | ||
993ac88d | 1244 | static int |
7e6a7998 | 1245 | parse_branch_mode(const struct option *opt, |
1d037ca1 | 1246 | const char *str __maybe_unused, int unset) |
993ac88d | 1247 | { |
55369fc1 NK |
1248 | int *branch_mode = opt->value; |
1249 | ||
1250 | *branch_mode = !unset; | |
993ac88d SE |
1251 | return 0; |
1252 | } | |
1253 | ||
064f1981 NK |
1254 | static int |
1255 | parse_percent_limit(const struct option *opt, const char *str, | |
1256 | int unset __maybe_unused) | |
1257 | { | |
28b21393 | 1258 | struct report *rep = opt->value; |
2665b452 | 1259 | double pcnt = strtof(str, NULL); |
064f1981 | 1260 | |
2665b452 NK |
1261 | rep->min_percent = pcnt; |
1262 | callchain_param.min_percent = pcnt; | |
064f1981 NK |
1263 | return 0; |
1264 | } | |
1265 | ||
30f29bae | 1266 | static int process_attr(const struct perf_tool *tool __maybe_unused, |
0d71a2b2 JO |
1267 | union perf_event *event, |
1268 | struct evlist **pevlist) | |
1269 | { | |
1270 | u64 sample_type; | |
1271 | int err; | |
1272 | ||
1273 | err = perf_event__process_attr(tool, event, pevlist); | |
1274 | if (err) | |
1275 | return err; | |
1276 | ||
1277 | /* | |
1278 | * Check if we need to enable callchains based | |
1279 | * on events sample_type. | |
1280 | */ | |
b3c2cc2b | 1281 | sample_type = evlist__combined_sample_type(*pevlist); |
aa8db3e4 | 1282 | callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env)); |
0d71a2b2 JO |
1283 | return 0; |
1284 | } | |
1285 | ||
48966a5a TF |
1286 | #define CALLCHAIN_BRANCH_SORT_ORDER \ |
1287 | "srcline,symbol,dso,callchain_branch_predicted," \ | |
1288 | "callchain_branch_abort,callchain_branch_cycles" | |
1289 | ||
b0ad8ea6 | 1290 | int cmd_report(int argc, const char **argv) |
d20deb64 | 1291 | { |
993ac88d | 1292 | struct perf_session *session; |
520a2ebc | 1293 | struct itrace_synth_opts itrace_synth_opts = { .set = 0, }; |
efad1415 | 1294 | struct stat st; |
993ac88d | 1295 | bool has_br_stack = false; |
55369fc1 | 1296 | int branch_mode = -1; |
0feba17b | 1297 | int last_key = 0; |
fa94c36c | 1298 | bool branch_call_mode = false; |
9d0199cd | 1299 | #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent" |
49b8e2be RV |
1300 | static const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n" |
1301 | CALLCHAIN_REPORT_HELP | |
1302 | "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT; | |
76a26549 | 1303 | char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT; |
d20deb64 | 1304 | const char * const report_usage[] = { |
fb2baceb | 1305 | "perf report [<options>]", |
d20deb64 ACM |
1306 | NULL |
1307 | }; | |
28b21393 | 1308 | struct report report = { |
fe176085 | 1309 | .max_stack = PERF_MAX_STACK_DEPTH, |
d20deb64 | 1310 | .pretty_printing_style = "normal", |
21394d94 | 1311 | .socket_filter = -1, |
8f08cf33 | 1312 | .skip_empty = true, |
d20deb64 | 1313 | }; |
871893d7 NK |
1314 | char *sort_order_help = sort_help("sort by key(s):", SORT_MODE__NORMAL); |
1315 | char *field_order_help = sort_help("output field(s):", SORT_MODE__NORMAL); | |
57594454 | 1316 | const char *disassembler_style = NULL, *objdump_path = NULL, *addr2line_path = NULL; |
d20deb64 | 1317 | const struct option options[] = { |
70cb4e96 | 1318 | OPT_STRING('i', "input", &input_name, "file", |
53cb8bc2 | 1319 | "input file name"), |
c0555642 | 1320 | OPT_INCR('v', "verbose", &verbose, |
815e777f | 1321 | "be more verbose (show symbol address, etc)"), |
a527c2c1 | 1322 | OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"), |
97b07b69 IM |
1323 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1324 | "dump raw trace in ASCII"), | |
a4a4d0a7 | 1325 | OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"), |
930f8b34 | 1326 | OPT_BOOLEAN(0, "tasks", &report.tasks_mode, "Display recorded tasks"), |
6439d7d1 | 1327 | OPT_BOOLEAN(0, "mmaps", &report.mmaps_mode, "Display recorded tasks memory maps"), |
b32d133a ACM |
1328 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
1329 | "file", "vmlinux pathname"), | |
91340c51 ACM |
1330 | OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux, |
1331 | "don't load vmlinux even if found"), | |
b226a5a7 DA |
1332 | OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, |
1333 | "file", "kallsyms pathname"), | |
2059fc7a | 1334 | OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), |
b32d133a | 1335 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
42976487 | 1336 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
d599db3f | 1337 | OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, |
e3d7e183 | 1338 | "Show a column with the number of samples"), |
fa372aae | 1339 | OPT_BOOLEAN('T', "threads", &report.show_threads, |
8d513270 | 1340 | "Show per-thread event counters"), |
fa372aae | 1341 | OPT_STRING(0, "pretty", &report.pretty_printing_style, "key", |
9f866697 | 1342 | "pretty printing style key: normal raw"), |
3402ae0a | 1343 | #ifdef HAVE_SLANG_SUPPORT |
fa372aae | 1344 | OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"), |
3402ae0a | 1345 | #endif |
557cc18e | 1346 | #ifdef HAVE_GTK2_SUPPORT |
c31a9457 | 1347 | OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"), |
557cc18e | 1348 | #endif |
fa372aae ACM |
1349 | OPT_BOOLEAN(0, "stdio", &report.use_stdio, |
1350 | "Use the stdio interface"), | |
5cfe2c82 JO |
1351 | OPT_BOOLEAN(0, "header", &report.header, "Show data header."), |
1352 | OPT_BOOLEAN(0, "header-only", &report.header_only, | |
1353 | "Show only data header."), | |
63299f05 | 1354 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
a37338aa | 1355 | sort_order_help), |
a7d945bc | 1356 | OPT_STRING('F', "fields", &field_order, "key[,keys...]", |
a37338aa | 1357 | field_order_help), |
b272a59d | 1358 | OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization, |
a1645ce1 | 1359 | "Show sample percentage for different cpu modes"), |
b272a59d NK |
1360 | OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, |
1361 | "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN), | |
b25bcf2f IM |
1362 | OPT_STRING('p', "parent", &parent_pattern, "regex", |
1363 | "regex filter to identify parent, see: '--sort parent'"), | |
d599db3f | 1364 | OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other, |
b8e6d829 | 1365 | "Only display entries with parent-match"), |
1cc83815 | 1366 | OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param, |
f2af0086 | 1367 | "print_type,threshold[,print_limit],order,sort_key[,branch],value", |
21cf6284 NK |
1368 | report_callchain_help, &report_parse_callchain_opt, |
1369 | callchain_default_opt), | |
793aaaab | 1370 | OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain, |
aa9d1f83 AK |
1371 | "Accumulate callchains of children and show total overhead as well. " |
1372 | "Enabled by default, use --no-children to disable."), | |
91e95617 WL |
1373 | OPT_INTEGER(0, "max-stack", &report.max_stack, |
1374 | "Set the maximum stack depth when parsing the callchain, " | |
1375 | "anything beyond the specified depth will be ignored. " | |
4cb93446 | 1376 | "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), |
fa372aae ACM |
1377 | OPT_BOOLEAN('G', "inverted", &report.inverted_callchain, |
1378 | "alias for inverted call graph"), | |
b21484f1 GP |
1379 | OPT_CALLBACK(0, "ignore-callees", NULL, "regex", |
1380 | "ignore callees of these functions in call graphs", | |
1381 | report_parse_ignore_callees_opt), | |
655000e7 | 1382 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
25903407 | 1383 | "only consider symbols in these dsos"), |
c8e66720 | 1384 | OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", |
cc8b88b1 | 1385 | "only consider symbols in these comms"), |
e03eaa40 DA |
1386 | OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]", |
1387 | "only consider symbols in these pids"), | |
1388 | OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", | |
1389 | "only consider symbols in these tids"), | |
655000e7 | 1390 | OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", |
7bec7a91 | 1391 | "only consider these symbols"), |
b14ffaca NK |
1392 | OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter", |
1393 | "only show symbols that (partially) match with this filter"), | |
655000e7 | 1394 | OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str, |
52d422de ACM |
1395 | "width[,width...]", |
1396 | "don't try to adjust column width, use these fixed values"), | |
0c8c2077 | 1397 | OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator", |
52d422de ACM |
1398 | "separator for columns, no spaces will be added between " |
1399 | "columns '.' is reserved."), | |
b49a8fe5 | 1400 | OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved, |
71289be7 | 1401 | "Only display entries resolved to a symbol"), |
a7066709 HK |
1402 | OPT_CALLBACK(0, "symfs", NULL, "directory", |
1403 | "Look for files with symbols relative to this directory", | |
1404 | symbol__config_symfs), | |
c8e66720 | 1405 | OPT_STRING('C', "cpu", &report.cpu_list, "cpu", |
fa372aae | 1406 | "list of cpus to profile"), |
61b6b31c DV |
1407 | OPT_STRING(0, "parallelism", &symbol_conf.parallelism_list_str, "parallelism", |
1408 | "only consider these parallelism levels (cpu set format)"), | |
fa372aae | 1409 | OPT_BOOLEAN('I', "show-info", &report.show_full_info, |
fbe96f29 | 1410 | "Display extended information about perf.data file"), |
14953f03 | 1411 | OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src, |
64c6f0c7 | 1412 | "Interleave source code with assembly code (default)"), |
14953f03 | 1413 | OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw, |
64c6f0c7 | 1414 | "Display raw encoding of assembly instructions (default)"), |
56d9117c | 1415 | OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", |
f69b64f7 | 1416 | "Specify disassembler style (e.g. -M intel for intel syntax)"), |
14953f03 | 1417 | OPT_STRING(0, "prefix", &annotate_opts.prefix, "prefix", |
3b0b16bf | 1418 | "Add prefix to source file path names in programs (with --prefix-strip)"), |
14953f03 | 1419 | OPT_STRING(0, "prefix-strip", &annotate_opts.prefix_strip, "N", |
3b0b16bf | 1420 | "Strip first N entries of source file path name in programs (with --prefix)"), |
3f2728bd ACM |
1421 | OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period, |
1422 | "Show a column with the sum of periods"), | |
57b5de46 | 1423 | OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set, |
01d14f16 | 1424 | "Show event group information together"), |
429a5f9d JY |
1425 | OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx, |
1426 | "Sort the output by the event at the index n in group. " | |
1427 | "If n is invalid, sort by the first event. " | |
1428 | "WARNING: should be used on grouped events."), | |
55369fc1 | 1429 | OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "", |
fa94c36c AK |
1430 | "use branch records for per branch histogram filling", |
1431 | parse_branch_mode), | |
1432 | OPT_BOOLEAN(0, "branch-history", &branch_call_mode, | |
1433 | "add last branch records to call history"), | |
56d9117c | 1434 | OPT_STRING(0, "objdump", &objdump_path, "path", |
7a4ec938 | 1435 | "objdump binary to use for disassembly and annotations"), |
57594454 IR |
1436 | OPT_STRING(0, "addr2line", &addr2line_path, "path", |
1437 | "addr2line binary to use for line numbers"), | |
328ccdac | 1438 | OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, |
ac0ac751 | 1439 | "Symbol demangling. Enabled by default, use --no-demangle to disable."), |
763122ad AK |
1440 | OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, |
1441 | "Enable kernel symbol demangling"), | |
f4f7e28d | 1442 | OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"), |
4968ac8f AK |
1443 | OPT_INTEGER(0, "samples", &symbol_conf.res_sample, |
1444 | "Number of samples to save per histogram entry for individual browsing"), | |
064f1981 NK |
1445 | OPT_CALLBACK(0, "percent-limit", &report, "percent", |
1446 | "Don't show entries under that percent", parse_percent_limit), | |
f2148330 | 1447 | OPT_CALLBACK(0, "percentage", NULL, "relative|absolute", |
33db4568 | 1448 | "how to display percentage of filtered entries", parse_filter_percentage), |
520a2ebc | 1449 | OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", |
c12e039d | 1450 | "Instruction Tracing options\n" ITRACE_HELP, |
520a2ebc | 1451 | itrace_parse_synth_opts), |
a9710ba0 AK |
1452 | OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename, |
1453 | "Show full source file name path for source lines"), | |
9e207ddf KL |
1454 | OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph, |
1455 | "Show callgraph from reference event"), | |
b1d1429b KL |
1456 | OPT_BOOLEAN(0, "stitch-lbr", &report.stitch_lbr, |
1457 | "Enable LBR callgraph stitching approach"), | |
21394d94 KL |
1458 | OPT_INTEGER(0, "socket-filter", &report.socket_filter, |
1459 | "only show processor socket that match with this filter"), | |
053a3989 NK |
1460 | OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace, |
1461 | "Show raw trace event output (do not use print fmt or plugins)"), | |
7727d59d | 1462 | OPT_BOOLEAN('H', "hierarchy", &symbol_conf.report_hierarchy, |
4251446d | 1463 | "Show entries in a hierarchy"), |
175b968b ACM |
1464 | OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode", |
1465 | "'always' (default), 'never' or 'auto' only applicable to --stdio mode", | |
1466 | stdio__config_color, "always"), | |
46690a80 DA |
1467 | OPT_STRING(0, "time", &report.time_str, "str", |
1468 | "Time span of interest (start,stop)"), | |
f3a60646 JY |
1469 | OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name, |
1470 | "Show inline function"), | |
14953f03 | 1471 | OPT_CALLBACK(0, "percent-type", &annotate_opts, "local-period", |
e6902d1b JO |
1472 | "Set percent type local/global-period/hits", |
1473 | annotate_parse_percent_type), | |
52bab886 | 1474 | OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, "Show times in nanosecs"), |
2a1292cb AK |
1475 | OPT_CALLBACK(0, "time-quantum", &symbol_conf.time_quantum, "time (ms|us|ns|s)", |
1476 | "Set time quantum for time sort key (default 100ms)", | |
1477 | parse_time_quantum), | |
ef4b1a53 | 1478 | OPTS_EVSWITCH(&report.evswitch), |
6f7164fa JY |
1479 | OPT_BOOLEAN(0, "total-cycles", &report.total_cycles_mode, |
1480 | "Sort all blocks by 'Sampled Cycles%'"), | |
2e989f82 JY |
1481 | OPT_BOOLEAN(0, "disable-order", &report.disable_order, |
1482 | "Disable raw trace ordering"), | |
2775de0b NK |
1483 | OPT_BOOLEAN(0, "skip-empty", &report.skip_empty, |
1484 | "Do not display empty (or dummy) events in the output"), | |
2570c02c DV |
1485 | OPT_BOOLEAN(0, "latency", &symbol_conf.prefer_latency, |
1486 | "Show latency-centric profile rather than the default\n" | |
1487 | "\t\t\t CPU-consumption-centric profile\n" | |
1488 | "\t\t\t (requires perf record --latency flag)."), | |
53cb8bc2 | 1489 | OPT_END() |
d20deb64 | 1490 | }; |
8ceb41d7 | 1491 | struct perf_data data = { |
f5fc1412 JO |
1492 | .mode = PERF_DATA_MODE_READ, |
1493 | }; | |
a635fc51 | 1494 | int ret = hists__init(); |
ec6ae74f | 1495 | char sort_tmp[128]; |
113f614c | 1496 | bool ordered_events = true; |
a635fc51 ACM |
1497 | |
1498 | if (ret < 0) | |
a37338aa | 1499 | goto exit; |
53cb8bc2 | 1500 | |
9ffa6c75 IR |
1501 | /* |
1502 | * tasks_mode require access to exited threads to list those that are in | |
1503 | * the data file. Off-cpu events are synthesized after other events and | |
1504 | * reference exited threads. | |
1505 | */ | |
1506 | symbol_conf.keep_exited_threads = true; | |
1507 | ||
7f929aea | 1508 | annotation_options__init(); |
217b7d41 | 1509 | |
ecc4c561 ACM |
1510 | ret = perf_config(report__config, &report); |
1511 | if (ret) | |
a37338aa | 1512 | goto exit; |
00c7e1f1 | 1513 | |
655000e7 | 1514 | argc = parse_options(argc, argv, options, report_usage, 0); |
b3f38fc2 NK |
1515 | if (argc) { |
1516 | /* | |
1517 | * Special case: if there's an argument left then assume that | |
1518 | * it's a symbol filter: | |
1519 | */ | |
1520 | if (argc > 1) | |
1521 | usage_with_options(report_usage, options); | |
1522 | ||
1523 | report.symbol_filter_str = argv[0]; | |
1524 | } | |
655000e7 | 1525 | |
56d9117c | 1526 | if (disassembler_style) { |
14953f03 NK |
1527 | annotate_opts.disassembler_style = strdup(disassembler_style); |
1528 | if (!annotate_opts.disassembler_style) | |
56d9117c IR |
1529 | return -ENOMEM; |
1530 | } | |
1531 | if (objdump_path) { | |
14953f03 NK |
1532 | annotate_opts.objdump_path = strdup(objdump_path); |
1533 | if (!annotate_opts.objdump_path) | |
56d9117c IR |
1534 | return -ENOMEM; |
1535 | } | |
57594454 IR |
1536 | if (addr2line_path) { |
1537 | symbol_conf.addr2line_path = strdup(addr2line_path); | |
1538 | if (!symbol_conf.addr2line_path) | |
1539 | return -ENOMEM; | |
1540 | } | |
56d9117c | 1541 | |
7f929aea | 1542 | if (annotate_check_args() < 0) { |
a37338aa RM |
1543 | ret = -EINVAL; |
1544 | goto exit; | |
1545 | } | |
3b0b16bf | 1546 | |
6439d7d1 ACM |
1547 | if (report.mmaps_mode) |
1548 | report.tasks_mode = true; | |
1549 | ||
2e989f82 | 1550 | if (dump_trace && report.disable_order) |
113f614c | 1551 | ordered_events = false; |
977f739b | 1552 | |
27fafab5 NK |
1553 | if (quiet) |
1554 | perf_quiet_option(); | |
1555 | ||
a3df50ab JC |
1556 | ret = symbol__validate_sym_arguments(); |
1557 | if (ret) | |
a37338aa | 1558 | goto exit; |
36c8bb56 | 1559 | |
fa372aae | 1560 | if (report.inverted_callchain) |
d797fdc5 | 1561 | callchain_param.order = ORDER_CALLER; |
792aeafa NK |
1562 | if (symbol_conf.cumulate_callchain && !callchain_param.order_set) |
1563 | callchain_param.order = ORDER_CALLER; | |
d797fdc5 | 1564 | |
1c5c25b3 | 1565 | if ((itrace_synth_opts.callchain || itrace_synth_opts.add_callchain) && |
188bb5e2 AH |
1566 | (int)itrace_synth_opts.callchain_sz > report.max_stack) |
1567 | report.max_stack = itrace_synth_opts.callchain_sz; | |
1568 | ||
70cb4e96 | 1569 | if (!input_name || !strlen(input_name)) { |
efad1415 | 1570 | if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) |
70cb4e96 | 1571 | input_name = "-"; |
efad1415 | 1572 | else |
70cb4e96 | 1573 | input_name = "perf.data"; |
efad1415 | 1574 | } |
ad0de097 | 1575 | |
43c2b613 | 1576 | repeat: |
2d4f2799 JO |
1577 | data.path = input_name; |
1578 | data.force = symbol_conf.force; | |
f5fc1412 | 1579 | |
411ee135 NK |
1580 | symbol_conf.skip_empty = report.skip_empty; |
1581 | ||
113f614c IR |
1582 | perf_tool__init(&report.tool, ordered_events); |
1583 | report.tool.sample = process_sample_event; | |
1584 | report.tool.mmap = perf_event__process_mmap; | |
1585 | report.tool.mmap2 = perf_event__process_mmap2; | |
1586 | report.tool.comm = perf_event__process_comm; | |
1587 | report.tool.namespaces = perf_event__process_namespaces; | |
1588 | report.tool.cgroup = perf_event__process_cgroup; | |
1589 | report.tool.exit = perf_event__process_exit; | |
1590 | report.tool.fork = perf_event__process_fork; | |
f13bc61b | 1591 | report.tool.context_switch = perf_event__process_switch; |
113f614c IR |
1592 | report.tool.lost = perf_event__process_lost; |
1593 | report.tool.read = process_read_event; | |
1594 | report.tool.attr = process_attr; | |
1595 | #ifdef HAVE_LIBTRACEEVENT | |
1596 | report.tool.tracing_data = perf_event__process_tracing_data; | |
1597 | #endif | |
1598 | report.tool.build_id = perf_event__process_build_id; | |
1599 | report.tool.id_index = perf_event__process_id_index; | |
1600 | report.tool.auxtrace_info = perf_event__process_auxtrace_info; | |
1601 | report.tool.auxtrace = perf_event__process_auxtrace; | |
1602 | report.tool.event_update = perf_event__process_event_update; | |
1603 | report.tool.feature = process_feature_event; | |
1604 | report.tool.ordering_requires_timestamps = true; | |
1605 | ||
2681bd85 | 1606 | session = perf_session__new(&data, &report.tool); |
a37338aa RM |
1607 | if (IS_ERR(session)) { |
1608 | ret = PTR_ERR(session); | |
1609 | goto exit; | |
1610 | } | |
993ac88d | 1611 | |
ef4b1a53 ACM |
1612 | ret = evswitch__init(&report.evswitch, session->evlist, stderr); |
1613 | if (ret) | |
a37338aa | 1614 | goto exit; |
ef4b1a53 | 1615 | |
cb62c6f1 AB |
1616 | if (zstd_init(&(session->zstd_data), 0) < 0) |
1617 | pr_warning("Decompression initialization failed. Reported data may be incomplete.\n"); | |
1618 | ||
94786b67 JO |
1619 | if (report.queue_size) { |
1620 | ordered_events__set_alloc_size(&session->ordered_events, | |
1621 | report.queue_size); | |
1622 | } | |
1623 | ||
520a2ebc AH |
1624 | session->itrace_synth_opts = &itrace_synth_opts; |
1625 | ||
993ac88d SE |
1626 | report.session = session; |
1627 | ||
1628 | has_br_stack = perf_header__has_feat(&session->header, | |
1629 | HEADER_BRANCH_STACK); | |
b3c2cc2b | 1630 | if (evlist__combined_sample_type(session->evlist) & PERF_SAMPLE_STACK_USER) |
10ccbc1c | 1631 | has_br_stack = false; |
efad1415 | 1632 | |
57b5de46 | 1633 | setup_forced_leader(&report, session->evlist); |
ad52b8cb | 1634 | |
9d2dc632 | 1635 | if (symbol_conf.group_sort_idx && evlist__nr_groups(session->evlist) == 0) { |
429a5f9d JY |
1636 | parse_options_usage(NULL, options, "group-sort-idx", 0); |
1637 | ret = -EINVAL; | |
1638 | goto error; | |
1639 | } | |
1640 | ||
ec90e42c | 1641 | if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch) |
fb9fab66 AH |
1642 | has_br_stack = true; |
1643 | ||
f9a7be7c JY |
1644 | if (has_br_stack && branch_call_mode) |
1645 | symbol_conf.show_branchflag_count = true; | |
1646 | ||
2d78b189 JY |
1647 | memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat)); |
1648 | ||
fa94c36c AK |
1649 | /* |
1650 | * Branch mode is a tristate: | |
1651 | * -1 means default, so decide based on the file having branch data. | |
1652 | * 0/1 means the user chose a mode. | |
1653 | */ | |
1654 | if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) && | |
fefd2d96 | 1655 | !branch_call_mode) { |
55369fc1 | 1656 | sort__mode = SORT_MODE__BRANCH; |
793aaaab NK |
1657 | symbol_conf.cumulate_callchain = false; |
1658 | } | |
fa94c36c | 1659 | if (branch_call_mode) { |
09a6a1b0 | 1660 | callchain_param.key = CCKEY_ADDRESS; |
6fa9c3e7 | 1661 | callchain_param.branch_callstack = true; |
fa94c36c AK |
1662 | symbol_conf.use_callchain = true; |
1663 | callchain_register_param(&callchain_param); | |
1664 | if (sort_order == NULL) | |
48966a5a | 1665 | sort_order = CALLCHAIN_BRANCH_SORT_ORDER; |
fa94c36c | 1666 | } |
993ac88d | 1667 | |
f4f7e28d | 1668 | if (report.mem_mode) { |
55369fc1 | 1669 | if (sort__mode == SORT_MODE__BRANCH) { |
a4210141 | 1670 | pr_err("branch and mem mode incompatible\n"); |
f4f7e28d SE |
1671 | goto error; |
1672 | } | |
afab87b9 | 1673 | sort__mode = SORT_MODE__MEMORY; |
793aaaab | 1674 | symbol_conf.cumulate_callchain = false; |
f4f7e28d | 1675 | } |
a68c2c58 | 1676 | |
4251446d | 1677 | if (symbol_conf.report_hierarchy) { |
0ef8091f NK |
1678 | /* |
1679 | * The hist entries in hierarchy are added during the collpase | |
1680 | * phase. Let's enable it even if no sort keys require it. | |
1681 | */ | |
52225036 | 1682 | perf_hpp_list.need_collapse = true; |
4251446d NK |
1683 | } |
1684 | ||
712d36db SS |
1685 | if (report.use_stdio) |
1686 | use_browser = 0; | |
3402ae0a | 1687 | #ifdef HAVE_SLANG_SUPPORT |
712d36db SS |
1688 | else if (report.use_tui) |
1689 | use_browser = 1; | |
3402ae0a | 1690 | #endif |
557cc18e | 1691 | #ifdef HAVE_GTK2_SUPPORT |
712d36db SS |
1692 | else if (report.use_gtk) |
1693 | use_browser = 2; | |
557cc18e | 1694 | #endif |
712d36db | 1695 | |
b138f42e NK |
1696 | /* Force tty output for header output and per-thread stat. */ |
1697 | if (report.header || report.header_only || report.show_threads) | |
5cfe2c82 | 1698 | use_browser = 0; |
114f709e DCC |
1699 | if (report.header || report.header_only) |
1700 | report.tool.show_feat_hdr = SHOW_FEAT_HEADER; | |
1701 | if (report.show_full_info) | |
1702 | report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO; | |
930f8b34 | 1703 | if (report.stats_mode || report.tasks_mode) |
a4a4d0a7 | 1704 | use_browser = 0; |
930f8b34 | 1705 | if (report.stats_mode && report.tasks_mode) { |
6439d7d1 | 1706 | pr_err("Error: --tasks and --mmaps can't be used together with --stats\n"); |
930f8b34 JO |
1707 | goto error; |
1708 | } | |
5cfe2c82 | 1709 | |
6f7164fa JY |
1710 | if (report.total_cycles_mode) { |
1711 | if (sort__mode != SORT_MODE__BRANCH) | |
1712 | report.total_cycles_mode = false; | |
7fa46cbf | 1713 | else |
848a5e50 | 1714 | sort_order = NULL; |
6f7164fa JY |
1715 | } |
1716 | ||
81e57dee NK |
1717 | if (sort_order && strstr(sort_order, "type")) { |
1718 | report.data_type = true; | |
1719 | annotate_opts.annotate_src = false; | |
1720 | ||
d10a7aaa NK |
1721 | /* disable incompatible options */ |
1722 | symbol_conf.cumulate_callchain = false; | |
1723 | ||
8838abf6 | 1724 | #ifndef HAVE_LIBDW_SUPPORT |
81e57dee NK |
1725 | pr_err("Error: Data type profiling is disabled due to missing DWARF support\n"); |
1726 | goto error; | |
1727 | #endif | |
1728 | } | |
1729 | ||
4bceffbc NK |
1730 | if (strcmp(input_name, "-") != 0) |
1731 | setup_browser(true); | |
22af969e | 1732 | else |
4bceffbc | 1733 | use_browser = 0; |
4bceffbc | 1734 | |
0bfbe661 NK |
1735 | if (report.data_type && use_browser == 1) { |
1736 | symbol_conf.annotate_data_member = true; | |
1737 | symbol_conf.annotate_data_sample = true; | |
1738 | } | |
1739 | ||
2570c02c | 1740 | symbol_conf.enable_latency = true; |
7ae1972e | 1741 | if (report.disable_order || !perf_session__has_switch_events(session)) { |
61b6b31c | 1742 | if (symbol_conf.parallelism_list_str || |
2570c02c DV |
1743 | symbol_conf.prefer_latency || |
1744 | (sort_order && (strstr(sort_order, "latency") || | |
1745 | strstr(sort_order, "parallelism"))) || | |
1746 | (field_order && (strstr(field_order, "latency") || | |
1747 | strstr(field_order, "parallelism")))) { | |
7ae1972e | 1748 | if (report.disable_order) |
2570c02c | 1749 | ui__error("Use of latency profile or parallelism is incompatible with --disable-order.\n"); |
7ae1972e | 1750 | else |
2570c02c | 1751 | ui__error("Use of latency profile or parallelism requires --latency flag during record.\n"); |
7ae1972e DV |
1752 | return -1; |
1753 | } | |
2570c02c DV |
1754 | /* |
1755 | * If user did not ask for anything related to | |
1756 | * latency/parallelism explicitly, just don't show it. | |
1757 | */ | |
1758 | symbol_conf.enable_latency = false; | |
7ae1972e DV |
1759 | } |
1760 | ||
6353255e DV |
1761 | if (last_key != K_SWITCH_INPUT_DATA) { |
1762 | if (sort_order && strstr(sort_order, "ipc")) { | |
1763 | parse_options_usage(report_usage, options, "s", 1); | |
1764 | goto error; | |
ec6ae74f JY |
1765 | } |
1766 | ||
6353255e DV |
1767 | if (sort_order && strstr(sort_order, "symbol")) { |
1768 | if (sort__mode == SORT_MODE__BRANCH) { | |
1769 | snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s", | |
1770 | sort_order, "ipc_lbr"); | |
1771 | report.symbol_ipc = true; | |
1772 | } else { | |
1773 | snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s", | |
1774 | sort_order, "ipc_null"); | |
1775 | } | |
1776 | ||
1777 | sort_order = sort_tmp; | |
1778 | } | |
ec6ae74f JY |
1779 | } |
1780 | ||
5e3b810a | 1781 | if ((last_key != K_SWITCH_INPUT_DATA && last_key != K_RELOAD) && |
0feba17b | 1782 | (setup_sorting(session->evlist) < 0)) { |
9887804d JO |
1783 | if (sort_order) |
1784 | parse_options_usage(report_usage, options, "s", 1); | |
1785 | if (field_order) | |
1786 | parse_options_usage(sort_order ? NULL : report_usage, | |
1787 | options, "F", 1); | |
1788 | goto error; | |
1789 | } | |
1790 | ||
27fafab5 | 1791 | if ((report.header || report.header_only) && !quiet) { |
5cfe2c82 JO |
1792 | perf_session__fprintf_info(session, stdout, |
1793 | report.show_full_info); | |
07a716ff | 1794 | if (report.header_only) { |
03de8656 NK |
1795 | if (data.is_pipe) { |
1796 | /* | |
1797 | * we need to process first few records | |
1798 | * which contains PERF_RECORD_HEADER_FEATURE. | |
1799 | */ | |
1800 | perf_session__process_events(session); | |
1801 | } | |
07a716ff TS |
1802 | ret = 0; |
1803 | goto error; | |
1804 | } | |
930f8b34 JO |
1805 | } else if (use_browser == 0 && !quiet && |
1806 | !report.stats_mode && !report.tasks_mode) { | |
5cfe2c82 JO |
1807 | fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n", |
1808 | stdout); | |
1809 | } | |
1810 | ||
ef7b93a1 | 1811 | /* |
6692c262 | 1812 | * Only in the TUI browser we are doing integrated annotation, |
ef7b93a1 ACM |
1813 | * so don't allocate extra space that won't be used in the stdio |
1814 | * implementation. | |
1815 | */ | |
81e57dee | 1816 | if (ui__has_annotation() || report.symbol_ipc || report.data_type || |
6f7164fa | 1817 | report.total_cycles_mode) { |
b01141f4 ACM |
1818 | ret = symbol__annotation_init(); |
1819 | if (ret < 0) | |
1820 | goto error; | |
80d50cae ACM |
1821 | /* |
1822 | * For searching by name on the "Browse map details". | |
1823 | * providing it only in verbose mode not to bloat too | |
1824 | * much struct symbol. | |
1825 | */ | |
bb963e16 | 1826 | if (verbose > 0) { |
80d50cae ACM |
1827 | /* |
1828 | * XXX: Need to provide a less kludgy way to ask for | |
1829 | * more space per symbol, the u32 is for the index on | |
1830 | * the ui browser. | |
1831 | * See symbol__browser_index. | |
1832 | */ | |
1833 | symbol_conf.priv_size += sizeof(u32); | |
80d50cae | 1834 | } |
7f929aea | 1835 | annotation_config__init(); |
80d50cae | 1836 | } |
655000e7 | 1837 | |
0a7e6d1b | 1838 | if (symbol__init(&session->header.env) < 0) |
993ac88d | 1839 | goto error; |
53cb8bc2 | 1840 | |
284c4e18 JY |
1841 | if (report.time_str) { |
1842 | ret = perf_time__parse_for_ranges(report.time_str, session, | |
1843 | &report.ptime_range, | |
1844 | &report.range_size, | |
1845 | &report.range_num); | |
1846 | if (ret < 0) | |
0a3cc3ae | 1847 | goto error; |
4885c90c AH |
1848 | |
1849 | itrace_synth_opts__set_time_range(&itrace_synth_opts, | |
1850 | report.ptime_range, | |
1851 | report.range_num); | |
46690a80 DA |
1852 | } |
1853 | ||
378ef0f5 | 1854 | #ifdef HAVE_LIBTRACEEVENT |
ea85ab24 | 1855 | if (session->tevent.pevent && |
ece2a4f4 TSV |
1856 | tep_set_function_resolver(session->tevent.pevent, |
1857 | machine__resolve_kernel_addr, | |
1858 | &session->machines.host) < 0) { | |
ea85ab24 WY |
1859 | pr_err("%s: failed to set libtraceevent function resolver\n", |
1860 | __func__); | |
1861 | return -1; | |
1862 | } | |
378ef0f5 | 1863 | #endif |
08e71542 | 1864 | sort__setup_elide(stdout); |
25903407 | 1865 | |
993ac88d | 1866 | ret = __cmd_report(&report); |
5e3b810a | 1867 | if (ret == K_SWITCH_INPUT_DATA || ret == K_RELOAD) { |
ad0de097 | 1868 | perf_session__delete(session); |
0feba17b | 1869 | last_key = K_SWITCH_INPUT_DATA; |
acda4c20 NK |
1870 | /* |
1871 | * To support switching between data with and without callchains. | |
1872 | * report__setup_sample_type() will update it properly. | |
1873 | */ | |
1874 | symbol_conf.use_callchain = false; | |
ad0de097 FT |
1875 | goto repeat; |
1876 | } else | |
1877 | ret = 0; | |
1878 | ||
0bdfbd04 AH |
1879 | if (!use_browser && (verbose > 2 || debug_kmaps)) |
1880 | perf_session__dump_kmaps(session); | |
993ac88d | 1881 | error: |
4885c90c AH |
1882 | if (report.ptime_range) { |
1883 | itrace_synth_opts__clear_time_range(&itrace_synth_opts); | |
284c4e18 | 1884 | zfree(&report.ptime_range); |
4885c90c | 1885 | } |
6f7164fa | 1886 | |
cca0cc76 JY |
1887 | if (report.block_reports) { |
1888 | block_info__free_report(report.block_reports, | |
1889 | report.nr_block_reports); | |
1890 | report.block_reports = NULL; | |
1891 | } | |
6f7164fa | 1892 | |
cb62c6f1 | 1893 | zstd_fini(&(session->zstd_data)); |
993ac88d | 1894 | perf_session__delete(session); |
a37338aa | 1895 | exit: |
7f929aea | 1896 | annotation_options__exit(); |
a37338aa RM |
1897 | free(sort_order_help); |
1898 | free(field_order_help); | |
993ac88d | 1899 | return ret; |
53cb8bc2 | 1900 | } |