diff options
author | Andi Kleen <ak@linux.intel.com> | 2015-05-27 13:51:51 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-05-27 20:02:17 -0400 |
commit | f00898f4e20b286877b8d6d96d6e404661fd7985 (patch) | |
tree | 74a48727edbc5edb44b6df4b1455e6e17c332f13 | |
parent | 83be34a7a913bdf9f21f524333c63d9c48a28ef4 (diff) |
perf tools: Move branch option parsing to own file
.. to allow sharing between builtin-record and builtin-top later. No
code changes, just moved code.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1432749114-904-9-git-send-email-andi@firstfloor.org
[ Rename too generic branch.[ch] name to parse-branch-options.[ch] ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-record.c | 89 | ||||
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/parse-branch-options.c | 93 | ||||
-rw-r--r-- | tools/perf/util/parse-branch-options.h | 5 |
4 files changed, 100 insertions, 88 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 5dfe91395617..91aa2a3dcf19 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "util/thread_map.h" | 28 | #include "util/thread_map.h" |
29 | #include "util/data.h" | 29 | #include "util/data.h" |
30 | #include "util/auxtrace.h" | 30 | #include "util/auxtrace.h" |
31 | #include "util/parse-branch-options.h" | ||
31 | 32 | ||
32 | #include <unistd.h> | 33 | #include <unistd.h> |
33 | #include <sched.h> | 34 | #include <sched.h> |
@@ -751,94 +752,6 @@ out_delete_session: | |||
751 | return status; | 752 | return status; |
752 | } | 753 | } |
753 | 754 | ||
754 | #define BRANCH_OPT(n, m) \ | ||
755 | { .name = n, .mode = (m) } | ||
756 | |||
757 | #define BRANCH_END { .name = NULL } | ||
758 | |||
759 | struct branch_mode { | ||
760 | const char *name; | ||
761 | int mode; | ||
762 | }; | ||
763 | |||
764 | static const struct branch_mode branch_modes[] = { | ||
765 | BRANCH_OPT("u", PERF_SAMPLE_BRANCH_USER), | ||
766 | BRANCH_OPT("k", PERF_SAMPLE_BRANCH_KERNEL), | ||
767 | BRANCH_OPT("hv", PERF_SAMPLE_BRANCH_HV), | ||
768 | BRANCH_OPT("any", PERF_SAMPLE_BRANCH_ANY), | ||
769 | BRANCH_OPT("any_call", PERF_SAMPLE_BRANCH_ANY_CALL), | ||
770 | BRANCH_OPT("any_ret", PERF_SAMPLE_BRANCH_ANY_RETURN), | ||
771 | BRANCH_OPT("ind_call", PERF_SAMPLE_BRANCH_IND_CALL), | ||
772 | BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX), | ||
773 | BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX), | ||
774 | BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX), | ||
775 | BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND), | ||
776 | BRANCH_END | ||
777 | }; | ||
778 | |||
779 | static int | ||
780 | parse_branch_stack(const struct option *opt, const char *str, int unset) | ||
781 | { | ||
782 | #define ONLY_PLM \ | ||
783 | (PERF_SAMPLE_BRANCH_USER |\ | ||
784 | PERF_SAMPLE_BRANCH_KERNEL |\ | ||
785 | PERF_SAMPLE_BRANCH_HV) | ||
786 | |||
787 | uint64_t *mode = (uint64_t *)opt->value; | ||
788 | const struct branch_mode *br; | ||
789 | char *s, *os = NULL, *p; | ||
790 | int ret = -1; | ||
791 | |||
792 | if (unset) | ||
793 | return 0; | ||
794 | |||
795 | /* | ||
796 | * cannot set it twice, -b + --branch-filter for instance | ||
797 | */ | ||
798 | if (*mode) | ||
799 | return -1; | ||
800 | |||
801 | /* str may be NULL in case no arg is passed to -b */ | ||
802 | if (str) { | ||
803 | /* because str is read-only */ | ||
804 | s = os = strdup(str); | ||
805 | if (!s) | ||
806 | return -1; | ||
807 | |||
808 | for (;;) { | ||
809 | p = strchr(s, ','); | ||
810 | if (p) | ||
811 | *p = '\0'; | ||
812 | |||
813 | for (br = branch_modes; br->name; br++) { | ||
814 | if (!strcasecmp(s, br->name)) | ||
815 | break; | ||
816 | } | ||
817 | if (!br->name) { | ||
818 | ui__warning("unknown branch filter %s," | ||
819 | " check man page\n", s); | ||
820 | goto error; | ||
821 | } | ||
822 | |||
823 | *mode |= br->mode; | ||
824 | |||
825 | if (!p) | ||
826 | break; | ||
827 | |||
828 | s = p + 1; | ||
829 | } | ||
830 | } | ||
831 | ret = 0; | ||
832 | |||
833 | /* default to any branch */ | ||
834 | if ((*mode & ~ONLY_PLM) == 0) { | ||
835 | *mode = PERF_SAMPLE_BRANCH_ANY; | ||
836 | } | ||
837 | error: | ||
838 | free(os); | ||
839 | return ret; | ||
840 | } | ||
841 | |||
842 | static void callchain_debug(void) | 755 | static void callchain_debug(void) |
843 | { | 756 | { |
844 | static const char *str[CALLCHAIN_MAX] = { "NONE", "FP", "DWARF", "LBR" }; | 757 | static const char *str[CALLCHAIN_MAX] = { "NONE", "FP", "DWARF", "LBR" }; |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 6966d0743bf7..e4b676de2f64 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -75,6 +75,7 @@ libperf-$(CONFIG_X86) += tsc.o | |||
75 | libperf-y += cloexec.o | 75 | libperf-y += cloexec.o |
76 | libperf-y += thread-stack.o | 76 | libperf-y += thread-stack.o |
77 | libperf-$(CONFIG_AUXTRACE) += auxtrace.o | 77 | libperf-$(CONFIG_AUXTRACE) += auxtrace.o |
78 | libperf-y += parse-branch-options.o | ||
78 | 79 | ||
79 | libperf-$(CONFIG_LIBELF) += symbol-elf.o | 80 | libperf-$(CONFIG_LIBELF) += symbol-elf.o |
80 | libperf-$(CONFIG_LIBELF) += probe-event.o | 81 | libperf-$(CONFIG_LIBELF) += probe-event.o |
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c new file mode 100644 index 000000000000..9d999436658f --- /dev/null +++ b/tools/perf/util/parse-branch-options.c | |||
@@ -0,0 +1,93 @@ | |||
1 | #include "perf.h" | ||
2 | #include "util/util.h" | ||
3 | #include "util/debug.h" | ||
4 | #include "util/parse-options.h" | ||
5 | #include "util/parse-branch-options.h" | ||
6 | |||
7 | #define BRANCH_OPT(n, m) \ | ||
8 | { .name = n, .mode = (m) } | ||
9 | |||
10 | #define BRANCH_END { .name = NULL } | ||
11 | |||
12 | struct branch_mode { | ||
13 | const char *name; | ||
14 | int mode; | ||
15 | }; | ||
16 | |||
17 | static const struct branch_mode branch_modes[] = { | ||
18 | BRANCH_OPT("u", PERF_SAMPLE_BRANCH_USER), | ||
19 | BRANCH_OPT("k", PERF_SAMPLE_BRANCH_KERNEL), | ||
20 | BRANCH_OPT("hv", PERF_SAMPLE_BRANCH_HV), | ||
21 | BRANCH_OPT("any", PERF_SAMPLE_BRANCH_ANY), | ||
22 | BRANCH_OPT("any_call", PERF_SAMPLE_BRANCH_ANY_CALL), | ||
23 | BRANCH_OPT("any_ret", PERF_SAMPLE_BRANCH_ANY_RETURN), | ||
24 | BRANCH_OPT("ind_call", PERF_SAMPLE_BRANCH_IND_CALL), | ||
25 | BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX), | ||
26 | BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX), | ||
27 | BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX), | ||
28 | BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND), | ||
29 | BRANCH_END | ||
30 | }; | ||
31 | |||
32 | int | ||
33 | parse_branch_stack(const struct option *opt, const char *str, int unset) | ||
34 | { | ||
35 | #define ONLY_PLM \ | ||
36 | (PERF_SAMPLE_BRANCH_USER |\ | ||
37 | PERF_SAMPLE_BRANCH_KERNEL |\ | ||
38 | PERF_SAMPLE_BRANCH_HV) | ||
39 | |||
40 | uint64_t *mode = (uint64_t *)opt->value; | ||
41 | const struct branch_mode *br; | ||
42 | char *s, *os = NULL, *p; | ||
43 | int ret = -1; | ||
44 | |||
45 | if (unset) | ||
46 | return 0; | ||
47 | |||
48 | /* | ||
49 | * cannot set it twice, -b + --branch-filter for instance | ||
50 | */ | ||
51 | if (*mode) | ||
52 | return -1; | ||
53 | |||
54 | /* str may be NULL in case no arg is passed to -b */ | ||
55 | if (str) { | ||
56 | /* because str is read-only */ | ||
57 | s = os = strdup(str); | ||
58 | if (!s) | ||
59 | return -1; | ||
60 | |||
61 | for (;;) { | ||
62 | p = strchr(s, ','); | ||
63 | if (p) | ||
64 | *p = '\0'; | ||
65 | |||
66 | for (br = branch_modes; br->name; br++) { | ||
67 | if (!strcasecmp(s, br->name)) | ||
68 | break; | ||
69 | } | ||
70 | if (!br->name) { | ||
71 | ui__warning("unknown branch filter %s," | ||
72 | " check man page\n", s); | ||
73 | goto error; | ||
74 | } | ||
75 | |||
76 | *mode |= br->mode; | ||
77 | |||
78 | if (!p) | ||
79 | break; | ||
80 | |||
81 | s = p + 1; | ||
82 | } | ||
83 | } | ||
84 | ret = 0; | ||
85 | |||
86 | /* default to any branch */ | ||
87 | if ((*mode & ~ONLY_PLM) == 0) { | ||
88 | *mode = PERF_SAMPLE_BRANCH_ANY; | ||
89 | } | ||
90 | error: | ||
91 | free(os); | ||
92 | return ret; | ||
93 | } | ||
diff --git a/tools/perf/util/parse-branch-options.h b/tools/perf/util/parse-branch-options.h new file mode 100644 index 000000000000..b9d9470c2e82 --- /dev/null +++ b/tools/perf/util/parse-branch-options.h | |||
@@ -0,0 +1,5 @@ | |||
1 | #ifndef _PERF_PARSE_BRANCH_OPTIONS_H | ||
2 | #define _PERF_PARSE_BRANCH_OPTIONS_H 1 | ||
3 | struct option; | ||
4 | int parse_branch_stack(const struct option *opt, const char *str, int unset); | ||
5 | #endif /* _PERF_PARSE_BRANCH_OPTIONS_H */ | ||