aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDon Zickus <dzickus@redhat.com>2014-04-07 14:55:24 -0400
committerJiri Olsa <jolsa@redhat.com>2014-04-22 11:39:24 -0400
commitcff6bb46d477383092f46682a0d12e323e4b84d2 (patch)
tree88b5217cdee5126642e6f3db587fab1b1050ba65 /tools
parent4b6279579c84cca7f162cfbcb98f66418f3062f3 (diff)
perf callchain: Add generic report parse callchain callback function
This takes the parse_callchain_opt function and copies it into the callchain.c file. Now the c2c tool can use it too without duplicating. Update perf-report to use the new routine too. Signed-off-by: Don Zickus <dzickus@redhat.com> Reviewed-by: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/1396896924-129847-5-git-send-email-dzickus@redhat.com [ Adding missing braces to multiline if condition ] Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-report.c81
-rw-r--r--tools/perf/util/callchain.c78
-rw-r--r--tools/perf/util/callchain.h1
3 files changed, 82 insertions, 78 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index af8cb7a2c9b6..76e2bb6cf571 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -589,11 +589,9 @@ static int __cmd_report(struct report *rep)
589} 589}
590 590
591static int 591static int
592parse_callchain_opt(const struct option *opt, const char *arg, int unset) 592report_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
593{ 593{
594 struct report *rep = (struct report *)opt->value; 594 struct report *rep = (struct report *)opt->value;
595 char *tok, *tok2;
596 char *endptr;
597 595
598 /* 596 /*
599 * --no-call-graph 597 * --no-call-graph
@@ -603,80 +601,7 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset)
603 return 0; 601 return 0;
604 } 602 }
605 603
606 symbol_conf.use_callchain = true; 604 return parse_callchain_report_opt(arg);
607
608 if (!arg)
609 return 0;
610
611 tok = strtok((char *)arg, ",");
612 if (!tok)
613 return -1;
614
615 /* get the output mode */
616 if (!strncmp(tok, "graph", strlen(arg)))
617 callchain_param.mode = CHAIN_GRAPH_ABS;
618
619 else if (!strncmp(tok, "flat", strlen(arg)))
620 callchain_param.mode = CHAIN_FLAT;
621
622 else if (!strncmp(tok, "fractal", strlen(arg)))
623 callchain_param.mode = CHAIN_GRAPH_REL;
624
625 else if (!strncmp(tok, "none", strlen(arg))) {
626 callchain_param.mode = CHAIN_NONE;
627 symbol_conf.use_callchain = false;
628
629 return 0;
630 }
631
632 else
633 return -1;
634
635 /* get the min percentage */
636 tok = strtok(NULL, ",");
637 if (!tok)
638 goto setup;
639
640 callchain_param.min_percent = strtod(tok, &endptr);
641 if (tok == endptr)
642 return -1;
643
644 /* get the print limit */
645 tok2 = strtok(NULL, ",");
646 if (!tok2)
647 goto setup;
648
649 if (tok2[0] != 'c') {
650 callchain_param.print_limit = strtoul(tok2, &endptr, 0);
651 tok2 = strtok(NULL, ",");
652 if (!tok2)
653 goto setup;
654 }
655
656 /* get the call chain order */
657 if (!strncmp(tok2, "caller", strlen("caller")))
658 callchain_param.order = ORDER_CALLER;
659 else if (!strncmp(tok2, "callee", strlen("callee")))
660 callchain_param.order = ORDER_CALLEE;
661 else
662 return -1;
663
664 /* Get the sort key */
665 tok2 = strtok(NULL, ",");
666 if (!tok2)
667 goto setup;
668 if (!strncmp(tok2, "function", strlen("function")))
669 callchain_param.key = CCKEY_FUNCTION;
670 else if (!strncmp(tok2, "address", strlen("address")))
671 callchain_param.key = CCKEY_ADDRESS;
672 else
673 return -1;
674setup:
675 if (callchain_register_param(&callchain_param) < 0) {
676 pr_err("Can't register callchain params\n");
677 return -1;
678 }
679 return 0;
680} 605}
681 606
682int 607int
@@ -788,7 +713,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
788 "Only display entries with parent-match"), 713 "Only display entries with parent-match"),
789 OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order", 714 OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order",
790 "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address). " 715 "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address). "
791 "Default: fractal,0.5,callee,function", &parse_callchain_opt, callchain_default_opt), 716 "Default: fractal,0.5,callee,function", &report_parse_callchain_opt, callchain_default_opt),
792 OPT_INTEGER(0, "max-stack", &report.max_stack, 717 OPT_INTEGER(0, "max-stack", &report.max_stack,
793 "Set the maximum stack depth when parsing the callchain, " 718 "Set the maximum stack depth when parsing the callchain, "
794 "anything beyond the specified depth will be ignored. " 719 "anything beyond the specified depth will be ignored. "
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 8d9db454f1a9..9a42382b3921 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -25,6 +25,84 @@
25 25
26__thread struct callchain_cursor callchain_cursor; 26__thread struct callchain_cursor callchain_cursor;
27 27
28int
29parse_callchain_report_opt(const char *arg)
30{
31 char *tok, *tok2;
32 char *endptr;
33
34 symbol_conf.use_callchain = true;
35
36 if (!arg)
37 return 0;
38
39 tok = strtok((char *)arg, ",");
40 if (!tok)
41 return -1;
42
43 /* get the output mode */
44 if (!strncmp(tok, "graph", strlen(arg))) {
45 callchain_param.mode = CHAIN_GRAPH_ABS;
46
47 } else if (!strncmp(tok, "flat", strlen(arg))) {
48 callchain_param.mode = CHAIN_FLAT;
49 } else if (!strncmp(tok, "fractal", strlen(arg))) {
50 callchain_param.mode = CHAIN_GRAPH_REL;
51 } else if (!strncmp(tok, "none", strlen(arg))) {
52 callchain_param.mode = CHAIN_NONE;
53 symbol_conf.use_callchain = false;
54 return 0;
55 } else {
56 return -1;
57 }
58
59 /* get the min percentage */
60 tok = strtok(NULL, ",");
61 if (!tok)
62 goto setup;
63
64 callchain_param.min_percent = strtod(tok, &endptr);
65 if (tok == endptr)
66 return -1;
67
68 /* get the print limit */
69 tok2 = strtok(NULL, ",");
70 if (!tok2)
71 goto setup;
72
73 if (tok2[0] != 'c') {
74 callchain_param.print_limit = strtoul(tok2, &endptr, 0);
75 tok2 = strtok(NULL, ",");
76 if (!tok2)
77 goto setup;
78 }
79
80 /* get the call chain order */
81 if (!strncmp(tok2, "caller", strlen("caller")))
82 callchain_param.order = ORDER_CALLER;
83 else if (!strncmp(tok2, "callee", strlen("callee")))
84 callchain_param.order = ORDER_CALLEE;
85 else
86 return -1;
87
88 /* Get the sort key */
89 tok2 = strtok(NULL, ",");
90 if (!tok2)
91 goto setup;
92 if (!strncmp(tok2, "function", strlen("function")))
93 callchain_param.key = CCKEY_FUNCTION;
94 else if (!strncmp(tok2, "address", strlen("address")))
95 callchain_param.key = CCKEY_ADDRESS;
96 else
97 return -1;
98setup:
99 if (callchain_register_param(&callchain_param) < 0) {
100 pr_err("Can't register callchain params\n");
101 return -1;
102 }
103 return 0;
104}
105
28static void 106static void
29rb_insert_callchain(struct rb_root *root, struct callchain_node *chain, 107rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,
30 enum chain_mode mode) 108 enum chain_mode mode)
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 8ad97e9b119f..dda4cf8b534c 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -157,4 +157,5 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent
157int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); 157int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
158 158
159extern const char record_callchain_help[]; 159extern const char record_callchain_help[];
160int parse_callchain_report_opt(const char *arg);
160#endif /* __PERF_CALLCHAIN_H */ 161#endif /* __PERF_CALLCHAIN_H */