diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-06 12:11:18 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-06 12:11:18 -0400 |
commit | 8ad7013b252ba683055df19e657eb03d98f4f312 (patch) | |
tree | c558eac4f3bcf3ecf7e9b64efe52be83249fea41 | |
parent | 831394bdd9dd3ac1661336505c7cbdfd786d8cd4 (diff) |
perf test: Add round trip test for sw and hw event names
It basically traverses the hardware and software event name arrays
creating an evlist with all events, then it uses perf_evsel__name to
check that the name is the expected one.
With it I noticed this problem:
[root@sandy ~]# perf test 10
10: roundtrip evsel->name check:invalid or unsupported event: 'CPU-migrations'
Run 'perf list' for a list of valid events
FAILED!
Changed it to "cpu-migrations" in the software event arrays and it
worked.
This is to catch problems like the one reported by Joel Uckelman in
http://permalink.gmane.org/gmane.linux.kernel.perf.user/1016
Hardware cache events will be checked in the following patch.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-5jskfkuqvf2fi257zmni0ftz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-test.c | 53 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 6 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 6 |
3 files changed, 60 insertions, 5 deletions
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 381d5ab8712..ba94fbe1fa4 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
@@ -1092,6 +1092,55 @@ static int test__perf_pmu(void) | |||
1092 | return perf_pmu__test(); | 1092 | return perf_pmu__test(); |
1093 | } | 1093 | } |
1094 | 1094 | ||
1095 | static int __perf_evsel__name_array_test(const char *names[], int nr_names) | ||
1096 | { | ||
1097 | int i, err; | ||
1098 | struct perf_evsel *evsel; | ||
1099 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | ||
1100 | |||
1101 | if (evlist == NULL) | ||
1102 | return -ENOMEM; | ||
1103 | |||
1104 | for (i = 0; i < nr_names; ++i) { | ||
1105 | err = parse_events(evlist, names[i], 0); | ||
1106 | if (err) { | ||
1107 | pr_debug("failed to parse event '%s', err %d\n", | ||
1108 | names[i], err); | ||
1109 | goto out_delete_evlist; | ||
1110 | } | ||
1111 | } | ||
1112 | |||
1113 | err = 0; | ||
1114 | list_for_each_entry(evsel, &evlist->entries, node) { | ||
1115 | if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) { | ||
1116 | --err; | ||
1117 | pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]); | ||
1118 | } | ||
1119 | } | ||
1120 | |||
1121 | out_delete_evlist: | ||
1122 | perf_evlist__delete(evlist); | ||
1123 | return err; | ||
1124 | } | ||
1125 | |||
1126 | #define perf_evsel__name_array_test(names) \ | ||
1127 | __perf_evsel__name_array_test(names, ARRAY_SIZE(names)) | ||
1128 | |||
1129 | static int perf_evsel__roundtrip_name_test(void) | ||
1130 | { | ||
1131 | int err = 0, ret = 0; | ||
1132 | |||
1133 | err = perf_evsel__name_array_test(perf_evsel__hw_names); | ||
1134 | if (err) | ||
1135 | ret = err; | ||
1136 | |||
1137 | err = perf_evsel__name_array_test(perf_evsel__sw_names); | ||
1138 | if (err) | ||
1139 | ret = err; | ||
1140 | |||
1141 | return ret; | ||
1142 | } | ||
1143 | |||
1095 | static struct test { | 1144 | static struct test { |
1096 | const char *desc; | 1145 | const char *desc; |
1097 | int (*func)(void); | 1146 | int (*func)(void); |
@@ -1135,6 +1184,10 @@ static struct test { | |||
1135 | .func = dso__test_data, | 1184 | .func = dso__test_data, |
1136 | }, | 1185 | }, |
1137 | { | 1186 | { |
1187 | .desc = "roundtrip evsel->name check", | ||
1188 | .func = perf_evsel__roundtrip_name_test, | ||
1189 | }, | ||
1190 | { | ||
1138 | .func = NULL, | 1191 | .func = NULL, |
1139 | }, | 1192 | }, |
1140 | }; | 1193 | }; |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 7ff3c8fb736..06f76441547 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -68,7 +68,7 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) | |||
68 | return evsel; | 68 | return evsel; |
69 | } | 69 | } |
70 | 70 | ||
71 | static const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { | 71 | const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { |
72 | "cycles", | 72 | "cycles", |
73 | "instructions", | 73 | "instructions", |
74 | "cache-references", | 74 | "cache-references", |
@@ -131,12 +131,12 @@ static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) | |||
131 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); | 131 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); |
132 | } | 132 | } |
133 | 133 | ||
134 | static const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX] = { | 134 | const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX] = { |
135 | "cpu-clock", | 135 | "cpu-clock", |
136 | "task-clock", | 136 | "task-clock", |
137 | "page-faults", | 137 | "page-faults", |
138 | "context-switches", | 138 | "context-switches", |
139 | "CPU-migrations", | 139 | "cpu-migrations", |
140 | "minor-faults", | 140 | "minor-faults", |
141 | "major-faults", | 141 | "major-faults", |
142 | "alignment-faults", | 142 | "alignment-faults", |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 94f6ba16747..a3f562cec43 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -97,8 +97,10 @@ extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX] | |||
97 | [PERF_EVSEL__MAX_ALIASES]; | 97 | [PERF_EVSEL__MAX_ALIASES]; |
98 | extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] | 98 | extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] |
99 | [PERF_EVSEL__MAX_ALIASES]; | 99 | [PERF_EVSEL__MAX_ALIASES]; |
100 | const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] | 100 | extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] |
101 | [PERF_EVSEL__MAX_ALIASES]; | 101 | [PERF_EVSEL__MAX_ALIASES]; |
102 | extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX]; | ||
103 | extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX]; | ||
102 | int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, | 104 | int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, |
103 | char *bf, size_t size); | 105 | char *bf, size_t size); |
104 | const char *perf_evsel__name(struct perf_evsel *evsel); | 106 | const char *perf_evsel__name(struct perf_evsel *evsel); |