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.
10 #include "util/util.h"
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"
23 #include "util/debug.h"
24 #include "util/header.h"
26 #include "util/parse-options.h"
27 #include "util/parse-events.h"
29 #include "util/thread.h"
30 #include "util/sort.h"
31 #include "util/hist.h"
33 static char const *input_name = "perf.data";
35 static char *dso_list_str, *comm_list_str, *sym_list_str,
37 static struct strlist *dso_list, *comm_list, *sym_list;
42 static int full_paths;
43 static int show_nr_samples;
45 static int show_threads;
46 static struct perf_read_values show_threads_values;
48 static char default_pretty_printing_style[] = "normal";
49 static char *pretty_printing_style = default_pretty_printing_style;
51 static unsigned long page_size;
52 static unsigned long mmap_window = 32;
54 static int exclude_other = 1;
56 static char callchain_default_opt[] = "fractal,0.5";
58 static char __cwd[PATH_MAX];
59 static char *cwd = __cwd;
62 static struct rb_root threads;
63 static struct thread *last_match;
65 static struct perf_header *header;
67 static u64 sample_type;
69 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask)
74 ret += fprintf(fp, "%s", " ");
76 for (i = 0; i < depth; i++)
77 if (depth_mask & (1 << i))
78 ret += fprintf(fp, "| ");
80 ret += fprintf(fp, " ");
82 ret += fprintf(fp, "\n");
87 ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, int depth,
88 int depth_mask, int count, u64 total_samples,
94 ret += fprintf(fp, "%s", " ");
95 for (i = 0; i < depth; i++) {
96 if (depth_mask & (1 << i))
97 ret += fprintf(fp, "|");
99 ret += fprintf(fp, " ");
100 if (!count && i == depth - 1) {
103 percent = hits * 100.0 / total_samples;
104 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
106 ret += fprintf(fp, "%s", " ");
109 ret += fprintf(fp, "%s\n", chain->sym->name);
111 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
116 static struct symbol *rem_sq_bracket;
117 static struct callchain_list rem_hits;
119 static void init_rem_hits(void)
121 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
122 if (!rem_sq_bracket) {
123 fprintf(stderr, "Not enough memory to display remaining hits\n");
127 strcpy(rem_sq_bracket->name, "[...]");
128 rem_hits.sym = rem_sq_bracket;
132 callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
133 u64 total_samples, int depth, int depth_mask)
135 struct rb_node *node, *next;
136 struct callchain_node *child;
137 struct callchain_list *chain;
138 int new_depth_mask = depth_mask;
144 if (callchain_param.mode == CHAIN_GRAPH_REL)
145 new_total = self->children_hit;
147 new_total = total_samples;
149 remaining = new_total;
151 node = rb_first(&self->rb_root);
155 child = rb_entry(node, struct callchain_node, rb_node);
156 cumul = cumul_hits(child);
160 * The depth mask manages the output of pipes that show
161 * the depth. We don't want to keep the pipes of the current
162 * level for the last child of this depth.
163 * Except if we have remaining filtered hits. They will
164 * supersede the last child
166 next = rb_next(node);
167 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
168 new_depth_mask &= ~(1 << (depth - 1));
171 * But we keep the older depth mask for the line seperator
172 * to keep the level link until we reach the last child
174 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask);
176 list_for_each_entry(chain, &child->val, list) {
177 if (chain->ip >= PERF_CONTEXT_MAX)
179 ret += ipchain__fprintf_graph(fp, chain, depth,
184 ret += callchain__fprintf_graph(fp, child, new_total,
186 new_depth_mask | (1 << depth));
190 if (callchain_param.mode == CHAIN_GRAPH_REL &&
191 remaining && remaining != new_total) {
196 new_depth_mask &= ~(1 << (depth - 1));
198 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
199 new_depth_mask, 0, new_total,
207 callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
210 struct callchain_list *chain;
216 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
219 list_for_each_entry(chain, &self->val, list) {
220 if (chain->ip >= PERF_CONTEXT_MAX)
223 ret += fprintf(fp, " %s\n", chain->sym->name);
225 ret += fprintf(fp, " %p\n",
226 (void *)(long)chain->ip);
233 hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
236 struct rb_node *rb_node;
237 struct callchain_node *chain;
240 rb_node = rb_first(&self->sorted_chain);
244 chain = rb_entry(rb_node, struct callchain_node, rb_node);
245 percent = chain->hit * 100.0 / total_samples;
246 switch (callchain_param.mode) {
248 ret += percent_color_fprintf(fp, " %6.2f%%\n",
250 ret += callchain__fprintf_flat(fp, chain, total_samples);
252 case CHAIN_GRAPH_ABS: /* Falldown */
253 case CHAIN_GRAPH_REL:
254 ret += callchain__fprintf_graph(fp, chain,
255 total_samples, 1, 1);
260 ret += fprintf(fp, "\n");
261 rb_node = rb_next(rb_node);
268 hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
270 struct sort_entry *se;
273 if (exclude_other && !self->parent)
277 ret = percent_color_fprintf(fp,
278 field_sep ? "%.2f" : " %6.2f%%",
279 (self->count * 100.0) / total_samples);
281 ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count);
283 if (show_nr_samples) {
285 fprintf(fp, "%c%lld", *field_sep, self->count);
287 fprintf(fp, "%11lld", self->count);
290 list_for_each_entry(se, &hist_entry__sort_list, list) {
294 fprintf(fp, "%s", field_sep ?: " ");
295 ret += se->print(fp, self, se->width ? *se->width : 0);
298 ret += fprintf(fp, "\n");
301 hist_entry_callchain__fprintf(fp, self, total_samples);
310 static void dso__calc_col_width(struct dso *self)
312 if (!col_width_list_str && !field_sep &&
313 (!dso_list || strlist__has_entry(dso_list, self->name))) {
314 unsigned int slen = strlen(self->name);
315 if (slen > dsos__col_width)
316 dsos__col_width = slen;
319 self->slen_calculated = 1;
322 static void thread__comm_adjust(struct thread *self)
324 char *comm = self->comm;
326 if (!col_width_list_str && !field_sep &&
327 (!comm_list || strlist__has_entry(comm_list, comm))) {
328 unsigned int slen = strlen(comm);
330 if (slen > comms__col_width) {
331 comms__col_width = slen;
332 threads__col_width = slen + 6;
337 static int thread__set_comm_adjust(struct thread *self, const char *comm)
339 int ret = thread__set_comm(self, comm);
344 thread__comm_adjust(self);
350 static struct symbol *
351 resolve_symbol(struct thread *thread, struct map **mapp, u64 *ipp)
353 struct map *map = mapp ? *mapp : NULL;
362 map = thread__find_map(thread, ip);
365 * We have to do this here as we may have a dso
366 * with no symbol hit that has a name longer than
367 * the ones with symbols sampled.
369 if (!sort_dso.elide && !map->dso->slen_calculated)
370 dso__calc_col_width(map->dso);
375 ip = map->map_ip(map, ip);
378 * If this is outside of all known maps,
379 * and is a negative address, try to look it
380 * up in the kernel dso, as it might be a
381 * vsyscall or vdso (which executes in user-mode).
383 * XXX This is nasty, we should have a symbol list in
384 * the "[vdso]" dso, but for now lets use the old
385 * trick of looking in the whole kernel symbol list.
387 if ((long long)ip < 0)
388 return kernel_maps__find_symbol(ip, mapp);
390 dump_printf(" ...... dso: %s\n",
391 map ? map->dso->long_name : "<not found>");
392 dump_printf(" ...... map: %Lx -> %Lx\n", *ipp, ip);
395 return map ? map->dso->find_symbol(map->dso, ip) : NULL;
398 static int call__match(struct symbol *sym)
400 if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0))
406 static struct symbol **resolve_callchain(struct thread *thread, struct map *map,
407 struct ip_callchain *chain,
408 struct symbol **parent)
410 u64 context = PERF_CONTEXT_MAX;
411 struct symbol **syms = NULL;
415 syms = calloc(chain->nr, sizeof(*syms));
417 fprintf(stderr, "Can't allocate memory for symbols\n");
422 for (i = 0; i < chain->nr; i++) {
423 u64 ip = chain->ips[i];
424 struct symbol *sym = NULL;
426 if (ip >= PERF_CONTEXT_MAX) {
432 case PERF_CONTEXT_HV:
434 case PERF_CONTEXT_KERNEL:
435 sym = kernel_maps__find_symbol(ip, &map);
438 sym = resolve_symbol(thread, &map, &ip);
443 if (sort__has_parent && !*parent && call__match(sym))
455 * collect histogram counts
459 hist_entry__add(struct thread *thread, struct map *map,
460 struct symbol *sym, u64 ip, struct ip_callchain *chain,
461 char level, u64 count)
463 struct symbol **syms = NULL, *parent = NULL;
465 struct hist_entry *he;
467 if ((sort__has_parent || callchain) && chain)
468 syms = resolve_callchain(thread, map, chain, &parent);
470 he = __hist_entry__add(thread, map, sym, parent,
471 ip, count, level, &hit);
480 callchain_init(&he->callchain);
481 append_chain(&he->callchain, chain, syms);
488 static size_t output__fprintf(FILE *fp, u64 total_samples)
490 struct hist_entry *pos;
491 struct sort_entry *se;
495 char *col_width = col_width_list_str;
496 int raw_printing_style;
498 raw_printing_style = !strcmp(pretty_printing_style, "raw");
502 fprintf(fp, "# Samples: %Ld\n", (u64)total_samples);
505 fprintf(fp, "# Overhead");
506 if (show_nr_samples) {
508 fprintf(fp, "%cSamples", *field_sep);
510 fputs(" Samples ", fp);
512 list_for_each_entry(se, &hist_entry__sort_list, list) {
516 fprintf(fp, "%c%s", *field_sep, se->header);
519 width = strlen(se->header);
521 if (col_width_list_str) {
523 *se->width = atoi(col_width);
524 col_width = strchr(col_width, ',');
529 width = *se->width = max(*se->width, width);
531 fprintf(fp, " %*s", width, se->header);
538 fprintf(fp, "# ........");
540 fprintf(fp, " ..........");
541 list_for_each_entry(se, &hist_entry__sort_list, list) {
551 width = strlen(se->header);
552 for (i = 0; i < width; i++)
560 for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) {
561 pos = rb_entry(nd, struct hist_entry, rb_node);
562 ret += hist_entry__fprintf(fp, pos, total_samples);
565 if (sort_order == default_sort_order &&
566 parent_pattern == default_parent_pattern) {
568 fprintf(fp, "# (For a higher level overview, try: perf report --sort comm,dso)\n");
573 free(rem_sq_bracket);
576 perf_read_values_display(fp, &show_threads_values,
582 static int validate_chain(struct ip_callchain *chain, event_t *event)
584 unsigned int chain_size;
586 chain_size = event->header.size;
587 chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
589 if (chain->nr*sizeof(u64) > chain_size)
596 process_sample_event(event_t *event, unsigned long offset, unsigned long head)
599 struct symbol *sym = NULL;
600 struct thread *thread;
601 u64 ip = event->ip.ip;
603 struct map *map = NULL;
604 void *more_data = event->ip.__more_data;
605 struct ip_callchain *chain = NULL;
608 thread = threads__findnew(event->ip.pid, &threads, &last_match);
610 if (sample_type & PERF_SAMPLE_PERIOD) {
611 period = *(u64 *)more_data;
612 more_data += sizeof(u64);
615 dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n",
616 (void *)(offset + head),
617 (void *)(long)(event->header.size),
619 event->ip.pid, event->ip.tid,
623 if (sample_type & PERF_SAMPLE_CALLCHAIN) {
626 chain = (void *)more_data;
628 dump_printf("... chain: nr:%Lu\n", chain->nr);
630 if (validate_chain(chain, event) < 0) {
631 eprintf("call-chain problem with event, skipping it.\n");
636 for (i = 0; i < chain->nr; i++)
637 dump_printf("..... %2d: %016Lx\n", i, chain->ips[i]);
641 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
643 if (thread == NULL) {
644 eprintf("problem processing %d event, skipping it.\n",
649 if (comm_list && !strlist__has_entry(comm_list, thread->comm))
652 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
654 if (cpumode == PERF_RECORD_MISC_KERNEL) {
656 sym = kernel_maps__find_symbol(ip, &map);
657 dump_printf(" ...... dso: %s\n",
658 map ? map->dso->long_name : "<not found>");
659 } else if (cpumode == PERF_RECORD_MISC_USER) {
661 sym = resolve_symbol(thread, &map, &ip);
665 dump_printf(" ...... dso: [hypervisor]\n");
669 (!map || !map->dso ||
670 !(strlist__has_entry(dso_list, map->dso->short_name) ||
671 (map->dso->short_name != map->dso->long_name &&
672 strlist__has_entry(dso_list, map->dso->long_name)))))
675 if (sym_list && sym && !strlist__has_entry(sym_list, sym->name))
678 if (hist_entry__add(thread, map, sym, ip,
679 chain, level, period)) {
680 eprintf("problem incrementing symbol count, skipping event\n");
690 process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
692 struct thread *thread;
693 struct map *map = map__new(&event->mmap, cwd, cwdlen);
695 thread = threads__findnew(event->mmap.pid, &threads, &last_match);
697 dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
698 (void *)(offset + head),
699 (void *)(long)(event->header.size),
702 (void *)(long)event->mmap.start,
703 (void *)(long)event->mmap.len,
704 (void *)(long)event->mmap.pgoff,
705 event->mmap.filename);
707 if (thread == NULL || map == NULL) {
708 dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
712 thread__insert_map(thread, map);
719 process_comm_event(event_t *event, unsigned long offset, unsigned long head)
721 struct thread *thread;
723 thread = threads__findnew(event->comm.pid, &threads, &last_match);
725 dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n",
726 (void *)(offset + head),
727 (void *)(long)(event->header.size),
728 event->comm.comm, event->comm.pid);
730 if (thread == NULL ||
731 thread__set_comm_adjust(thread, event->comm.comm)) {
732 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
741 process_task_event(event_t *event, unsigned long offset, unsigned long head)
743 struct thread *thread;
744 struct thread *parent;
746 thread = threads__findnew(event->fork.pid, &threads, &last_match);
747 parent = threads__findnew(event->fork.ppid, &threads, &last_match);
749 dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n",
750 (void *)(offset + head),
751 (void *)(long)(event->header.size),
752 event->header.type == PERF_RECORD_FORK ? "FORK" : "EXIT",
753 event->fork.pid, event->fork.tid,
754 event->fork.ppid, event->fork.ptid);
757 * A thread clone will have the same PID for both
760 if (thread == parent)
763 if (event->header.type == PERF_RECORD_EXIT)
766 if (!thread || !parent || thread__fork(thread, parent)) {
767 dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
776 process_lost_event(event_t *event, unsigned long offset, unsigned long head)
778 dump_printf("%p [%p]: PERF_RECORD_LOST: id:%Ld: lost:%Ld\n",
779 (void *)(offset + head),
780 (void *)(long)(event->header.size),
784 total_lost += event->lost.lost;
790 process_read_event(event_t *event, unsigned long offset, unsigned long head)
792 struct perf_event_attr *attr;
794 attr = perf_header__find_attr(event->read.id, header);
797 const char *name = attr ? __event_name(attr->type, attr->config)
799 perf_read_values_add_value(&show_threads_values,
800 event->read.pid, event->read.tid,
806 dump_printf("%p [%p]: PERF_RECORD_READ: %d %d %s %Lu\n",
807 (void *)(offset + head),
808 (void *)(long)(event->header.size),
811 attr ? __event_name(attr->type, attr->config)
819 process_event(event_t *event, unsigned long offset, unsigned long head)
823 switch (event->header.type) {
824 case PERF_RECORD_SAMPLE:
825 return process_sample_event(event, offset, head);
827 case PERF_RECORD_MMAP:
828 return process_mmap_event(event, offset, head);
830 case PERF_RECORD_COMM:
831 return process_comm_event(event, offset, head);
833 case PERF_RECORD_FORK:
834 case PERF_RECORD_EXIT:
835 return process_task_event(event, offset, head);
837 case PERF_RECORD_LOST:
838 return process_lost_event(event, offset, head);
840 case PERF_RECORD_READ:
841 return process_read_event(event, offset, head);
844 * We dont process them right now but they are fine:
847 case PERF_RECORD_THROTTLE:
848 case PERF_RECORD_UNTHROTTLE:
858 static int __cmd_report(void)
860 int ret, rc = EXIT_FAILURE;
861 unsigned long offset = 0;
862 unsigned long head, shift;
863 struct stat input_stat;
869 idle = register_idle_thread(&threads, &last_match);
870 thread__comm_adjust(idle);
873 perf_read_values_init(&show_threads_values);
875 input = open(input_name, O_RDONLY);
877 fprintf(stderr, " failed to open file: %s", input_name);
878 if (!strcmp(input_name, "perf.data"))
879 fprintf(stderr, " (try 'perf record' first)");
880 fprintf(stderr, "\n");
884 ret = fstat(input, &input_stat);
886 perror("failed to stat file");
890 if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) {
891 fprintf(stderr, "file: %s not owned by current user or root\n", input_name);
895 if (!input_stat.st_size) {
896 fprintf(stderr, "zero-sized file, nothing to do!\n");
900 header = perf_header__read(input);
901 head = header->data_offset;
903 sample_type = perf_header__sample_type(header);
905 if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
906 if (sort__has_parent) {
907 fprintf(stderr, "selected --sort parent, but no"
908 " callchain data. Did you call"
909 " perf record without -g?\n");
913 fprintf(stderr, "selected -g but no callchain data."
914 " Did you call perf record without"
918 } else if (callchain_param.mode != CHAIN_NONE && !callchain) {
920 if (register_callchain_param(&callchain_param) < 0) {
921 fprintf(stderr, "Can't register callchain"
927 if (load_kernel() < 0) {
928 perror("failed to load kernel symbols");
933 if (getcwd(__cwd, sizeof(__cwd)) == NULL) {
934 perror("failed to get the current directory");
937 cwdlen = strlen(cwd);
943 shift = page_size * (head / page_size);
948 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
949 MAP_SHARED, input, offset);
950 if (buf == MAP_FAILED) {
951 perror("failed to mmap file");
956 event = (event_t *)(buf + head);
958 size = event->header.size;
962 if (head + event->header.size >= page_size * mmap_window) {
965 shift = page_size * (head / page_size);
967 munmap_ret = munmap(buf, page_size * mmap_window);
968 assert(munmap_ret == 0);
975 size = event->header.size;
977 dump_printf("\n%p [%p]: event: %d\n",
978 (void *)(offset + head),
979 (void *)(long)event->header.size,
982 if (!size || process_event(event, offset, head) < 0) {
984 dump_printf("%p [%p]: skipping unknown header type: %d\n",
985 (void *)(offset + head),
986 (void *)(long)(event->header.size),
992 * assume we lost track of the stream, check alignment, and
993 * increment a single u64 in the hope to catch on again 'soon'.
996 if (unlikely(head & 7))
1004 if (offset + head >= header->data_offset + header->data_size)
1007 if (offset + head < (unsigned long)input_stat.st_size)
1014 dump_printf(" IP events: %10ld\n", total);
1015 dump_printf(" mmap events: %10ld\n", total_mmap);
1016 dump_printf(" comm events: %10ld\n", total_comm);
1017 dump_printf(" fork events: %10ld\n", total_fork);
1018 dump_printf(" lost events: %10ld\n", total_lost);
1019 dump_printf(" unknown events: %10ld\n", total_unknown);
1025 threads__fprintf(stdout, &threads);
1028 dsos__fprintf(stdout);
1031 output__resort(total);
1032 output__fprintf(stdout, total);
1035 perf_read_values_destroy(&show_threads_values);
1041 parse_callchain_opt(const struct option *opt __used, const char *arg,
1052 tok = strtok((char *)arg, ",");
1056 /* get the output mode */
1057 if (!strncmp(tok, "graph", strlen(arg)))
1058 callchain_param.mode = CHAIN_GRAPH_ABS;
1060 else if (!strncmp(tok, "flat", strlen(arg)))
1061 callchain_param.mode = CHAIN_FLAT;
1063 else if (!strncmp(tok, "fractal", strlen(arg)))
1064 callchain_param.mode = CHAIN_GRAPH_REL;
1066 else if (!strncmp(tok, "none", strlen(arg))) {
1067 callchain_param.mode = CHAIN_NONE;
1076 /* get the min percentage */
1077 tok = strtok(NULL, ",");
1081 callchain_param.min_percent = strtod(tok, &endptr);
1086 if (register_callchain_param(&callchain_param) < 0) {
1087 fprintf(stderr, "Can't register callchain params\n");
1093 //static const char * const report_usage[] = {
1094 const char * const report_usage[] = {
1095 "perf report [<options>] <command>",
1099 static const struct option options[] = {
1100 OPT_STRING('i', "input", &input_name, "file",
1102 OPT_BOOLEAN('v', "verbose", &verbose,
1103 "be more verbose (show symbol address, etc)"),
1104 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1105 "dump raw trace in ASCII"),
1106 OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
1107 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
1108 OPT_BOOLEAN('m', "modules", &modules,
1109 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1110 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
1111 "Show a column with the number of samples"),
1112 OPT_BOOLEAN('T', "threads", &show_threads,
1113 "Show per-thread event counters"),
1114 OPT_STRING(0, "pretty", &pretty_printing_style, "key",
1115 "pretty printing style key: normal raw"),
1116 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1117 "sort by key(s): pid, comm, dso, symbol, parent"),
1118 OPT_BOOLEAN('P', "full-paths", &full_paths,
1119 "Don't shorten the pathnames taking into account the cwd"),
1120 OPT_STRING('p', "parent", &parent_pattern, "regex",
1121 "regex filter to identify parent, see: '--sort parent'"),
1122 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
1123 "Only display entries with parent-match"),
1124 OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent",
1125 "Display callchains using output_type and min percent threshold. "
1126 "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt),
1127 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
1128 "only consider symbols in these dsos"),
1129 OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]",
1130 "only consider symbols in these comms"),
1131 OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]",
1132 "only consider these symbols"),
1133 OPT_STRING('w', "column-widths", &col_width_list_str,
1135 "don't try to adjust column width, use these fixed values"),
1136 OPT_STRING('t', "field-separator", &field_sep, "separator",
1137 "separator for columns, no spaces will be added between "
1138 "columns '.' is reserved."),
1142 static void setup_sorting(void)
1144 char *tmp, *tok, *str = strdup(sort_order);
1146 for (tok = strtok_r(str, ", ", &tmp);
1147 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1148 if (sort_dimension__add(tok) < 0) {
1149 error("Unknown --sort key: `%s'", tok);
1150 usage_with_options(report_usage, options);
1157 static void setup_list(struct strlist **list, const char *list_str,
1158 struct sort_entry *se, const char *list_name,
1162 *list = strlist__new(true, list_str);
1164 fprintf(stderr, "problems parsing %s list\n",
1168 if (strlist__nr_entries(*list) == 1) {
1169 fprintf(fp, "# %s: %s\n", list_name,
1170 strlist__entry(*list, 0)->s);
1176 int cmd_report(int argc, const char **argv, const char *prefix __used)
1180 page_size = getpagesize();
1182 argc = parse_options(argc, argv, options, report_usage, 0);
1186 if (parent_pattern != default_parent_pattern) {
1187 sort_dimension__add("parent");
1188 sort_parent.elide = 1;
1193 * Any (unrecognized) arguments left?
1196 usage_with_options(report_usage, options);
1200 setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout);
1201 setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout);
1202 setup_list(&sym_list, sym_list_str, &sort_sym, "symbol", stdout);
1204 if (field_sep && *field_sep == '.') {
1205 fputs("'.' is the only non valid --field-separator argument\n",
1210 return __cmd_report();