From: Andi Kleen <a...@linux.intel.com> Change pmu.c to allow descriptions of events and add interfaces to add aliases at runtime from another file. To be used by jevents in a followon patch
Acked-by: Namhyung Kim <namhy...@kernel.org> Signed-off-by: Andi Kleen <a...@linux.intel.com> Signed-off-by: Sukadev Bhattiprolu <suka...@linux.vnet.ibm.com> --- Changelog[v9] by Sukadev Bhattiprolu Rebase to 4.0 v2: Move perf list changes to other patch. --- tools/perf/util/json.c | 1 + tools/perf/util/pmu.c | 48 +++++++++++++++++++++++++++++++++--------------- tools/perf/util/pmu.h | 1 + 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/json.c b/tools/perf/util/json.c index e20001f..2219844 100644 --- a/tools/perf/util/json.c +++ b/tools/perf/util/json.c @@ -38,6 +38,7 @@ #include "jsmn.h" #include "json.h" #include <linux/kernel.h> +#include "debug.h" static char *mapfile(const char *fn, size_t *size) { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4841167..527da74 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -198,17 +198,12 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, return 0; } -static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) +static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir, + char *desc, char *val) { struct perf_pmu_alias *alias; - char buf[256]; int ret; - ret = fread(buf, 1, sizeof(buf), file); - if (ret == 0) - return -EINVAL; - buf[ret] = 0; - alias = malloc(sizeof(*alias)); if (!alias) return -ENOMEM; @@ -218,26 +213,49 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI alias->unit[0] = '\0'; alias->per_pkg = false; - ret = parse_events_terms(&alias->terms, buf); + ret = parse_events_terms(&alias->terms, val); if (ret) { + pr_err("Cannot parse alias %s: %d\n", val, ret); free(alias); return ret; } alias->name = strdup(name); - /* - * load unit name and scale if available - */ - perf_pmu__parse_unit(alias, dir, name); - perf_pmu__parse_scale(alias, dir, name); - perf_pmu__parse_per_pkg(alias, dir, name); - perf_pmu__parse_snapshot(alias, dir, name); + + if (dir) { + /* + * load unit name and scale if available + */ + perf_pmu__parse_unit(alias, dir, name); + perf_pmu__parse_scale(alias, dir, name); + perf_pmu__parse_per_pkg(alias, dir, name); + perf_pmu__parse_snapshot(alias, dir, name); + } + + alias->desc = desc ? strdup(desc) : NULL; list_add_tail(&alias->list, list); return 0; } +static int perf_pmu__new_alias(struct list_head *list, + char *dir, + char *name, + FILE *file) +{ + char buf[256]; + int ret; + + ret = fread(buf, 1, sizeof(buf), file); + if (ret == 0) + return -EINVAL; + buf[ret] = 0; + + return __perf_pmu__new_alias(list, name, dir, NULL, buf); +} + + static inline bool pmu_alias_info_file(char *name) { size_t len; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 6b1249f..d06496d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -37,6 +37,7 @@ struct perf_pmu_info { struct perf_pmu_alias { char *name; + char *desc; struct list_head terms; /* HEAD struct parse_events_term -> list */ struct list_head list; /* ELEM */ char unit[UNIT_MAX_LEN+1]; -- 1.7.9.5 _______________________________________________ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev