]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - tools/perf/builtin-report.c
perf symbols: Adopt the strlists for dso, comm
[mirror_ubuntu-eoan-kernel.git] / tools / perf / builtin-report.c
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 */
8 #include "builtin.h"
9
10 #include "util/util.h"
11
12 #include "util/color.h"
13 #include <linux/list.h>
14 #include "util/cache.h"
15 #include <linux/rbtree.h>
16 #include "util/symbol.h"
17 #include "util/string.h"
18 #include "util/callchain.h"
19 #include "util/strlist.h"
20 #include "util/values.h"
21
22 #include "perf.h"
23 #include "util/debug.h"
24 #include "util/header.h"
25 #include "util/session.h"
26
27 #include "util/parse-options.h"
28 #include "util/parse-events.h"
29
30 #include "util/thread.h"
31 #include "util/sort.h"
32 #include "util/hist.h"
33
34 static char const *input_name = "perf.data";
35
36 static int force;
37 static bool use_callchain;
38
39 static int show_nr_samples;
40
41 static int show_threads;
42 static struct perf_read_values show_threads_values;
43
44 static char default_pretty_printing_style[] = "normal";
45 static char *pretty_printing_style = default_pretty_printing_style;
46
47 static int exclude_other = 1;
48
49 static char callchain_default_opt[] = "fractal,0.5";
50
51 static size_t
52 callchain__fprintf_left_margin(FILE *fp, int left_margin)
53 {
54 int i;
55 int ret;
56
57 ret = fprintf(fp, " ");
58
59 for (i = 0; i < left_margin; i++)
60 ret += fprintf(fp, " ");
61
62 return ret;
63 }
64
65 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
66 int left_margin)
67 {
68 int i;
69 size_t ret = 0;
70
71 ret += callchain__fprintf_left_margin(fp, left_margin);
72
73 for (i = 0; i < depth; i++)
74 if (depth_mask & (1 << i))
75 ret += fprintf(fp, "| ");
76 else
77 ret += fprintf(fp, " ");
78
79 ret += fprintf(fp, "\n");
80
81 return ret;
82 }
83 static size_t
84 ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, int depth,
85 int depth_mask, int count, u64 total_samples,
86 int hits, int left_margin)
87 {
88 int i;
89 size_t ret = 0;
90
91 ret += callchain__fprintf_left_margin(fp, left_margin);
92 for (i = 0; i < depth; i++) {
93 if (depth_mask & (1 << i))
94 ret += fprintf(fp, "|");
95 else
96 ret += fprintf(fp, " ");
97 if (!count && i == depth - 1) {
98 double percent;
99
100 percent = hits * 100.0 / total_samples;
101 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
102 } else
103 ret += fprintf(fp, "%s", " ");
104 }
105 if (chain->sym)
106 ret += fprintf(fp, "%s\n", chain->sym->name);
107 else
108 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
109
110 return ret;
111 }
112
113 static struct symbol *rem_sq_bracket;
114 static struct callchain_list rem_hits;
115
116 static void init_rem_hits(void)
117 {
118 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
119 if (!rem_sq_bracket) {
120 fprintf(stderr, "Not enough memory to display remaining hits\n");
121 return;
122 }
123
124 strcpy(rem_sq_bracket->name, "[...]");
125 rem_hits.sym = rem_sq_bracket;
126 }
127
128 static size_t
129 __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
130 u64 total_samples, int depth, int depth_mask,
131 int left_margin)
132 {
133 struct rb_node *node, *next;
134 struct callchain_node *child;
135 struct callchain_list *chain;
136 int new_depth_mask = depth_mask;
137 u64 new_total;
138 u64 remaining;
139 size_t ret = 0;
140 int i;
141
142 if (callchain_param.mode == CHAIN_GRAPH_REL)
143 new_total = self->children_hit;
144 else
145 new_total = total_samples;
146
147 remaining = new_total;
148
149 node = rb_first(&self->rb_root);
150 while (node) {
151 u64 cumul;
152
153 child = rb_entry(node, struct callchain_node, rb_node);
154 cumul = cumul_hits(child);
155 remaining -= cumul;
156
157 /*
158 * The depth mask manages the output of pipes that show
159 * the depth. We don't want to keep the pipes of the current
160 * level for the last child of this depth.
161 * Except if we have remaining filtered hits. They will
162 * supersede the last child
163 */
164 next = rb_next(node);
165 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
166 new_depth_mask &= ~(1 << (depth - 1));
167
168 /*
169 * But we keep the older depth mask for the line seperator
170 * to keep the level link until we reach the last child
171 */
172 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
173 left_margin);
174 i = 0;
175 list_for_each_entry(chain, &child->val, list) {
176 if (chain->ip >= PERF_CONTEXT_MAX)
177 continue;
178 ret += ipchain__fprintf_graph(fp, chain, depth,
179 new_depth_mask, i++,
180 new_total,
181 cumul,
182 left_margin);
183 }
184 ret += __callchain__fprintf_graph(fp, child, new_total,
185 depth + 1,
186 new_depth_mask | (1 << depth),
187 left_margin);
188 node = next;
189 }
190
191 if (callchain_param.mode == CHAIN_GRAPH_REL &&
192 remaining && remaining != new_total) {
193
194 if (!rem_sq_bracket)
195 return ret;
196
197 new_depth_mask &= ~(1 << (depth - 1));
198
199 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
200 new_depth_mask, 0, new_total,
201 remaining, left_margin);
202 }
203
204 return ret;
205 }
206
207
208 static size_t
209 callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
210 u64 total_samples, int left_margin)
211 {
212 struct callchain_list *chain;
213 bool printed = false;
214 int i = 0;
215 int ret = 0;
216
217 list_for_each_entry(chain, &self->val, list) {
218 if (chain->ip >= PERF_CONTEXT_MAX)
219 continue;
220
221 if (!i++ && sort__first_dimension == SORT_SYM)
222 continue;
223
224 if (!printed) {
225 ret += callchain__fprintf_left_margin(fp, left_margin);
226 ret += fprintf(fp, "|\n");
227 ret += callchain__fprintf_left_margin(fp, left_margin);
228 ret += fprintf(fp, "---");
229
230 left_margin += 3;
231 printed = true;
232 } else
233 ret += callchain__fprintf_left_margin(fp, left_margin);
234
235 if (chain->sym)
236 ret += fprintf(fp, " %s\n", chain->sym->name);
237 else
238 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
239 }
240
241 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
242
243 return ret;
244 }
245
246 static size_t
247 callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
248 u64 total_samples)
249 {
250 struct callchain_list *chain;
251 size_t ret = 0;
252
253 if (!self)
254 return 0;
255
256 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
257
258
259 list_for_each_entry(chain, &self->val, list) {
260 if (chain->ip >= PERF_CONTEXT_MAX)
261 continue;
262 if (chain->sym)
263 ret += fprintf(fp, " %s\n", chain->sym->name);
264 else
265 ret += fprintf(fp, " %p\n",
266 (void *)(long)chain->ip);
267 }
268
269 return ret;
270 }
271
272 static size_t
273 hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
274 u64 total_samples, int left_margin)
275 {
276 struct rb_node *rb_node;
277 struct callchain_node *chain;
278 size_t ret = 0;
279
280 rb_node = rb_first(&self->sorted_chain);
281 while (rb_node) {
282 double percent;
283
284 chain = rb_entry(rb_node, struct callchain_node, rb_node);
285 percent = chain->hit * 100.0 / total_samples;
286 switch (callchain_param.mode) {
287 case CHAIN_FLAT:
288 ret += percent_color_fprintf(fp, " %6.2f%%\n",
289 percent);
290 ret += callchain__fprintf_flat(fp, chain, total_samples);
291 break;
292 case CHAIN_GRAPH_ABS: /* Falldown */
293 case CHAIN_GRAPH_REL:
294 ret += callchain__fprintf_graph(fp, chain, total_samples,
295 left_margin);
296 case CHAIN_NONE:
297 default:
298 break;
299 }
300 ret += fprintf(fp, "\n");
301 rb_node = rb_next(rb_node);
302 }
303
304 return ret;
305 }
306
307 static size_t hist_entry__fprintf(FILE *fp, struct hist_entry *self,
308 struct perf_session *session,
309 u64 total_samples)
310 {
311 struct sort_entry *se;
312 size_t ret;
313
314 if (exclude_other && !self->parent)
315 return 0;
316
317 if (total_samples)
318 ret = percent_color_fprintf(fp,
319 field_sep ? "%.2f" : " %6.2f%%",
320 (self->count * 100.0) / total_samples);
321 else
322 ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count);
323
324 if (show_nr_samples) {
325 if (field_sep)
326 fprintf(fp, "%c%lld", *field_sep, self->count);
327 else
328 fprintf(fp, "%11lld", self->count);
329 }
330
331 list_for_each_entry(se, &hist_entry__sort_list, list) {
332 if (se->elide)
333 continue;
334
335 fprintf(fp, "%s", field_sep ?: " ");
336 ret += se->print(fp, self, se->width ? *se->width : 0);
337 }
338
339 ret += fprintf(fp, "\n");
340
341 if (session->use_callchain) {
342 int left_margin = 0;
343
344 if (sort__first_dimension == SORT_COMM) {
345 se = list_first_entry(&hist_entry__sort_list, typeof(*se),
346 list);
347 left_margin = se->width ? *se->width : 0;
348 left_margin -= thread__comm_len(self->thread);
349 }
350
351 hist_entry_callchain__fprintf(fp, self, total_samples,
352 left_margin);
353 }
354
355 return ret;
356 }
357
358 /*
359 *
360 */
361
362 static void dso__calc_col_width(struct dso *self)
363 {
364 if (!symbol_conf.col_width_list_str && !field_sep &&
365 (!symbol_conf.dso_list ||
366 strlist__has_entry(symbol_conf.dso_list, self->name))) {
367 unsigned int slen = strlen(self->name);
368 if (slen > dsos__col_width)
369 dsos__col_width = slen;
370 }
371
372 self->slen_calculated = 1;
373 }
374
375 static void thread__comm_adjust(struct thread *self)
376 {
377 char *comm = self->comm;
378
379 if (!symbol_conf.col_width_list_str && !field_sep &&
380 (!symbol_conf.comm_list ||
381 strlist__has_entry(symbol_conf.comm_list, comm))) {
382 unsigned int slen = strlen(comm);
383
384 if (slen > comms__col_width) {
385 comms__col_width = slen;
386 threads__col_width = slen + 6;
387 }
388 }
389 }
390
391 static int thread__set_comm_adjust(struct thread *self, const char *comm)
392 {
393 int ret = thread__set_comm(self, comm);
394
395 if (ret)
396 return ret;
397
398 thread__comm_adjust(self);
399
400 return 0;
401 }
402
403 /*
404 * collect histogram counts
405 */
406
407 static int perf_session__add_hist_entry(struct perf_session *self,
408 struct addr_location *al,
409 struct ip_callchain *chain, u64 count)
410 {
411 struct symbol **syms = NULL, *parent = NULL;
412 bool hit;
413 struct hist_entry *he;
414
415 if ((sort__has_parent || self->use_callchain) && chain)
416 syms = perf_session__resolve_callchain(self, al->thread,
417 chain, &parent);
418 he = __perf_session__add_hist_entry(self, al, parent, count, &hit);
419 if (he == NULL)
420 return -ENOMEM;
421
422 if (hit)
423 he->count += count;
424
425 if (self->use_callchain) {
426 if (!hit)
427 callchain_init(&he->callchain);
428 append_chain(&he->callchain, chain, syms);
429 free(syms);
430 }
431
432 return 0;
433 }
434
435 static size_t perf_session__fprintf_hist_entries(struct perf_session *self,
436 u64 total_samples, FILE *fp)
437 {
438 struct hist_entry *pos;
439 struct sort_entry *se;
440 struct rb_node *nd;
441 size_t ret = 0;
442 unsigned int width;
443 char *col_width = symbol_conf.col_width_list_str;
444 int raw_printing_style;
445
446 raw_printing_style = !strcmp(pretty_printing_style, "raw");
447
448 init_rem_hits();
449
450 fprintf(fp, "# Samples: %Ld\n", (u64)total_samples);
451 fprintf(fp, "#\n");
452
453 fprintf(fp, "# Overhead");
454 if (show_nr_samples) {
455 if (field_sep)
456 fprintf(fp, "%cSamples", *field_sep);
457 else
458 fputs(" Samples ", fp);
459 }
460 list_for_each_entry(se, &hist_entry__sort_list, list) {
461 if (se->elide)
462 continue;
463 if (field_sep) {
464 fprintf(fp, "%c%s", *field_sep, se->header);
465 continue;
466 }
467 width = strlen(se->header);
468 if (se->width) {
469 if (symbol_conf.col_width_list_str) {
470 if (col_width) {
471 *se->width = atoi(col_width);
472 col_width = strchr(col_width, ',');
473 if (col_width)
474 ++col_width;
475 }
476 }
477 width = *se->width = max(*se->width, width);
478 }
479 fprintf(fp, " %*s", width, se->header);
480 }
481 fprintf(fp, "\n");
482
483 if (field_sep)
484 goto print_entries;
485
486 fprintf(fp, "# ........");
487 if (show_nr_samples)
488 fprintf(fp, " ..........");
489 list_for_each_entry(se, &hist_entry__sort_list, list) {
490 unsigned int i;
491
492 if (se->elide)
493 continue;
494
495 fprintf(fp, " ");
496 if (se->width)
497 width = *se->width;
498 else
499 width = strlen(se->header);
500 for (i = 0; i < width; i++)
501 fprintf(fp, ".");
502 }
503 fprintf(fp, "\n");
504
505 fprintf(fp, "#\n");
506
507 print_entries:
508 for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) {
509 pos = rb_entry(nd, struct hist_entry, rb_node);
510 ret += hist_entry__fprintf(fp, pos, self, total_samples);
511 }
512
513 if (sort_order == default_sort_order &&
514 parent_pattern == default_parent_pattern) {
515 fprintf(fp, "#\n");
516 fprintf(fp, "# (For a higher level overview, try: perf report --sort comm,dso)\n");
517 fprintf(fp, "#\n");
518 }
519 fprintf(fp, "\n");
520
521 free(rem_sq_bracket);
522
523 if (show_threads)
524 perf_read_values_display(fp, &show_threads_values,
525 raw_printing_style);
526
527 return ret;
528 }
529
530 static int validate_chain(struct ip_callchain *chain, event_t *event)
531 {
532 unsigned int chain_size;
533
534 chain_size = event->header.size;
535 chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
536
537 if (chain->nr*sizeof(u64) > chain_size)
538 return -1;
539
540 return 0;
541 }
542
543 static int process_sample_event(event_t *event, struct perf_session *session)
544 {
545 struct sample_data data;
546 int cpumode;
547 struct addr_location al;
548 struct thread *thread;
549
550 memset(&data, 0, sizeof(data));
551 data.period = 1;
552
553 event__parse_sample(event, session->sample_type, &data);
554
555 dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
556 event->header.misc,
557 data.pid, data.tid,
558 (void *)(long)data.ip,
559 (long long)data.period);
560
561 if (session->sample_type & PERF_SAMPLE_CALLCHAIN) {
562 unsigned int i;
563
564 dump_printf("... chain: nr:%Lu\n", data.callchain->nr);
565
566 if (validate_chain(data.callchain, event) < 0) {
567 pr_debug("call-chain problem with event, "
568 "skipping it.\n");
569 return 0;
570 }
571
572 if (dump_trace) {
573 for (i = 0; i < data.callchain->nr; i++)
574 dump_printf("..... %2d: %016Lx\n",
575 i, data.callchain->ips[i]);
576 }
577 }
578
579 thread = perf_session__findnew(session, data.pid);
580 if (thread == NULL) {
581 pr_debug("problem processing %d event, skipping it.\n",
582 event->header.type);
583 return -1;
584 }
585
586 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
587
588 if (symbol_conf.comm_list &&
589 !strlist__has_entry(symbol_conf.comm_list, thread->comm))
590 return 0;
591
592 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
593
594 thread__find_addr_location(thread, session, cpumode,
595 MAP__FUNCTION, data.ip, &al, NULL);
596 /*
597 * We have to do this here as we may have a dso with no symbol hit that
598 * has a name longer than the ones with symbols sampled.
599 */
600 if (al.map && !sort_dso.elide && !al.map->dso->slen_calculated)
601 dso__calc_col_width(al.map->dso);
602
603 if (symbol_conf.dso_list &&
604 (!al.map || !al.map->dso ||
605 !(strlist__has_entry(symbol_conf.dso_list, al.map->dso->short_name) ||
606 (al.map->dso->short_name != al.map->dso->long_name &&
607 strlist__has_entry(symbol_conf.dso_list, al.map->dso->long_name)))))
608 return 0;
609
610 if (symbol_conf.sym_list && al.sym &&
611 !strlist__has_entry(symbol_conf.sym_list, al.sym->name))
612 return 0;
613
614 if (perf_session__add_hist_entry(session, &al, data.callchain, data.period)) {
615 pr_debug("problem incrementing symbol count, skipping event\n");
616 return -1;
617 }
618
619 session->events_stats.total += data.period;
620 return 0;
621 }
622
623 static int process_comm_event(event_t *event, struct perf_session *session)
624 {
625 struct thread *thread = perf_session__findnew(session, event->comm.pid);
626
627 dump_printf(": %s:%d\n", event->comm.comm, event->comm.pid);
628
629 if (thread == NULL ||
630 thread__set_comm_adjust(thread, event->comm.comm)) {
631 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
632 return -1;
633 }
634
635 return 0;
636 }
637
638 static int process_read_event(event_t *event, struct perf_session *session __used)
639 {
640 struct perf_event_attr *attr;
641
642 attr = perf_header__find_attr(event->read.id, &session->header);
643
644 if (show_threads) {
645 const char *name = attr ? __event_name(attr->type, attr->config)
646 : "unknown";
647 perf_read_values_add_value(&show_threads_values,
648 event->read.pid, event->read.tid,
649 event->read.id,
650 name,
651 event->read.value);
652 }
653
654 dump_printf(": %d %d %s %Lu\n", event->read.pid, event->read.tid,
655 attr ? __event_name(attr->type, attr->config) : "FAIL",
656 event->read.value);
657
658 return 0;
659 }
660
661 static int sample_type_check(struct perf_session *session)
662 {
663 if (!(session->sample_type & PERF_SAMPLE_CALLCHAIN)) {
664 if (sort__has_parent) {
665 fprintf(stderr, "selected --sort parent, but no"
666 " callchain data. Did you call"
667 " perf record without -g?\n");
668 return -1;
669 }
670 if (session->use_callchain) {
671 fprintf(stderr, "selected -g but no callchain data."
672 " Did you call perf record without"
673 " -g?\n");
674 return -1;
675 }
676 } else if (callchain_param.mode != CHAIN_NONE && !session->use_callchain) {
677 session->use_callchain = true;
678 if (register_callchain_param(&callchain_param) < 0) {
679 fprintf(stderr, "Can't register callchain"
680 " params\n");
681 return -1;
682 }
683 }
684
685 return 0;
686 }
687
688 static struct perf_event_ops event_ops = {
689 .process_sample_event = process_sample_event,
690 .process_mmap_event = event__process_mmap,
691 .process_comm_event = process_comm_event,
692 .process_exit_event = event__process_task,
693 .process_fork_event = event__process_task,
694 .process_lost_event = event__process_lost,
695 .process_read_event = process_read_event,
696 .sample_type_check = sample_type_check,
697 };
698
699
700 static int __cmd_report(void)
701 {
702 int ret;
703 struct perf_session *session;
704
705 session = perf_session__new(input_name, O_RDONLY, force);
706 if (session == NULL)
707 return -ENOMEM;
708
709 session->use_callchain = use_callchain;
710
711 if (show_threads)
712 perf_read_values_init(&show_threads_values);
713
714 ret = perf_session__process_events(session, &event_ops);
715 if (ret)
716 goto out_delete;
717
718 if (dump_trace) {
719 event__print_totals();
720 goto out_delete;
721 }
722
723 if (verbose > 3)
724 perf_session__fprintf(session, stdout);
725
726 if (verbose > 2)
727 dsos__fprintf(stdout);
728
729 perf_session__collapse_resort(session);
730 perf_session__output_resort(session, session->events_stats.total);
731 perf_session__fprintf_hist_entries(session, session->events_stats.total, stdout);
732
733 if (show_threads)
734 perf_read_values_destroy(&show_threads_values);
735 out_delete:
736 perf_session__delete(session);
737 return ret;
738 }
739
740 static int
741 parse_callchain_opt(const struct option *opt __used, const char *arg,
742 int unset __used)
743 {
744 char *tok;
745 char *endptr;
746
747 use_callchain = true;
748
749 if (!arg)
750 return 0;
751
752 tok = strtok((char *)arg, ",");
753 if (!tok)
754 return -1;
755
756 /* get the output mode */
757 if (!strncmp(tok, "graph", strlen(arg)))
758 callchain_param.mode = CHAIN_GRAPH_ABS;
759
760 else if (!strncmp(tok, "flat", strlen(arg)))
761 callchain_param.mode = CHAIN_FLAT;
762
763 else if (!strncmp(tok, "fractal", strlen(arg)))
764 callchain_param.mode = CHAIN_GRAPH_REL;
765
766 else if (!strncmp(tok, "none", strlen(arg))) {
767 callchain_param.mode = CHAIN_NONE;
768 use_callchain = true;
769
770 return 0;
771 }
772
773 else
774 return -1;
775
776 /* get the min percentage */
777 tok = strtok(NULL, ",");
778 if (!tok)
779 goto setup;
780
781 callchain_param.min_percent = strtod(tok, &endptr);
782 if (tok == endptr)
783 return -1;
784
785 setup:
786 if (register_callchain_param(&callchain_param) < 0) {
787 fprintf(stderr, "Can't register callchain params\n");
788 return -1;
789 }
790 return 0;
791 }
792
793 //static const char * const report_usage[] = {
794 const char * const report_usage[] = {
795 "perf report [<options>] <command>",
796 NULL
797 };
798
799 static const struct option options[] = {
800 OPT_STRING('i', "input", &input_name, "file",
801 "input file name"),
802 OPT_BOOLEAN('v', "verbose", &verbose,
803 "be more verbose (show symbol address, etc)"),
804 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
805 "dump raw trace in ASCII"),
806 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
807 "file", "vmlinux pathname"),
808 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
809 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
810 "load module symbols - WARNING: use only with -k and LIVE kernel"),
811 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
812 "Show a column with the number of samples"),
813 OPT_BOOLEAN('T', "threads", &show_threads,
814 "Show per-thread event counters"),
815 OPT_STRING(0, "pretty", &pretty_printing_style, "key",
816 "pretty printing style key: normal raw"),
817 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
818 "sort by key(s): pid, comm, dso, symbol, parent"),
819 OPT_BOOLEAN('P', "full-paths", &event_ops.full_paths,
820 "Don't shorten the pathnames taking into account the cwd"),
821 OPT_STRING('p', "parent", &parent_pattern, "regex",
822 "regex filter to identify parent, see: '--sort parent'"),
823 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
824 "Only display entries with parent-match"),
825 OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent",
826 "Display callchains using output_type and min percent threshold. "
827 "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt),
828 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
829 "only consider symbols in these dsos"),
830 OPT_STRING('C', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
831 "only consider symbols in these comms"),
832 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
833 "only consider these symbols"),
834 OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
835 "width[,width...]",
836 "don't try to adjust column width, use these fixed values"),
837 OPT_STRING('t', "field-separator", &field_sep, "separator",
838 "separator for columns, no spaces will be added between "
839 "columns '.' is reserved."),
840 OPT_END()
841 };
842
843 static void sort_entry__setup_elide(struct sort_entry *self,
844 struct strlist *list,
845 const char *list_name, FILE *fp)
846 {
847 if (list && strlist__nr_entries(list) == 1) {
848 fprintf(fp, "# %s: %s\n", list_name, strlist__entry(list, 0)->s);
849 self->elide = true;
850 }
851 }
852
853 int cmd_report(int argc, const char **argv, const char *prefix __used)
854 {
855 argc = parse_options(argc, argv, options, report_usage, 0);
856
857 setup_pager();
858
859 if (symbol__init() < 0)
860 return -1;
861
862 setup_sorting(report_usage, options);
863
864 if (parent_pattern != default_parent_pattern) {
865 sort_dimension__add("parent");
866 sort_parent.elide = 1;
867 } else
868 exclude_other = 0;
869
870 /*
871 * Any (unrecognized) arguments left?
872 */
873 if (argc)
874 usage_with_options(report_usage, options);
875
876 sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso", stdout);
877 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout);
878 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout);
879
880 if (field_sep && *field_sep == '.') {
881 fputs("'.' is the only non valid --field-separator argument\n",
882 stderr);
883 exit(129);
884 }
885
886 return __cmd_report();
887 }