perf session: Event statistics also are per session
[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 session->events_stats.total += data.period;
623 return 0;
624 }
625
626 static int process_comm_event(event_t *event, struct perf_session *session)
627 {
628 struct thread *thread = perf_session__findnew(session, event->comm.pid);
629
630 dump_printf(": %s:%d\n", event->comm.comm, event->comm.pid);
631
632 if (thread == NULL ||
633 thread__set_comm_adjust(thread, event->comm.comm)) {
634 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
635 return -1;
636 }
637
638 return 0;
639 }
640
641 static int process_read_event(event_t *event, struct perf_session *session __used)
642 {
643 struct perf_event_attr *attr;
644
645 attr = perf_header__find_attr(event->read.id, &session->header);
646
647 if (show_threads) {
648 const char *name = attr ? __event_name(attr->type, attr->config)
649 : "unknown";
650 perf_read_values_add_value(&show_threads_values,
651 event->read.pid, event->read.tid,
652 event->read.id,
653 name,
654 event->read.value);
655 }
656
657 dump_printf(": %d %d %s %Lu\n", event->read.pid, event->read.tid,
658 attr ? __event_name(attr->type, attr->config) : "FAIL",
659 event->read.value);
660
661 return 0;
662 }
663
664 static int sample_type_check(struct perf_session *session)
665 {
666 if (!(session->sample_type & PERF_SAMPLE_CALLCHAIN)) {
667 if (sort__has_parent) {
668 fprintf(stderr, "selected --sort parent, but no"
669 " callchain data. Did you call"
670 " perf record without -g?\n");
671 return -1;
672 }
673 if (session->use_callchain) {
674 fprintf(stderr, "selected -g but no callchain data."
675 " Did you call perf record without"
676 " -g?\n");
677 return -1;
678 }
679 } else if (callchain_param.mode != CHAIN_NONE && !session->use_callchain) {
680 session->use_callchain = true;
681 if (register_callchain_param(&callchain_param) < 0) {
682 fprintf(stderr, "Can't register callchain"
683 " params\n");
684 return -1;
685 }
686 }
687
688 return 0;
689 }
690
691 static struct perf_event_ops event_ops = {
692 .process_sample_event = process_sample_event,
693 .process_mmap_event = event__process_mmap,
694 .process_comm_event = process_comm_event,
695 .process_exit_event = event__process_task,
696 .process_fork_event = event__process_task,
697 .process_lost_event = event__process_lost,
698 .process_read_event = process_read_event,
699 .sample_type_check = sample_type_check,
700 };
701
702
703 static int __cmd_report(void)
704 {
705 int ret;
706 struct perf_session *session;
707
708 session = perf_session__new(input_name, O_RDONLY, force, &symbol_conf);
709 if (session == NULL)
710 return -ENOMEM;
711
712 session->use_callchain = use_callchain;
713
714 if (show_threads)
715 perf_read_values_init(&show_threads_values);
716
717 ret = perf_session__process_events(session, &event_ops);
718 if (ret)
719 goto out_delete;
720
721 if (dump_trace) {
722 event__print_totals();
723 goto out_delete;
724 }
725
726 if (verbose > 3)
727 perf_session__fprintf(session, stdout);
728
729 if (verbose > 2)
730 dsos__fprintf(stdout);
731
732 perf_session__collapse_resort(session);
733 perf_session__output_resort(session, session->events_stats.total);
734 perf_session__fprintf_hist_entries(session, session->events_stats.total, stdout);
735
736 if (show_threads)
737 perf_read_values_destroy(&show_threads_values);
738 out_delete:
739 perf_session__delete(session);
740 return ret;
741 }
742
743 static int
744 parse_callchain_opt(const struct option *opt __used, const char *arg,
745 int unset __used)
746 {
747 char *tok;
748 char *endptr;
749
750 use_callchain = true;
751
752 if (!arg)
753 return 0;
754
755 tok = strtok((char *)arg, ",");
756 if (!tok)
757 return -1;
758
759 /* get the output mode */
760 if (!strncmp(tok, "graph", strlen(arg)))
761 callchain_param.mode = CHAIN_GRAPH_ABS;
762
763 else if (!strncmp(tok, "flat", strlen(arg)))
764 callchain_param.mode = CHAIN_FLAT;
765
766 else if (!strncmp(tok, "fractal", strlen(arg)))
767 callchain_param.mode = CHAIN_GRAPH_REL;
768
769 else if (!strncmp(tok, "none", strlen(arg))) {
770 callchain_param.mode = CHAIN_NONE;
771 use_callchain = true;
772
773 return 0;
774 }
775
776 else
777 return -1;
778
779 /* get the min percentage */
780 tok = strtok(NULL, ",");
781 if (!tok)
782 goto setup;
783
784 callchain_param.min_percent = strtod(tok, &endptr);
785 if (tok == endptr)
786 return -1;
787
788 setup:
789 if (register_callchain_param(&callchain_param) < 0) {
790 fprintf(stderr, "Can't register callchain params\n");
791 return -1;
792 }
793 return 0;
794 }
795
796 //static const char * const report_usage[] = {
797 const char * const report_usage[] = {
798 "perf report [<options>] <command>",
799 NULL
800 };
801
802 static const struct option options[] = {
803 OPT_STRING('i', "input", &input_name, "file",
804 "input file name"),
805 OPT_BOOLEAN('v', "verbose", &verbose,
806 "be more verbose (show symbol address, etc)"),
807 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
808 "dump raw trace in ASCII"),
809 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
810 "file", "vmlinux pathname"),
811 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
812 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
813 "load module symbols - WARNING: use only with -k and LIVE kernel"),
814 OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
815 "Show a column with the number of samples"),
816 OPT_BOOLEAN('T', "threads", &show_threads,
817 "Show per-thread event counters"),
818 OPT_STRING(0, "pretty", &pretty_printing_style, "key",
819 "pretty printing style key: normal raw"),
820 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
821 "sort by key(s): pid, comm, dso, symbol, parent"),
822 OPT_BOOLEAN('P', "full-paths", &event_ops.full_paths,
823 "Don't shorten the pathnames taking into account the cwd"),
824 OPT_STRING('p', "parent", &parent_pattern, "regex",
825 "regex filter to identify parent, see: '--sort parent'"),
826 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
827 "Only display entries with parent-match"),
828 OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent",
829 "Display callchains using output_type and min percent threshold. "
830 "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt),
831 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
832 "only consider symbols in these dsos"),
833 OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]",
834 "only consider symbols in these comms"),
835 OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]",
836 "only consider these symbols"),
837 OPT_STRING('w', "column-widths", &col_width_list_str,
838 "width[,width...]",
839 "don't try to adjust column width, use these fixed values"),
840 OPT_STRING('t', "field-separator", &field_sep, "separator",
841 "separator for columns, no spaces will be added between "
842 "columns '.' is reserved."),
843 OPT_END()
844 };
845
846 static void setup_sorting(void)
847 {
848 char *tmp, *tok, *str = strdup(sort_order);
849
850 for (tok = strtok_r(str, ", ", &tmp);
851 tok; tok = strtok_r(NULL, ", ", &tmp)) {
852 if (sort_dimension__add(tok) < 0) {
853 error("Unknown --sort key: `%s'", tok);
854 usage_with_options(report_usage, options);
855 }
856 }
857
858 free(str);
859 }
860
861 static void setup_list(struct strlist **list, const char *list_str,
862 struct sort_entry *se, const char *list_name,
863 FILE *fp)
864 {
865 if (list_str) {
866 *list = strlist__new(true, list_str);
867 if (!*list) {
868 fprintf(stderr, "problems parsing %s list\n",
869 list_name);
870 exit(129);
871 }
872 if (strlist__nr_entries(*list) == 1) {
873 fprintf(fp, "# %s: %s\n", list_name,
874 strlist__entry(*list, 0)->s);
875 se->elide = true;
876 }
877 }
878 }
879
880 int cmd_report(int argc, const char **argv, const char *prefix __used)
881 {
882 if (symbol__init(&symbol_conf) < 0)
883 return -1;
884
885 argc = parse_options(argc, argv, options, report_usage, 0);
886
887 setup_sorting();
888
889 if (parent_pattern != default_parent_pattern) {
890 sort_dimension__add("parent");
891 sort_parent.elide = 1;
892 } else
893 exclude_other = 0;
894
895 /*
896 * Any (unrecognized) arguments left?
897 */
898 if (argc)
899 usage_with_options(report_usage, options);
900
901 setup_pager();
902
903 setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout);
904 setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout);
905 setup_list(&sym_list, sym_list_str, &sort_sym, "symbol", stdout);
906
907 if (field_sep && *field_sep == '.') {
908 fputs("'.' is the only non valid --field-separator argument\n",
909 stderr);
910 exit(129);
911 }
912
913 return __cmd_report();
914 }
This page took 0.055552 seconds and 5 git commands to generate.