diff options
author | Ingo Molnar <mingo@elte.hu> | 2011-04-26 22:06:33 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-04-26 14:04:55 -0400 |
commit | ceb53fbf6dbb1df26d38379a262c6981fe73dd36 (patch) | |
tree | 128bc025a3b4a99c212d9c78ca3ff3b492d730af /tools/perf | |
parent | b908debd4eef91471016138569f7a9e292be682e (diff) |
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: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/n/tip-wlaw3dvz1ly6wple8l52cfca@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/parse-events.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 8e54bdb553c3..b686269427ea 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -721,15 +721,19 @@ parse_numeric_event(const char **strp, struct perf_event_attr *attr) | |||
721 | return EVT_FAILED; | 721 | return EVT_FAILED; |
722 | } | 722 | } |
723 | 723 | ||
724 | static enum event_result | 724 | static int |
725 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) | 725 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) |
726 | { | 726 | { |
727 | const char *str = *strp; | 727 | const char *str = *strp; |
728 | int exclude = 0; | 728 | int exclude = 0; |
729 | int eu = 0, ek = 0, eh = 0, precise = 0; | 729 | int eu = 0, ek = 0, eh = 0, precise = 0; |
730 | 730 | ||
731 | if (*str++ != ':') | 731 | if (!*str) |
732 | return 0; | 732 | return 0; |
733 | |||
734 | if (*str++ != ':') | ||
735 | return -1; | ||
736 | |||
733 | while (*str) { | 737 | while (*str) { |
734 | if (*str == 'u') { | 738 | if (*str == 'u') { |
735 | if (!exclude) | 739 | if (!exclude) |
@@ -750,14 +754,16 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr) | |||
750 | 754 | ||
751 | ++str; | 755 | ++str; |
752 | } | 756 | } |
753 | if (str >= *strp + 2) { | 757 | if (str < *strp + 2) |
754 | *strp = str; | 758 | return -1; |
755 | attr->exclude_user = eu; | 759 | |
756 | attr->exclude_kernel = ek; | 760 | *strp = str; |
757 | attr->exclude_hv = eh; | 761 | |
758 | attr->precise_ip = precise; | 762 | attr->exclude_user = eu; |
759 | return 1; | 763 | attr->exclude_kernel = ek; |
760 | } | 764 | attr->exclude_hv = eh; |
765 | attr->precise_ip = precise; | ||
766 | |||
761 | return 0; | 767 | return 0; |
762 | } | 768 | } |
763 | 769 | ||
@@ -800,7 +806,12 @@ parse_event_symbols(const struct option *opt, const char **str, | |||
800 | return EVT_FAILED; | 806 | return EVT_FAILED; |
801 | 807 | ||
802 | modifier: | 808 | modifier: |
803 | parse_event_modifier(str, attr); | 809 | if (parse_event_modifier(str, attr) < 0) { |
810 | fprintf(stderr, "invalid event modifier: '%s'\n", *str); | ||
811 | fprintf(stderr, "Run 'perf list' for a list of valid events and modifiers\n"); | ||
812 | |||
813 | return EVT_FAILED; | ||
814 | } | ||
804 | 815 | ||
805 | return ret; | 816 | return ret; |
806 | } | 817 | } |