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