summaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorThomas Richter <tmricht@linux.ibm.com>2018-06-15 06:11:04 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-06-25 10:59:37 -0400
commit0c24d6fb7bd3578e5b9e4972d01bbe3d087ded33 (patch)
treef79b32b073f4b924b4da6cc90dd0b0d7249455a1 /tools/perf
parentea23ac73085743a4f1682d6605fe019577c82e1e (diff)
perf alias: Rebuild alias expression string to make it comparable
PMU alias definitions in sysfs files may have spaces, newlines and numbers with leading zeroes. Some alias definitions may also appear in JSON files without spaces, etc. Scan alias definitions and remove leading zeroes, spaces, newlines, etc and rebuild string to make alias->str member comparable. s390 for example has terms specified as event=0x0091 (read from files ../<PMU>/events/<FILE> and terms specified as event=0x91 (read from JSON files). Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Link: http://lkml.kernel.org/r/20180615101105.47047-2-tmricht@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/pmu.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 2738fc8d200d..f321ce97d9ec 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -241,9 +241,11 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
241 char *metric_expr, 241 char *metric_expr,
242 char *metric_name) 242 char *metric_name)
243{ 243{
244 struct parse_events_term *term;
244 struct perf_pmu_alias *alias; 245 struct perf_pmu_alias *alias;
245 int ret; 246 int ret;
246 int num; 247 int num;
248 char newval[256];
247 249
248 alias = malloc(sizeof(*alias)); 250 alias = malloc(sizeof(*alias));
249 if (!alias) 251 if (!alias)
@@ -262,6 +264,27 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
262 return ret; 264 return ret;
263 } 265 }
264 266
267 /* Scan event and remove leading zeroes, spaces, newlines, some
268 * platforms have terms specified as
269 * event=0x0091 (read from files ../<PMU>/events/<FILE>
270 * and terms specified as event=0x91 (read from JSON files).
271 *
272 * Rebuild string to make alias->str member comparable.
273 */
274 memset(newval, 0, sizeof(newval));
275 ret = 0;
276 list_for_each_entry(term, &alias->terms, list) {
277 if (ret)
278 ret += scnprintf(newval + ret, sizeof(newval) - ret,
279 ",");
280 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
281 ret += scnprintf(newval + ret, sizeof(newval) - ret,
282 "%s=%#x", term->config, term->val.num);
283 else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
284 ret += scnprintf(newval + ret, sizeof(newval) - ret,
285 "%s=%s", term->config, term->val.str);
286 }
287
265 alias->name = strdup(name); 288 alias->name = strdup(name);
266 if (dir) { 289 if (dir) {
267 /* 290 /*
@@ -285,7 +308,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
285 snprintf(alias->unit, sizeof(alias->unit), "%s", unit); 308 snprintf(alias->unit, sizeof(alias->unit), "%s", unit);
286 } 309 }
287 alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1; 310 alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1;
288 alias->str = strdup(val); 311 alias->str = strdup(newval);
289 312
290 list_add_tail(&alias->list, list); 313 list_add_tail(&alias->list, list);
291 314