]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/perf/builtin-report.c
perf report: Fix incorrectly added dimensions as switch perf data file
[mirror_ubuntu-bionic-kernel.git] / tools / perf / builtin-report.c
CommitLineData
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
bf9e1876 11#include "util/util.h"
41840d21 12#include "util/config.h"
bf9e1876 13
78f7defe 14#include "util/annotate.h"
8fc0321f 15#include "util/color.h"
5da50258 16#include <linux/list.h>
43cbcd8a 17#include <linux/rbtree.h>
a2928c42 18#include "util/symbol.h"
f55c5552 19#include "util/callchain.h"
8d513270 20#include "util/values.h"
8fa66bdc 21
53cb8bc2 22#include "perf.h"
8f28827a 23#include "util/debug.h"
e248de33
ACM
24#include "util/evlist.h"
25#include "util/evsel.h"
7c6a1c65 26#include "util/header.h"
94c744b6 27#include "util/session.h"
45694aa7 28#include "util/tool.h"
53cb8bc2 29
4b6ab94e 30#include <subcmd/parse-options.h>
34b7b0f9 31#include <subcmd/exec-cmd.h>
53cb8bc2
IM
32#include "util/parse-events.h"
33
6baa0a5a 34#include "util/thread.h"
dd68ada2 35#include "util/sort.h"
3d1d07ec 36#include "util/hist.h"
f5fc1412 37#include "util/data.h"
68e94f4e 38#include "arch/common.h"
46690a80 39#include "util/time-utils.h"
520a2ebc 40#include "util/auxtrace.h"
58db1d6e 41#include "util/units.h"
2d78b189 42#include "util/branch.h"
520a2ebc 43
fc67297b 44#include <dlfcn.h>
a43783ae 45#include <errno.h>
fd20e811 46#include <inttypes.h>
1eae20c1 47#include <regex.h>
9607ad3a 48#include <signal.h>
5d67be97 49#include <linux/bitmap.h>
531d2410 50#include <linux/stringify.h>
7a8ef4c4
ACM
51#include <sys/types.h>
52#include <sys/stat.h>
53#include <unistd.h>
5d67be97 54
28b21393 55struct report {
45694aa7 56 struct perf_tool tool;
d20deb64 57 struct perf_session *session;
2059fc7a 58 bool use_tui, use_gtk, use_stdio;
fa372aae
ACM
59 bool show_full_info;
60 bool show_threads;
61 bool inverted_callchain;
f4f7e28d 62 bool mem_mode;
5cfe2c82
JO
63 bool header;
64 bool header_only;
98df858e 65 bool nonany_branch_mode;
91e95617 66 int max_stack;
fa372aae
ACM
67 struct perf_read_values show_threads_values;
68 const char *pretty_printing_style;
fa372aae 69 const char *cpu_list;
b14ffaca 70 const char *symbol_filter_str;
46690a80
DA
71 const char *time_str;
72 struct perf_time_interval ptime;
064f1981 73 float min_percent;
58c311da 74 u64 nr_entries;
94786b67 75 u64 queue_size;
21394d94 76 int socket_filter;
fa372aae 77 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
2d78b189 78 struct branch_type_stat brtype_stat;
d20deb64 79};
5d67be97 80
28b21393 81static int report__config(const char *var, const char *value, void *cb)
00c7e1f1 82{
94786b67
JO
83 struct report *rep = cb;
84
00c7e1f1
NK
85 if (!strcmp(var, "report.group")) {
86 symbol_conf.event_group = perf_config_bool(var, value);
87 return 0;
88 }
eec574e6 89 if (!strcmp(var, "report.percent-limit")) {
2665b452
NK
90 double pcnt = strtof(value, NULL);
91
92 rep->min_percent = pcnt;
93 callchain_param.min_percent = pcnt;
eec574e6
NK
94 return 0;
95 }
8d8e645c
NK
96 if (!strcmp(var, "report.children")) {
97 symbol_conf.cumulate_callchain = perf_config_bool(var, value);
98 return 0;
99 }
25ce4bb8
ACM
100 if (!strcmp(var, "report.queue-size"))
101 return perf_config_u64(&rep->queue_size, var, value);
102
fa1f4565
ACM
103 if (!strcmp(var, "report.sort_order")) {
104 default_sort_order = strdup(value);
105 return 0;
106 }
00c7e1f1 107
b8cbb349 108 return 0;
00c7e1f1
NK
109}
110
9d3c02d7
NK
111static int hist_iter__report_callback(struct hist_entry_iter *iter,
112 struct addr_location *al, bool single,
113 void *arg)
114{
115 int err = 0;
116 struct report *rep = arg;
117 struct hist_entry *he = iter->he;
118 struct perf_evsel *evsel = iter->evsel;
bab89f6a 119 struct perf_sample *sample = iter->sample;
9d3c02d7
NK
120 struct mem_info *mi;
121 struct branch_info *bi;
122
9d3c02d7
NK
123 if (!ui__has_annotation())
124 return 0;
125
bab89f6a 126 hist__account_cycles(sample->branch_stack, al, sample,
57849998
AK
127 rep->nonany_branch_mode);
128
9d3c02d7
NK
129 if (sort__mode == SORT_MODE__BRANCH) {
130 bi = he->branch_info;
bab89f6a 131 err = addr_map_symbol__inc_samples(&bi->from, sample, evsel->idx);
9d3c02d7
NK
132 if (err)
133 goto out;
134
bab89f6a 135 err = addr_map_symbol__inc_samples(&bi->to, sample, evsel->idx);
9d3c02d7
NK
136
137 } else if (rep->mem_mode) {
138 mi = he->mem_info;
bab89f6a 139 err = addr_map_symbol__inc_samples(&mi->daddr, sample, evsel->idx);
9d3c02d7
NK
140 if (err)
141 goto out;
142
bab89f6a 143 err = hist_entry__inc_addr_samples(he, sample, evsel->idx, al->addr);
9d3c02d7
NK
144
145 } else if (symbol_conf.cumulate_callchain) {
146 if (single)
bab89f6a 147 err = hist_entry__inc_addr_samples(he, sample, evsel->idx,
9d3c02d7
NK
148 al->addr);
149 } else {
bab89f6a 150 err = hist_entry__inc_addr_samples(he, sample, evsel->idx, al->addr);
9d3c02d7
NK
151 }
152
153out:
154 return err;
f4f7e28d
SE
155}
156
2d78b189
JY
157static int hist_iter__branch_callback(struct hist_entry_iter *iter,
158 struct addr_location *al __maybe_unused,
159 bool single __maybe_unused,
160 void *arg)
161{
162 struct hist_entry *he = iter->he;
163 struct report *rep = arg;
164 struct branch_info *bi;
ed08667f
JY
165 struct perf_sample *sample = iter->sample;
166 struct perf_evsel *evsel = iter->evsel;
167 int err;
168
169 if (!ui__has_annotation())
170 return 0;
171
172 hist__account_cycles(sample->branch_stack, al, sample,
173 rep->nonany_branch_mode);
2d78b189
JY
174
175 bi = he->branch_info;
ed08667f
JY
176 err = addr_map_symbol__inc_samples(&bi->from, sample, evsel->idx);
177 if (err)
178 goto out;
179
180 err = addr_map_symbol__inc_samples(&bi->to, sample, evsel->idx);
181
2d78b189
JY
182 branch_type_count(&rep->brtype_stat, &bi->flags,
183 bi->from.addr, bi->to.addr);
184
ed08667f
JY
185out:
186 return err;
2d78b189
JY
187}
188
45694aa7 189static int process_sample_event(struct perf_tool *tool,
d20deb64 190 union perf_event *event,
8115d60c 191 struct perf_sample *sample,
9e69c210 192 struct perf_evsel *evsel,
743eb868 193 struct machine *machine)
75051724 194{
28b21393 195 struct report *rep = container_of(tool, struct report, tool);
1ed091c4 196 struct addr_location al;
69bcb019 197 struct hist_entry_iter iter = {
063bd936
NK
198 .evsel = evsel,
199 .sample = sample,
b49a8fe5 200 .hide_unresolved = symbol_conf.hide_unresolved,
063bd936 201 .add_entry_cb = hist_iter__report_callback,
69bcb019 202 };
b91fc39f 203 int ret = 0;
180f95e2 204
46690a80
DA
205 if (perf_time__skip_sample(&rep->ptime, sample->time))
206 return 0;
207
bb3eb566 208 if (machine__resolve(machine, &al, sample) < 0) {
a4210141
NK
209 pr_debug("problem processing %d event, skipping it.\n",
210 event->header.type);
75051724
IM
211 return -1;
212 }
e7fb08b1 213
b49a8fe5 214 if (symbol_conf.hide_unresolved && al.sym == NULL)
b91fc39f 215 goto out_put;
7bec7a91 216
fa372aae 217 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
b91fc39f 218 goto out_put;
5d67be97 219
f86225db
AH
220 if (sort__mode == SORT_MODE__BRANCH) {
221 /*
222 * A non-synthesized event might not have a branch stack if
223 * branch stacks have been synthesized (using itrace options).
224 */
225 if (!sample->branch_stack)
226 goto out_put;
2d78b189
JY
227
228 iter.add_entry_cb = hist_iter__branch_callback;
69bcb019 229 iter.ops = &hist_iter_branch;
f86225db 230 } else if (rep->mem_mode) {
69bcb019 231 iter.ops = &hist_iter_mem;
f86225db 232 } else if (symbol_conf.cumulate_callchain) {
7a13aa28 233 iter.ops = &hist_iter_cumulative;
f86225db 234 } else {
69bcb019 235 iter.ops = &hist_iter_normal;
f86225db 236 }
69bcb019
NK
237
238 if (al.map != NULL)
239 al.map->dso->hit = 1;
240
063bd936 241 ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
69bcb019
NK
242 if (ret < 0)
243 pr_debug("problem adding hist entry, skipping event\n");
b91fc39f
ACM
244out_put:
245 addr_location__put(&al);
27a0dcb7 246 return ret;
75051724 247}
3502973d 248
45694aa7 249static int process_read_event(struct perf_tool *tool,
d20deb64 250 union perf_event *event,
1d037ca1 251 struct perf_sample *sample __maybe_unused,
743eb868 252 struct perf_evsel *evsel,
1d037ca1 253 struct machine *machine __maybe_unused)
e9ea2fde 254{
28b21393 255 struct report *rep = container_of(tool, struct report, tool);
743eb868 256
fa372aae 257 if (rep->show_threads) {
7289f83c 258 const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
89973506 259 int err = perf_read_values_add_value(&rep->show_threads_values,
8d513270 260 event->read.pid, event->read.tid,
9933183e 261 evsel->idx,
8d513270
BG
262 name,
263 event->read.value);
89973506
ACM
264
265 if (err)
266 return err;
8d513270
BG
267 }
268
e9ea2fde
PZ
269 return 0;
270}
271
300aa941 272/* For pipe mode, sample_type is not currently set */
28b21393 273static int report__setup_sample_type(struct report *rep)
d80d338d 274{
c824c433
ACM
275 struct perf_session *session = rep->session;
276 u64 sample_type = perf_evlist__combined_sample_type(session->evlist);
8ceb41d7 277 bool is_pipe = perf_data__is_pipe(session->data);
d20deb64 278
d062ac16
AH
279 if (session->itrace_synth_opts->callchain ||
280 (!is_pipe &&
281 perf_header__has_feat(&session->header, HEADER_AUXTRACE) &&
282 !session->itrace_synth_opts->set))
283 sample_type |= PERF_SAMPLE_CALLCHAIN;
284
c7eced63
AH
285 if (session->itrace_synth_opts->last_branch)
286 sample_type |= PERF_SAMPLE_BRANCH_STACK;
287
cc9784bd 288 if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
de7e6a7c 289 if (perf_hpp_list.parent) {
3780f488 290 ui__error("Selected --sort parent, but no "
00894ce9
ACM
291 "callchain data. Did you call "
292 "'perf record' without -g?\n");
d549c769 293 return -EINVAL;
91b4eaea 294 }
b49a821e
JY
295 if (symbol_conf.use_callchain &&
296 !symbol_conf.show_branchflag_count) {
297 ui__error("Selected -g or --branch-history.\n"
298 "But no callchain or branch data.\n"
299 "Did you call 'perf record' without -g or -b?\n");
016e92fb 300 return -1;
91b4eaea 301 }
1cc83815 302 } else if (!callchain_param.enabled &&
fa372aae 303 callchain_param.mode != CHAIN_NONE &&
b9a63b9b 304 !symbol_conf.use_callchain) {
d599db3f 305 symbol_conf.use_callchain = true;
16537f13 306 if (callchain_register_param(&callchain_param) < 0) {
3780f488 307 ui__error("Can't register callchain params.\n");
d549c769 308 return -EINVAL;
b1a88349 309 }
f5970550
PZ
310 }
311
793aaaab
NK
312 if (symbol_conf.cumulate_callchain) {
313 /* Silently ignore if callchain is missing */
314 if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
315 symbol_conf.cumulate_callchain = false;
316 perf_hpp__cancel_cumulate();
317 }
318 }
319
55369fc1 320 if (sort__mode == SORT_MODE__BRANCH) {
cc9784bd 321 if (!is_pipe &&
7f3be652 322 !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
3780f488
NK
323 ui__error("Selected -b but no branch data. "
324 "Did you call perf record without -b?\n");
b50311dc
RAV
325 return -1;
326 }
327 }
328
0cdccac6
NK
329 if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) {
330 if ((sample_type & PERF_SAMPLE_REGS_USER) &&
1241c133 331 (sample_type & PERF_SAMPLE_STACK_USER)) {
0cdccac6 332 callchain_param.record_mode = CALLCHAIN_DWARF;
1241c133
ACM
333 dwarf_callchain_users = true;
334 } else if (sample_type & PERF_SAMPLE_BRANCH_STACK)
aad2b21c 335 callchain_param.record_mode = CALLCHAIN_LBR;
0cdccac6
NK
336 else
337 callchain_param.record_mode = CALLCHAIN_FP;
338 }
98df858e
AK
339
340 /* ??? handle more cases than just ANY? */
341 if (!(perf_evlist__combined_branch_type(session->evlist) &
342 PERF_SAMPLE_BRANCH_ANY))
343 rep->nonany_branch_mode = true;
344
016b1890
JY
345#ifndef HAVE_LIBUNWIND_SUPPORT
346 if (dwarf_callchain_users) {
347 ui__warning("Please install libunwind development packages "
348 "during the perf build.\n");
349 }
350#endif
351
016e92fb
FW
352 return 0;
353}
6142f9ec 354
1d037ca1 355static void sig_handler(int sig __maybe_unused)
46656ac7
TZ
356{
357 session_done = 1;
358}
359
28b21393 360static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report *rep,
c82ee828
ACM
361 const char *evname, FILE *fp)
362{
363 size_t ret;
364 char unit;
c824c433
ACM
365 unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
366 u64 nr_events = hists->stats.total_period;
367 struct perf_evsel *evsel = hists_to_evsel(hists);
717e263f
NK
368 char buf[512];
369 size_t size = sizeof(buf);
84734b06 370 int socked_id = hists->socket_filter;
717e263f 371
27fafab5
NK
372 if (quiet)
373 return 0;
374
f2148330
NK
375 if (symbol_conf.filter_relative) {
376 nr_samples = hists->stats.nr_non_filtered_samples;
377 nr_events = hists->stats.total_non_filtered_period;
378 }
379
759ff497 380 if (perf_evsel__is_group_event(evsel)) {
717e263f
NK
381 struct perf_evsel *pos;
382
383 perf_evsel__group_desc(evsel, buf, size);
384 evname = buf;
385
386 for_each_group_member(pos, evsel) {
4ea062ed
ACM
387 const struct hists *pos_hists = evsel__hists(pos);
388
f2148330 389 if (symbol_conf.filter_relative) {
4ea062ed
ACM
390 nr_samples += pos_hists->stats.nr_non_filtered_samples;
391 nr_events += pos_hists->stats.total_non_filtered_period;
f2148330 392 } else {
4ea062ed
ACM
393 nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
394 nr_events += pos_hists->stats.total_period;
f2148330 395 }
717e263f
NK
396 }
397 }
c82ee828 398
cc686280
AR
399 nr_samples = convert_unit(nr_samples, &unit);
400 ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
c82ee828 401 if (evname != NULL)
cc686280
AR
402 ret += fprintf(fp, " of event '%s'", evname);
403
9e207ddf
KL
404 if (symbol_conf.show_ref_callgraph &&
405 strstr(evname, "call-graph=no")) {
406 ret += fprintf(fp, ", show reference callgraph");
407 }
408
f4f7e28d
SE
409 if (rep->mem_mode) {
410 ret += fprintf(fp, "\n# Total weight : %" PRIu64, nr_events);
228f14f2 411 ret += fprintf(fp, "\n# Sort order : %s", sort_order ? : default_mem_sort_order);
f4f7e28d
SE
412 } else
413 ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
21394d94 414
84734b06
KL
415 if (socked_id > -1)
416 ret += fprintf(fp, "\n# Processor Socket: %d", socked_id);
21394d94 417
c82ee828
ACM
418 return ret + fprintf(fp, "\n#\n");
419}
420
7f0030b2 421static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
28b21393 422 struct report *rep,
7f0030b2 423 const char *help)
d67f088e 424{
e248de33 425 struct perf_evsel *pos;
d67f088e 426
27fafab5
NK
427 if (!quiet) {
428 fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n",
429 evlist->stats.total_lost_samples);
430 }
431
e5cadb93 432 evlist__for_each_entry(evlist, pos) {
4ea062ed 433 struct hists *hists = evsel__hists(pos);
7289f83c 434 const char *evname = perf_evsel__name(pos);
d67f088e 435
fc24d7c2
NK
436 if (symbol_conf.event_group &&
437 !perf_evsel__is_group_leader(pos))
438 continue;
439
28b21393 440 hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
27fafab5 441 hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout,
b49a821e
JY
442 symbol_conf.use_callchain ||
443 symbol_conf.show_branchflag_count);
d67f088e 444 fprintf(stdout, "\n\n");
d67f088e
ACM
445 }
446
8b53dbef 447 if (!quiet)
d67f088e
ACM
448 fprintf(stdout, "#\n# (%s)\n#\n", help);
449
021162cf
NK
450 if (rep->show_threads) {
451 bool style = !strcmp(rep->pretty_printing_style, "raw");
452 perf_read_values_display(stdout, &rep->show_threads_values,
453 style);
454 perf_read_values_destroy(&rep->show_threads_values);
d67f088e
ACM
455 }
456
2d78b189
JY
457 if (sort__mode == SORT_MODE__BRANCH)
458 branch_type_stat_display(stdout, &rep->brtype_stat);
459
d67f088e
ACM
460 return 0;
461}
462
fad2918e
ACM
463static void report__warn_kptr_restrict(const struct report *rep)
464{
a5e813c6 465 struct map *kernel_map = machine__kernel_map(&rep->session->machines.host);
f6fcc143 466 struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;
fad2918e 467
3f0a4c87
ACM
468 if (perf_evlist__exclude_kernel(rep->session->evlist))
469 return;
470
fad2918e
ACM
471 if (kernel_map == NULL ||
472 (kernel_map->dso->hit &&
473 (kernel_kmap->ref_reloc_sym == NULL ||
474 kernel_kmap->ref_reloc_sym->addr == 0))) {
475 const char *desc =
476 "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
477 "can't be resolved.";
478
479 if (kernel_map) {
480 const struct dso *kdso = kernel_map->dso;
481 if (!RB_EMPTY_ROOT(&kdso->symbols[MAP__FUNCTION])) {
482 desc = "If some relocation was applied (e.g. "
483 "kexec) symbols may be misresolved.";
484 }
485 }
486
487 ui__warning(
488"Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
489"Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
490"Samples in kernel modules can't be resolved as well.\n\n",
491 desc);
492 }
493}
494
8362951b
ACM
495static int report__gtk_browse_hists(struct report *rep, const char *help)
496{
497 int (*hist_browser)(struct perf_evlist *evlist, const char *help,
498 struct hist_browser_timer *timer, float min_pcnt);
499
500 hist_browser = dlsym(perf_gtk_handle, "perf_evlist__gtk_browse_hists");
501
502 if (hist_browser == NULL) {
503 ui__error("GTK browser not found!\n");
504 return -1;
505 }
506
507 return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
508}
509
510static int report__browse_hists(struct report *rep)
511{
512 int ret;
513 struct perf_session *session = rep->session;
514 struct perf_evlist *evlist = session->evlist;
34b7b0f9
NK
515 const char *help = perf_tip(system_path(TIPDIR));
516
517 if (help == NULL) {
518 /* fallback for people who don't install perf ;-) */
519 help = perf_tip(DOCDIR);
520 if (help == NULL)
521 help = "Cannot load tips.txt file, please install perf!";
522 }
8362951b
ACM
523
524 switch (use_browser) {
525 case 1:
526 ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
527 rep->min_percent,
528 &session->header.env);
529 /*
530 * Usually "ret" is the last pressed key, and we only
531 * care if the key notifies us to switch data file.
532 */
533 if (ret != K_SWITCH_INPUT_DATA)
534 ret = 0;
535 break;
536 case 2:
537 ret = report__gtk_browse_hists(rep, help);
538 break;
539 default:
540 ret = perf_evlist__tty_browse_hists(evlist, rep, help);
541 break;
542 }
543
544 return ret;
545}
546
5b2ea6f2 547static int report__collapse_hists(struct report *rep)
f6d8b057
ACM
548{
549 struct ui_progress prog;
550 struct perf_evsel *pos;
5b2ea6f2 551 int ret = 0;
f6d8b057 552
58c311da 553 ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
f6d8b057 554
e5cadb93 555 evlist__for_each_entry(rep->session->evlist, pos) {
4ea062ed 556 struct hists *hists = evsel__hists(pos);
f6d8b057
ACM
557
558 if (pos->idx == 0)
559 hists->symbol_filter_str = rep->symbol_filter_str;
560
21394d94
KL
561 hists->socket_filter = rep->socket_filter;
562
5b2ea6f2
NK
563 ret = hists__collapse_resort(hists, &prog);
564 if (ret < 0)
565 break;
f6d8b057
ACM
566
567 /* Non-group events are considered as leader */
568 if (symbol_conf.event_group &&
569 !perf_evsel__is_group_leader(pos)) {
4ea062ed 570 struct hists *leader_hists = evsel__hists(pos->leader);
f6d8b057
ACM
571
572 hists__match(leader_hists, hists);
573 hists__link(leader_hists, hists);
574 }
575 }
576
577 ui_progress__finish();
5b2ea6f2 578 return ret;
f6d8b057
ACM
579}
580
740b97f9
NK
581static void report__output_resort(struct report *rep)
582{
583 struct ui_progress prog;
584 struct perf_evsel *pos;
585
586 ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
587
e5cadb93 588 evlist__for_each_entry(rep->session->evlist, pos)
452ce03b 589 perf_evsel__output_resort(pos, &prog);
740b97f9
NK
590
591 ui_progress__finish();
592}
593
28b21393 594static int __cmd_report(struct report *rep)
016e92fb 595{
f6d8b057 596 int ret;
993ac88d 597 struct perf_session *session = rep->session;
e248de33 598 struct perf_evsel *pos;
8ceb41d7 599 struct perf_data *data = session->data;
8fa66bdc 600
46656ac7
TZ
601 signal(SIGINT, sig_handler);
602
fa372aae
ACM
603 if (rep->cpu_list) {
604 ret = perf_session__cpu_bitmap(session, rep->cpu_list,
605 rep->cpu_bitmap);
25b1606b
NK
606 if (ret) {
607 ui__error("failed to set cpu bitmap\n");
d4ae0a6f 608 return ret;
25b1606b 609 }
644e0840 610 session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
5d67be97
AB
611 }
612
89973506
ACM
613 if (rep->show_threads) {
614 ret = perf_read_values_init(&rep->show_threads_values);
615 if (ret)
616 return ret;
617 }
f5970550 618
28b21393 619 ret = report__setup_sample_type(rep);
25b1606b
NK
620 if (ret) {
621 /* report__setup_sample_type() already showed error message */
d4ae0a6f 622 return ret;
25b1606b 623 }
d549c769 624
b7b61cbe 625 ret = perf_session__process_events(session);
25b1606b
NK
626 if (ret) {
627 ui__error("failed to process sample\n");
d4ae0a6f 628 return ret;
25b1606b 629 }
97b07b69 630
fad2918e 631 report__warn_kptr_restrict(rep);
ec80fde7 632
e5cadb93 633 evlist__for_each_entry(session->evlist, pos)
590cd344
NK
634 rep->nr_entries += evsel__hists(pos)->nr_entries;
635
150e465a
NK
636 if (use_browser == 0) {
637 if (verbose > 3)
638 perf_session__fprintf(session, stdout);
9ac99545 639
150e465a
NK
640 if (verbose > 2)
641 perf_session__fprintf_dsos(session, stdout);
16f762a2 642
150e465a
NK
643 if (dump_trace) {
644 perf_session__fprintf_nr_events(session, stdout);
2a1731fb 645 perf_evlist__fprintf_nr_events(session->evlist, stdout);
150e465a
NK
646 return 0;
647 }
71ad0f5e
JO
648 }
649
5b2ea6f2
NK
650 ret = report__collapse_hists(rep);
651 if (ret) {
652 ui__error("failed to process hist entry\n");
653 return ret;
654 }
e248de33 655
33e940a2
ACM
656 if (session_done())
657 return 0;
658
740b97f9
NK
659 /*
660 * recalculate number of entries after collapsing since it
661 * might be changed during the collapse phase.
662 */
663 rep->nr_entries = 0;
e5cadb93 664 evlist__for_each_entry(session->evlist, pos)
740b97f9
NK
665 rep->nr_entries += evsel__hists(pos)->nr_entries;
666
58c311da 667 if (rep->nr_entries == 0) {
eae8ad80 668 ui__error("The %s file has no samples!\n", data->file.path);
d4ae0a6f 669 return 0;
cbbc79a5
EM
670 }
671
740b97f9 672 report__output_resort(rep);
6e1f601a 673
8362951b 674 return report__browse_hists(rep);
8fa66bdc
ACM
675}
676
4eb3e478 677static int
cff6bb46 678report_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
4eb3e478 679{
1cc83815 680 struct callchain_param *callchain = opt->value;
c20ab37e 681
1cc83815 682 callchain->enabled = !unset;
b9a63b9b
ACM
683 /*
684 * --no-call-graph
685 */
686 if (unset) {
1cc83815
ACM
687 symbol_conf.use_callchain = false;
688 callchain->mode = CHAIN_NONE;
b9a63b9b
ACM
689 return 0;
690 }
691
cff6bb46 692 return parse_callchain_report_opt(arg);
4eb3e478
FW
693}
694
b21484f1
GP
695int
696report_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
697 const char *arg, int unset __maybe_unused)
698{
699 if (arg) {
700 int err = regcomp(&ignore_callees_regex, arg, REG_EXTENDED);
701 if (err) {
702 char buf[BUFSIZ];
703 regerror(err, &ignore_callees_regex, buf, sizeof(buf));
704 pr_err("Invalid --ignore-callees regex: %s\n%s", arg, buf);
705 return -1;
706 }
707 have_ignore_callees = 1;
708 }
709
710 return 0;
711}
712
993ac88d 713static int
7e6a7998 714parse_branch_mode(const struct option *opt,
1d037ca1 715 const char *str __maybe_unused, int unset)
993ac88d 716{
55369fc1
NK
717 int *branch_mode = opt->value;
718
719 *branch_mode = !unset;
993ac88d
SE
720 return 0;
721}
722
064f1981
NK
723static int
724parse_percent_limit(const struct option *opt, const char *str,
725 int unset __maybe_unused)
726{
28b21393 727 struct report *rep = opt->value;
2665b452 728 double pcnt = strtof(str, NULL);
064f1981 729
2665b452
NK
730 rep->min_percent = pcnt;
731 callchain_param.min_percent = pcnt;
064f1981
NK
732 return 0;
733}
734
f2af0086 735#define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
76a26549
NK
736
737const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
738 CALLCHAIN_REPORT_HELP
739 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
21cf6284 740
b0ad8ea6 741int cmd_report(int argc, const char **argv)
d20deb64 742{
993ac88d 743 struct perf_session *session;
520a2ebc 744 struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
efad1415 745 struct stat st;
993ac88d 746 bool has_br_stack = false;
55369fc1 747 int branch_mode = -1;
013f61e1 748 int last_key = 0;
fa94c36c 749 bool branch_call_mode = false;
76a26549 750 char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
d20deb64 751 const char * const report_usage[] = {
fb2baceb 752 "perf report [<options>]",
d20deb64
ACM
753 NULL
754 };
28b21393 755 struct report report = {
45694aa7 756 .tool = {
d20deb64
ACM
757 .sample = process_sample_event,
758 .mmap = perf_event__process_mmap,
5c5e854b 759 .mmap2 = perf_event__process_mmap2,
d20deb64 760 .comm = perf_event__process_comm,
f3b3614a 761 .namespaces = perf_event__process_namespaces,
f62d3f0f
ACM
762 .exit = perf_event__process_exit,
763 .fork = perf_event__process_fork,
d20deb64
ACM
764 .lost = perf_event__process_lost,
765 .read = process_read_event,
766 .attr = perf_event__process_attr,
d20deb64
ACM
767 .tracing_data = perf_event__process_tracing_data,
768 .build_id = perf_event__process_build_id,
520a2ebc
AH
769 .id_index = perf_event__process_id_index,
770 .auxtrace_info = perf_event__process_auxtrace_info,
771 .auxtrace = perf_event__process_auxtrace,
e9def1b2 772 .feature = perf_event__process_feature,
0a8cb85c 773 .ordered_events = true,
d20deb64
ACM
774 .ordering_requires_timestamps = true,
775 },
fe176085 776 .max_stack = PERF_MAX_STACK_DEPTH,
d20deb64 777 .pretty_printing_style = "normal",
21394d94 778 .socket_filter = -1,
d20deb64
ACM
779 };
780 const struct option options[] = {
70cb4e96 781 OPT_STRING('i', "input", &input_name, "file",
53cb8bc2 782 "input file name"),
c0555642 783 OPT_INCR('v', "verbose", &verbose,
815e777f 784 "be more verbose (show symbol address, etc)"),
27fafab5 785 OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
97b07b69
IM
786 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
787 "dump raw trace in ASCII"),
b32d133a
ACM
788 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
789 "file", "vmlinux pathname"),
b226a5a7
DA
790 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
791 "file", "kallsyms pathname"),
2059fc7a 792 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
b32d133a 793 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
42976487 794 "load module symbols - WARNING: use only with -k and LIVE kernel"),
d599db3f 795 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
e3d7e183 796 "Show a column with the number of samples"),
fa372aae 797 OPT_BOOLEAN('T', "threads", &report.show_threads,
8d513270 798 "Show per-thread event counters"),
fa372aae 799 OPT_STRING(0, "pretty", &report.pretty_printing_style, "key",
9f866697 800 "pretty printing style key: normal raw"),
fa372aae 801 OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"),
c31a9457 802 OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"),
fa372aae
ACM
803 OPT_BOOLEAN(0, "stdio", &report.use_stdio,
804 "Use the stdio interface"),
5cfe2c82
JO
805 OPT_BOOLEAN(0, "header", &report.header, "Show data header."),
806 OPT_BOOLEAN(0, "header-only", &report.header_only,
807 "Show only data header."),
63299f05 808 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
a2ce067e
NK
809 "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
810 " Please refer the man page for the complete list."),
a7d945bc
NK
811 OPT_STRING('F', "fields", &field_order, "key[,keys...]",
812 "output field(s): overhead, period, sample plus all of sort keys"),
b272a59d 813 OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
a1645ce1 814 "Show sample percentage for different cpu modes"),
b272a59d
NK
815 OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
816 "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN),
b25bcf2f
IM
817 OPT_STRING('p', "parent", &parent_pattern, "regex",
818 "regex filter to identify parent, see: '--sort parent'"),
d599db3f 819 OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
b8e6d829 820 "Only display entries with parent-match"),
1cc83815 821 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
f2af0086 822 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
21cf6284
NK
823 report_callchain_help, &report_parse_callchain_opt,
824 callchain_default_opt),
793aaaab
NK
825 OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
826 "Accumulate callchains of children and show total overhead as well"),
91e95617
WL
827 OPT_INTEGER(0, "max-stack", &report.max_stack,
828 "Set the maximum stack depth when parsing the callchain, "
829 "anything beyond the specified depth will be ignored. "
4cb93446 830 "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
fa372aae
ACM
831 OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
832 "alias for inverted call graph"),
b21484f1
GP
833 OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
834 "ignore callees of these functions in call graphs",
835 report_parse_ignore_callees_opt),
655000e7 836 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
25903407 837 "only consider symbols in these dsos"),
c8e66720 838 OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
cc8b88b1 839 "only consider symbols in these comms"),
e03eaa40
DA
840 OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
841 "only consider symbols in these pids"),
842 OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
843 "only consider symbols in these tids"),
655000e7 844 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
7bec7a91 845 "only consider these symbols"),
b14ffaca
NK
846 OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
847 "only show symbols that (partially) match with this filter"),
655000e7 848 OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
52d422de
ACM
849 "width[,width...]",
850 "don't try to adjust column width, use these fixed values"),
0c8c2077 851 OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
52d422de
ACM
852 "separator for columns, no spaces will be added between "
853 "columns '.' is reserved."),
b49a8fe5 854 OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
71289be7 855 "Only display entries resolved to a symbol"),
a7066709
HK
856 OPT_CALLBACK(0, "symfs", NULL, "directory",
857 "Look for files with symbols relative to this directory",
858 symbol__config_symfs),
c8e66720 859 OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
fa372aae
ACM
860 "list of cpus to profile"),
861 OPT_BOOLEAN('I', "show-info", &report.show_full_info,
fbe96f29 862 "Display extended information about perf.data file"),
64c6f0c7
ACM
863 OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
864 "Interleave source code with assembly code (default)"),
865 OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
866 "Display raw encoding of assembly instructions (default)"),
f69b64f7
AK
867 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
868 "Specify disassembler style (e.g. -M intel for intel syntax)"),
3f2728bd
ACM
869 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
870 "Show a column with the sum of periods"),
01d14f16
NK
871 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
872 "Show event group information together"),
55369fc1 873 OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
fa94c36c
AK
874 "use branch records for per branch histogram filling",
875 parse_branch_mode),
876 OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
877 "add last branch records to call history"),
7a4ec938
MB
878 OPT_STRING(0, "objdump", &objdump_path, "path",
879 "objdump binary to use for disassembly and annotations"),
328ccdac
NK
880 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
881 "Disable symbol demangling"),
763122ad
AK
882 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
883 "Enable kernel symbol demangling"),
f4f7e28d 884 OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
064f1981
NK
885 OPT_CALLBACK(0, "percent-limit", &report, "percent",
886 "Don't show entries under that percent", parse_percent_limit),
f2148330 887 OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
33db4568 888 "how to display percentage of filtered entries", parse_filter_percentage),
520a2ebc
AH
889 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
890 "Instruction Tracing options",
891 itrace_parse_synth_opts),
a9710ba0
AK
892 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
893 "Show full source file name path for source lines"),
9e207ddf
KL
894 OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
895 "Show callgraph from reference event"),
21394d94
KL
896 OPT_INTEGER(0, "socket-filter", &report.socket_filter,
897 "only show processor socket that match with this filter"),
053a3989
NK
898 OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
899 "Show raw trace event output (do not use print fmt or plugins)"),
4251446d
NK
900 OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
901 "Show entries in a hierarchy"),
175b968b
ACM
902 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
903 "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
904 stdio__config_color, "always"),
46690a80
DA
905 OPT_STRING(0, "time", &report.time_str, "str",
906 "Time span of interest (start,stop)"),
f3a60646
JY
907 OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
908 "Show inline function"),
53cb8bc2 909 OPT_END()
d20deb64 910 };
8ceb41d7 911 struct perf_data data = {
f5fc1412
JO
912 .mode = PERF_DATA_MODE_READ,
913 };
a635fc51
ACM
914 int ret = hists__init();
915
916 if (ret < 0)
917 return ret;
53cb8bc2 918
ecc4c561
ACM
919 ret = perf_config(report__config, &report);
920 if (ret)
921 return ret;
00c7e1f1 922
655000e7 923 argc = parse_options(argc, argv, options, report_usage, 0);
b3f38fc2
NK
924 if (argc) {
925 /*
926 * Special case: if there's an argument left then assume that
927 * it's a symbol filter:
928 */
929 if (argc > 1)
930 usage_with_options(report_usage, options);
931
932 report.symbol_filter_str = argv[0];
933 }
655000e7 934
27fafab5
NK
935 if (quiet)
936 perf_quiet_option();
937
36c8bb56
LZ
938 if (symbol_conf.vmlinux_name &&
939 access(symbol_conf.vmlinux_name, R_OK)) {
940 pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
941 return -EINVAL;
942 }
943 if (symbol_conf.kallsyms_name &&
944 access(symbol_conf.kallsyms_name, R_OK)) {
945 pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
946 return -EINVAL;
947 }
948
fa372aae 949 if (report.use_stdio)
8b9e74eb 950 use_browser = 0;
fa372aae 951 else if (report.use_tui)
8b9e74eb 952 use_browser = 1;
c31a9457
PE
953 else if (report.use_gtk)
954 use_browser = 2;
8b9e74eb 955
fa372aae 956 if (report.inverted_callchain)
d797fdc5 957 callchain_param.order = ORDER_CALLER;
792aeafa
NK
958 if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
959 callchain_param.order = ORDER_CALLER;
d797fdc5 960
188bb5e2
AH
961 if (itrace_synth_opts.callchain &&
962 (int)itrace_synth_opts.callchain_sz > report.max_stack)
963 report.max_stack = itrace_synth_opts.callchain_sz;
964
70cb4e96 965 if (!input_name || !strlen(input_name)) {
efad1415 966 if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
70cb4e96 967 input_name = "-";
efad1415 968 else
70cb4e96 969 input_name = "perf.data";
efad1415 970 }
ad0de097 971
eae8ad80
JO
972 data.file.path = input_name;
973 data.force = symbol_conf.force;
f5fc1412 974
ad0de097 975repeat:
8ceb41d7 976 session = perf_session__new(&data, false, &report.tool);
993ac88d 977 if (session == NULL)
52e02834 978 return -1;
993ac88d 979
94786b67
JO
980 if (report.queue_size) {
981 ordered_events__set_alloc_size(&session->ordered_events,
982 report.queue_size);
983 }
984
520a2ebc
AH
985 session->itrace_synth_opts = &itrace_synth_opts;
986
993ac88d
SE
987 report.session = session;
988
989 has_br_stack = perf_header__has_feat(&session->header,
990 HEADER_BRANCH_STACK);
efad1415 991
fb9fab66
AH
992 if (itrace_synth_opts.last_branch)
993 has_br_stack = true;
994
f9a7be7c
JY
995 if (has_br_stack && branch_call_mode)
996 symbol_conf.show_branchflag_count = true;
997
2d78b189
JY
998 memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat));
999
fa94c36c
AK
1000 /*
1001 * Branch mode is a tristate:
1002 * -1 means default, so decide based on the file having branch data.
1003 * 0/1 means the user chose a mode.
1004 */
1005 if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) &&
fefd2d96 1006 !branch_call_mode) {
55369fc1 1007 sort__mode = SORT_MODE__BRANCH;
793aaaab
NK
1008 symbol_conf.cumulate_callchain = false;
1009 }
fa94c36c 1010 if (branch_call_mode) {
09a6a1b0 1011 callchain_param.key = CCKEY_ADDRESS;
fa94c36c
AK
1012 callchain_param.branch_callstack = 1;
1013 symbol_conf.use_callchain = true;
1014 callchain_register_param(&callchain_param);
1015 if (sort_order == NULL)
1016 sort_order = "srcline,symbol,dso";
1017 }
993ac88d 1018
f4f7e28d 1019 if (report.mem_mode) {
55369fc1 1020 if (sort__mode == SORT_MODE__BRANCH) {
a4210141 1021 pr_err("branch and mem mode incompatible\n");
f4f7e28d
SE
1022 goto error;
1023 }
afab87b9 1024 sort__mode = SORT_MODE__MEMORY;
793aaaab 1025 symbol_conf.cumulate_callchain = false;
f4f7e28d 1026 }
a68c2c58 1027
4251446d
NK
1028 if (symbol_conf.report_hierarchy) {
1029 /* disable incompatible options */
4251446d
NK
1030 symbol_conf.cumulate_callchain = false;
1031
1032 if (field_order) {
1033 pr_err("Error: --hierarchy and --fields options cannot be used together\n");
1034 parse_options_usage(report_usage, options, "F", 1);
1035 parse_options_usage(NULL, options, "hierarchy", 0);
1036 goto error;
1037 }
1038
52225036 1039 perf_hpp_list.need_collapse = true;
4251446d
NK
1040 }
1041
b138f42e
NK
1042 /* Force tty output for header output and per-thread stat. */
1043 if (report.header || report.header_only || report.show_threads)
5cfe2c82 1044 use_browser = 0;
114f709e
DCC
1045 if (report.header || report.header_only)
1046 report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
1047 if (report.show_full_info)
1048 report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
5cfe2c82 1049
4bceffbc
NK
1050 if (strcmp(input_name, "-") != 0)
1051 setup_browser(true);
22af969e 1052 else
4bceffbc 1053 use_browser = 0;
4bceffbc 1054
013f61e1
JY
1055 if ((last_key != K_SWITCH_INPUT_DATA) &&
1056 (setup_sorting(session->evlist) < 0)) {
9887804d
JO
1057 if (sort_order)
1058 parse_options_usage(report_usage, options, "s", 1);
1059 if (field_order)
1060 parse_options_usage(sort_order ? NULL : report_usage,
1061 options, "F", 1);
1062 goto error;
1063 }
1064
27fafab5 1065 if ((report.header || report.header_only) && !quiet) {
5cfe2c82
JO
1066 perf_session__fprintf_info(session, stdout,
1067 report.show_full_info);
07a716ff
TS
1068 if (report.header_only) {
1069 ret = 0;
1070 goto error;
1071 }
27fafab5 1072 } else if (use_browser == 0 && !quiet) {
5cfe2c82
JO
1073 fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
1074 stdout);
1075 }
1076
ef7b93a1 1077 /*
6692c262 1078 * Only in the TUI browser we are doing integrated annotation,
ef7b93a1
ACM
1079 * so don't allocate extra space that won't be used in the stdio
1080 * implementation.
1081 */
b9ce0c99 1082 if (ui__has_annotation()) {
b01141f4
ACM
1083 ret = symbol__annotation_init();
1084 if (ret < 0)
1085 goto error;
80d50cae
ACM
1086 /*
1087 * For searching by name on the "Browse map details".
1088 * providing it only in verbose mode not to bloat too
1089 * much struct symbol.
1090 */
bb963e16 1091 if (verbose > 0) {
80d50cae
ACM
1092 /*
1093 * XXX: Need to provide a less kludgy way to ask for
1094 * more space per symbol, the u32 is for the index on
1095 * the ui browser.
1096 * See symbol__browser_index.
1097 */
1098 symbol_conf.priv_size += sizeof(u32);
1099 symbol_conf.sort_by_name = true;
1100 }
1101 }
655000e7 1102
0a7e6d1b 1103 if (symbol__init(&session->header.env) < 0)
993ac88d 1104 goto error;
53cb8bc2 1105
46690a80
DA
1106 if (perf_time__parse_str(&report.ptime, report.time_str) != 0) {
1107 pr_err("Invalid time string\n");
1108 return -EINVAL;
1109 }
1110
08e71542 1111 sort__setup_elide(stdout);
25903407 1112
993ac88d 1113 ret = __cmd_report(&report);
ad0de097
FT
1114 if (ret == K_SWITCH_INPUT_DATA) {
1115 perf_session__delete(session);
013f61e1 1116 last_key = K_SWITCH_INPUT_DATA;
ad0de097
FT
1117 goto repeat;
1118 } else
1119 ret = 0;
1120
993ac88d
SE
1121error:
1122 perf_session__delete(session);
1123 return ret;
53cb8bc2 1124}