aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-branch-options.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2016-10-12 17:02:06 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-24 10:07:35 -0400
commitac12f6764c5097e791cd44f10b8943b40f44bfe7 (patch)
treee3a8ca10680e74baf7e16804b9ce50fff4e030f2 /tools/perf/util/parse-branch-options.c
parent84ee74affccc93b02dee5a986dfe214f4eaa08d3 (diff)
perf tools: Implement branch_type event parameter
It can be useful to specify branch type state per event, for example if we want to collect both software trace points and last branch PMU events in a single collection. Currently this doesn't work because the software trace point errors out with -b. There was already a branch-type parameter to configure branch sample types per event in the parser, but it was stubbed out. This patch implements the necessary plumbing to actually enable it. Now: $ perf record -e sched:sched_switch,cpu/cpu-cycles,branch_type=any/ ... works. Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/1476306127-19721-1-git-send-email-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-branch-options.c')
-rw-r--r--tools/perf/util/parse-branch-options.c85
1 files changed, 47 insertions, 38 deletions
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c
index afc088dd7d20..3634d6974300 100644
--- a/tools/perf/util/parse-branch-options.c
+++ b/tools/perf/util/parse-branch-options.c
@@ -31,59 +31,51 @@ static const struct branch_mode branch_modes[] = {
31 BRANCH_END 31 BRANCH_END
32}; 32};
33 33
34int 34int parse_branch_str(const char *str, __u64 *mode)
35parse_branch_stack(const struct option *opt, const char *str, int unset)
36{ 35{
37#define ONLY_PLM \ 36#define ONLY_PLM \
38 (PERF_SAMPLE_BRANCH_USER |\ 37 (PERF_SAMPLE_BRANCH_USER |\
39 PERF_SAMPLE_BRANCH_KERNEL |\ 38 PERF_SAMPLE_BRANCH_KERNEL |\
40 PERF_SAMPLE_BRANCH_HV) 39 PERF_SAMPLE_BRANCH_HV)
41 40
42 uint64_t *mode = (uint64_t *)opt->value; 41 int ret = 0;
42 char *p, *s;
43 char *os = NULL;
43 const struct branch_mode *br; 44 const struct branch_mode *br;
44 char *s, *os = NULL, *p;
45 int ret = -1;
46 45
47 if (unset) 46 if (str == NULL) {
47 *mode = PERF_SAMPLE_BRANCH_ANY;
48 return 0; 48 return 0;
49 }
49 50
50 /* 51 /* because str is read-only */
51 * cannot set it twice, -b + --branch-filter for instance 52 s = os = strdup(str);
52 */ 53 if (!s)
53 if (*mode)
54 return -1; 54 return -1;
55 55
56 /* str may be NULL in case no arg is passed to -b */ 56 for (;;) {
57 if (str) { 57 p = strchr(s, ',');
58 /* because str is read-only */ 58 if (p)
59 s = os = strdup(str); 59 *p = '\0';
60 if (!s)
61 return -1;
62
63 for (;;) {
64 p = strchr(s, ',');
65 if (p)
66 *p = '\0';
67
68 for (br = branch_modes; br->name; br++) {
69 if (!strcasecmp(s, br->name))
70 break;
71 }
72 if (!br->name) {
73 ui__warning("unknown branch filter %s,"
74 " check man page\n", s);
75 goto error;
76 }
77
78 *mode |= br->mode;
79
80 if (!p)
81 break;
82 60
83 s = p + 1; 61 for (br = branch_modes; br->name; br++) {
62 if (!strcasecmp(s, br->name))
63 break;
64 }
65 if (!br->name) {
66 ret = -1;
67 ui__warning("unknown branch filter %s,"
68 " check man page\n", s);
69 goto error;
84 } 70 }
71
72 *mode |= br->mode;
73
74 if (!p)
75 break;
76
77 s = p + 1;
85 } 78 }
86 ret = 0;
87 79
88 /* default to any branch */ 80 /* default to any branch */
89 if ((*mode & ~ONLY_PLM) == 0) { 81 if ((*mode & ~ONLY_PLM) == 0) {
@@ -93,3 +85,20 @@ error:
93 free(os); 85 free(os);
94 return ret; 86 return ret;
95} 87}
88
89int
90parse_branch_stack(const struct option *opt, const char *str, int unset)
91{
92 __u64 *mode = (__u64 *)opt->value;
93
94 if (unset)
95 return 0;
96
97 /*
98 * cannot set it twice, -b + --branch-filter for instance
99 */
100 if (*mode)
101 return -1;
102
103 return parse_branch_str(str, mode);
104}