Commit ceb53fbf authored by Ingo Molnar's avatar Ingo Molnar

perf stat: Fail more clearly when an invalid modifier is specified

Currently we fail without printing any error message on "perf stat -e task-clock-msecs".

The reason is that the task-clock event is matched and the "-msecs" postfix is assumed
to be an event modifier - but is not recognized.

This patch changes the code to be more informative:

 $ perf stat -e task-clock-msecs true
 invalid event modifier: '-msecs'
 Run 'perf list' for a list of valid events and modifiers

And restructures the return value of parse_event_modifier() to allow
the printing of all variants of invalid event modifiers.
Acked-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/n/tip-wlaw3dvz1ly6wple8l52cfca@git.kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent b908debd
...@@ -721,15 +721,19 @@ parse_numeric_event(const char **strp, struct perf_event_attr *attr) ...@@ -721,15 +721,19 @@ parse_numeric_event(const char **strp, struct perf_event_attr *attr)
return EVT_FAILED; return EVT_FAILED;
} }
static enum event_result static int
parse_event_modifier(const char **strp, struct perf_event_attr *attr) parse_event_modifier(const char **strp, struct perf_event_attr *attr)
{ {
const char *str = *strp; const char *str = *strp;
int exclude = 0; int exclude = 0;
int eu = 0, ek = 0, eh = 0, precise = 0; int eu = 0, ek = 0, eh = 0, precise = 0;
if (*str++ != ':') if (!*str)
return 0; return 0;
if (*str++ != ':')
return -1;
while (*str) { while (*str) {
if (*str == 'u') { if (*str == 'u') {
if (!exclude) if (!exclude)
...@@ -750,14 +754,16 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr) ...@@ -750,14 +754,16 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr)
++str; ++str;
} }
if (str >= *strp + 2) { if (str < *strp + 2)
*strp = str; return -1;
attr->exclude_user = eu;
attr->exclude_kernel = ek; *strp = str;
attr->exclude_hv = eh;
attr->precise_ip = precise; attr->exclude_user = eu;
return 1; attr->exclude_kernel = ek;
} attr->exclude_hv = eh;
attr->precise_ip = precise;
return 0; return 0;
} }
...@@ -800,7 +806,12 @@ parse_event_symbols(const struct option *opt, const char **str, ...@@ -800,7 +806,12 @@ parse_event_symbols(const struct option *opt, const char **str,
return EVT_FAILED; return EVT_FAILED;
modifier: modifier:
parse_event_modifier(str, attr); if (parse_event_modifier(str, attr) < 0) {
fprintf(stderr, "invalid event modifier: '%s'\n", *str);
fprintf(stderr, "Run 'perf list' for a list of valid events and modifiers\n");
return EVT_FAILED;
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment