2015-05-28 01:51:51 +08:00
|
|
|
#include "perf.h"
|
|
|
|
#include "util/util.h"
|
|
|
|
#include "util/debug.h"
|
2015-12-15 23:39:39 +08:00
|
|
|
#include <subcmd/parse-options.h>
|
2015-05-28 01:51:51 +08:00
|
|
|
#include "util/parse-branch-options.h"
|
|
|
|
|
|
|
|
#define BRANCH_OPT(n, m) \
|
|
|
|
{ .name = n, .mode = (m) }
|
|
|
|
|
|
|
|
#define BRANCH_END { .name = NULL }
|
|
|
|
|
|
|
|
struct branch_mode {
|
|
|
|
const char *name;
|
|
|
|
int mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct branch_mode branch_modes[] = {
|
|
|
|
BRANCH_OPT("u", PERF_SAMPLE_BRANCH_USER),
|
|
|
|
BRANCH_OPT("k", PERF_SAMPLE_BRANCH_KERNEL),
|
|
|
|
BRANCH_OPT("hv", PERF_SAMPLE_BRANCH_HV),
|
|
|
|
BRANCH_OPT("any", PERF_SAMPLE_BRANCH_ANY),
|
|
|
|
BRANCH_OPT("any_call", PERF_SAMPLE_BRANCH_ANY_CALL),
|
|
|
|
BRANCH_OPT("any_ret", PERF_SAMPLE_BRANCH_ANY_RETURN),
|
|
|
|
BRANCH_OPT("ind_call", PERF_SAMPLE_BRANCH_IND_CALL),
|
|
|
|
BRANCH_OPT("abort_tx", PERF_SAMPLE_BRANCH_ABORT_TX),
|
|
|
|
BRANCH_OPT("in_tx", PERF_SAMPLE_BRANCH_IN_TX),
|
|
|
|
BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX),
|
|
|
|
BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND),
|
2015-05-15 05:10:00 +08:00
|
|
|
BRANCH_OPT("ind_jmp", PERF_SAMPLE_BRANCH_IND_JUMP),
|
2015-10-13 15:09:11 +08:00
|
|
|
BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
|
2015-05-28 01:51:51 +08:00
|
|
|
BRANCH_END
|
|
|
|
};
|
|
|
|
|
2016-10-13 05:02:06 +08:00
|
|
|
int parse_branch_str(const char *str, __u64 *mode)
|
2015-05-28 01:51:51 +08:00
|
|
|
{
|
|
|
|
#define ONLY_PLM \
|
|
|
|
(PERF_SAMPLE_BRANCH_USER |\
|
|
|
|
PERF_SAMPLE_BRANCH_KERNEL |\
|
|
|
|
PERF_SAMPLE_BRANCH_HV)
|
|
|
|
|
2016-10-13 05:02:06 +08:00
|
|
|
int ret = 0;
|
|
|
|
char *p, *s;
|
|
|
|
char *os = NULL;
|
2015-05-28 01:51:51 +08:00
|
|
|
const struct branch_mode *br;
|
|
|
|
|
2016-10-13 05:02:06 +08:00
|
|
|
if (str == NULL) {
|
|
|
|
*mode = PERF_SAMPLE_BRANCH_ANY;
|
2015-05-28 01:51:51 +08:00
|
|
|
return 0;
|
2016-10-13 05:02:06 +08:00
|
|
|
}
|
2015-05-28 01:51:51 +08:00
|
|
|
|
2016-10-13 05:02:06 +08:00
|
|
|
/* because str is read-only */
|
|
|
|
s = os = strdup(str);
|
|
|
|
if (!s)
|
2015-05-28 01:51:51 +08:00
|
|
|
return -1;
|
|
|
|
|
2016-10-13 05:02:06 +08:00
|
|
|
for (;;) {
|
|
|
|
p = strchr(s, ',');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2015-05-28 01:51:51 +08:00
|
|
|
|
2016-10-13 05:02:06 +08:00
|
|
|
for (br = branch_modes; br->name; br++) {
|
|
|
|
if (!strcasecmp(s, br->name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!br->name) {
|
|
|
|
ret = -1;
|
perf tools: Add missing object file to the python binding linkage list
In ac12f6764c50 ("perf tools: Implement branch_type event parameter") we
started using the parse_branch_str() function from one of the files used
in the python binding, which caused this entry in 'perf test' to fail:
# perf test -v python
16: Try 'import perf' in python, checking link problems :
--- start ---
test child forked, pid 16667
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /tmp/build/perf/python/perf.so: undefined symbol:
parse_branch_str
test child finished with -1
---- end ----
Try 'import perf' in python, checking link problems: FAILED!
#
I must've commited some mistake when running 'perf test' to send the
pull request for the perf-core-for-mingo-20161024 tag, to have let this
regression to pass, sigh.
Just add tools/perf/util/parse-branch-options.c and switch from using
ui__warning(), that is not available in the python binding, use
pr_warning() instead, which is good enough for this case.
Now:
# perf test python
16: Try 'import perf' in python, checking link problems : Ok
#
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Fixes: ac12f6764c50 ("perf tools: Implement branch_type event parameter")
Link: http://lkml.kernel.org/n/tip-9kn1ct1cx9ppwqlmzl6z0xhs@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-10-27 05:02:35 +08:00
|
|
|
pr_warning("unknown branch filter %s,"
|
2016-10-13 05:02:06 +08:00
|
|
|
" check man page\n", s);
|
|
|
|
goto error;
|
2015-05-28 01:51:51 +08:00
|
|
|
}
|
2016-10-13 05:02:06 +08:00
|
|
|
|
|
|
|
*mode |= br->mode;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
|
|
|
|
s = p + 1;
|
2015-05-28 01:51:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* default to any branch */
|
|
|
|
if ((*mode & ~ONLY_PLM) == 0) {
|
|
|
|
*mode = PERF_SAMPLE_BRANCH_ANY;
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
free(os);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-10-13 05:02:06 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
parse_branch_stack(const struct option *opt, const char *str, int unset)
|
|
|
|
{
|
|
|
|
__u64 *mode = (__u64 *)opt->value;
|
|
|
|
|
|
|
|
if (unset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cannot set it twice, -b + --branch-filter for instance
|
|
|
|
*/
|
|
|
|
if (*mode)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return parse_branch_str(str, mode);
|
|
|
|
}
|