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