diff options
author | Andi Kleen <ak@linux.intel.com> | 2013-04-20 14:02:28 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-07-12 12:53:52 -0400 |
commit | 50e200f07948400694238e08e7add73df5ba8f83 (patch) | |
tree | 91a2b5a0e0d06d1d7690bac23077d7d4c7c42c11 /tools/perf/util | |
parent | 380512345e13c3af64e59627f1b993c4faa94a84 (diff) |
perf tools: Default to cpu// for events v5
When an event fails to parse and it's not in a new style format,
try to parse it again as a cpu event.
This allows to use sysfs exported events directly without //, so you can use
perf record -e mem-loads ...
instead of
perf record -e cpu/mem-loads/
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1366480949-32292-1-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/include/linux/string.h | 1 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 30 | ||||
-rw-r--r-- | tools/perf/util/string.c | 24 |
3 files changed, 54 insertions, 1 deletions
diff --git a/tools/perf/util/include/linux/string.h b/tools/perf/util/include/linux/string.h index 6f19c548ecc0..97a800738226 100644 --- a/tools/perf/util/include/linux/string.h +++ b/tools/perf/util/include/linux/string.h | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <string.h> | 1 | #include <string.h> |
2 | 2 | ||
3 | void *memdup(const void *src, size_t len); | 3 | void *memdup(const void *src, size_t len); |
4 | int str_append(char **s, int *len, const char *a); | ||
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index e85376999efc..a5076f4f6016 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "parse-options.h" | 6 | #include "parse-options.h" |
7 | #include "parse-events.h" | 7 | #include "parse-events.h" |
8 | #include "exec_cmd.h" | 8 | #include "exec_cmd.h" |
9 | #include "string.h" | 9 | #include "linux/string.h" |
10 | #include "symbol.h" | 10 | #include "symbol.h" |
11 | #include "cache.h" | 11 | #include "cache.h" |
12 | #include "header.h" | 12 | #include "header.h" |
@@ -823,6 +823,32 @@ int parse_events_name(struct list_head *list, char *name) | |||
823 | return 0; | 823 | return 0; |
824 | } | 824 | } |
825 | 825 | ||
826 | static int parse_events__scanner(const char *str, void *data, int start_token); | ||
827 | |||
828 | static int parse_events_fixup(int ret, const char *str, void *data, | ||
829 | int start_token) | ||
830 | { | ||
831 | char *o = strdup(str); | ||
832 | char *s = NULL; | ||
833 | char *t = o; | ||
834 | char *p; | ||
835 | int len = 0; | ||
836 | |||
837 | if (!o) | ||
838 | return ret; | ||
839 | while ((p = strsep(&t, ",")) != NULL) { | ||
840 | if (s) | ||
841 | str_append(&s, &len, ","); | ||
842 | str_append(&s, &len, "cpu/"); | ||
843 | str_append(&s, &len, p); | ||
844 | str_append(&s, &len, "/"); | ||
845 | } | ||
846 | free(o); | ||
847 | if (!s) | ||
848 | return -ENOMEM; | ||
849 | return parse_events__scanner(s, data, start_token); | ||
850 | } | ||
851 | |||
826 | static int parse_events__scanner(const char *str, void *data, int start_token) | 852 | static int parse_events__scanner(const char *str, void *data, int start_token) |
827 | { | 853 | { |
828 | YY_BUFFER_STATE buffer; | 854 | YY_BUFFER_STATE buffer; |
@@ -843,6 +869,8 @@ static int parse_events__scanner(const char *str, void *data, int start_token) | |||
843 | parse_events__flush_buffer(buffer, scanner); | 869 | parse_events__flush_buffer(buffer, scanner); |
844 | parse_events__delete_buffer(buffer, scanner); | 870 | parse_events__delete_buffer(buffer, scanner); |
845 | parse_events_lex_destroy(scanner); | 871 | parse_events_lex_destroy(scanner); |
872 | if (ret && !strchr(str, '/')) | ||
873 | ret = parse_events_fixup(ret, str, data, start_token); | ||
846 | return ret; | 874 | return ret; |
847 | } | 875 | } |
848 | 876 | ||
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 29c7b2cb2521..f0b0c008c507 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -387,3 +387,27 @@ void *memdup(const void *src, size_t len) | |||
387 | 387 | ||
388 | return p; | 388 | return p; |
389 | } | 389 | } |
390 | |||
391 | /** | ||
392 | * str_append - reallocate string and append another | ||
393 | * @s: pointer to string pointer | ||
394 | * @len: pointer to len (initialized) | ||
395 | * @a: string to append. | ||
396 | */ | ||
397 | int str_append(char **s, int *len, const char *a) | ||
398 | { | ||
399 | int olen = *s ? strlen(*s) : 0; | ||
400 | int nlen = olen + strlen(a) + 1; | ||
401 | if (*len < nlen) { | ||
402 | *len = *len * 2; | ||
403 | if (*len < nlen) | ||
404 | *len = nlen; | ||
405 | *s = realloc(*s, *len); | ||
406 | if (!*s) | ||
407 | return -ENOMEM; | ||
408 | if (olen == 0) | ||
409 | **s = 0; | ||
410 | } | ||
411 | strcat(*s, a); | ||
412 | return 0; | ||
413 | } | ||