summaryrefslogtreecommitdiff
path: root/tools/perf/builtin-trace.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-10-19 21:17:30 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-10-19 21:35:02 +0300
commit154c978d484c610468727c361576b7cfe9c3fec7 (patch)
tree72d934e7b3249c9f57c2918a0a2419102ae23b9e /tools/perf/builtin-trace.c
parentf77526be82fcc31cb0d54796dd8f8476472b05d0 (diff)
downloadlinux-154c978d484c610468727c361576b7cfe9c3fec7.tar.xz
libbeauty: Introduce strarray__strtoul_flags()
Counterpart of strarray__scnprintf_flags(), i.e. from a expression like: # perf trace -e syscalls:sys_enter_mmap --filter="flags==PRIVATE|FIXED|DENYWRITE" I.e. that "flags==PRIVATE|FIXED|DENYWRITE", turn that into # perf trace -e syscalls:sys_enter_mmap --filter=0x812 Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-8xst3zrqqogax7fmfzwymvbl@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-trace.c')
-rw-r--r--tools/perf/builtin-trace.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 72ef3b395504..73c5c14b52eb 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -586,6 +586,49 @@ bool strarray__strtoul(struct strarray *sa, char *bf, size_t size, u64 *ret)
return false;
}
+bool strarray__strtoul_flags(struct strarray *sa, char *bf, size_t size, u64 *ret)
+{
+ u64 val = 0;
+ char *tok = bf, *sep, *end;
+
+ *ret = 0;
+
+ while (size != 0) {
+ int toklen = size;
+
+ sep = memchr(tok, '|', size);
+ if (sep != NULL) {
+ size -= sep - tok + 1;
+
+ end = sep - 1;
+ while (end > tok && isspace(*end))
+ --end;
+
+ toklen = end - tok + 1;
+ }
+
+ while (isspace(*tok))
+ ++tok;
+
+ if (isalpha(*tok) || *tok == '_') {
+ if (!strarray__strtoul(sa, tok, toklen, &val))
+ return false;
+ } else {
+ bool is_hexa = tok[0] == 0 && (tok[1] = 'x' || tok[1] == 'X');
+
+ val = strtoul(tok, NULL, is_hexa ? 16 : 0);
+ }
+
+ *ret |= (1 << (val - 1));
+
+ if (sep == NULL)
+ break;
+ tok = sep + 1;
+ }
+
+ return true;
+}
+
bool strarrays__strtoul(struct strarrays *sas, char *bf, size_t size, u64 *ret)
{
int i;
@@ -3676,7 +3719,7 @@ static int trace__expand_filter(struct trace *trace __maybe_unused, struct evsel
}
right_end = right + 1;
- while (isalnum(*right_end) || *right_end == '_')
+ while (isalnum(*right_end) || *right_end == '_' || *right_end == '|')
++right_end;
if (isalpha(*right)) {