1 // SPDX-License-Identifier: GPL-2.0
4 #include "util/debug.h"
5 #include <subcmd/parse-options.h>
6 #include "util/parse-branch-options.h"
8 #define BRANCH_OPT(n, m) \
9 { .name = n, .mode = (m) }
11 #define BRANCH_END { .name = NULL }
18 static const struct branch_mode branch_modes
[] = {
19 BRANCH_OPT("u", PERF_SAMPLE_BRANCH_USER
),
20 BRANCH_OPT("k", PERF_SAMPLE_BRANCH_KERNEL
),
21 BRANCH_OPT("hv", PERF_SAMPLE_BRANCH_HV
),
22 BRANCH_OPT("any", PERF_SAMPLE_BRANCH_ANY
),
23 BRANCH_OPT("any_call", PERF_SAMPLE_BRANCH_ANY_CALL
),
24 BRANCH_OPT("any_ret", PERF_SAMPLE_BRANCH_ANY_RETURN
),
25 BRANCH_OPT("ind_call", PERF_SAMPLE_BRANCH_IND_CALL
),
26 BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX
),
27 BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX
),
28 BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX
),
29 BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND
),
30 BRANCH_OPT("ind_jmp", PERF_SAMPLE_BRANCH_IND_JUMP
),
31 BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL
),
32 BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE
),
36 int parse_branch_str(const char *str
, __u64
*mode
)
39 (PERF_SAMPLE_BRANCH_USER |\
40 PERF_SAMPLE_BRANCH_KERNEL |\
41 PERF_SAMPLE_BRANCH_HV)
46 const struct branch_mode
*br
;
49 *mode
= PERF_SAMPLE_BRANCH_ANY
;
53 /* because str is read-only */
63 for (br
= branch_modes
; br
->name
; br
++) {
64 if (!strcasecmp(s
, br
->name
))
69 pr_warning("unknown branch filter %s,"
70 " check man page\n", s
);
82 /* default to any branch */
83 if ((*mode
& ~ONLY_PLM
) == 0) {
84 *mode
= PERF_SAMPLE_BRANCH_ANY
;
92 parse_branch_stack(const struct option
*opt
, const char *str
, int unset
)
94 __u64
*mode
= (__u64
*)opt
->value
;
100 * cannot set it twice, -b + --branch-filter for instance
105 return parse_branch_str(str
, mode
);