diff options
author | Andi Kleen <ak@linux.intel.com> | 2017-03-20 13:17:10 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-03-23 11:42:31 -0300 |
commit | 962848142335e8b35d522be78f58f2011d976b17 (patch) | |
tree | 3d73b6f223cf8fd2246d2ee33870bac2166d34bc | |
parent | 7f372a636d92e21d6fa41aebd6986ef590aefbfc (diff) |
perf pmu: Add support for MetricName JSON attribute
Add support for a new JSON event attribute to name MetricExpr for better
output in perf stat.
If the event has no MetricName it uses the normal event name instead to
describe the metric.
Before
% perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}' --metric-only
time unc_p_freq_max_os_cycles
1.000149775 15.7
2.000344807 19.3
3.000502544 16.7
4.000640656 6.6
5.000779955 9.9
After
% perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}' --metric-only
time freq_max_os_cycles %
1.000149775 15.7
2.000344807 19.3
3.000502544 16.7
4.000640656 6.6
5.000779955 9.9
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-13-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/pmu-events/jevents.c | 14 | ||||
-rw-r--r-- | tools/perf/pmu-events/jevents.h | 3 | ||||
-rw-r--r-- | tools/perf/pmu-events/pmu-events.h | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 1 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 1 | ||||
-rw-r--r-- | tools/perf/util/pmu.c | 15 | ||||
-rw-r--r-- | tools/perf/util/pmu.h | 2 | ||||
-rw-r--r-- | tools/perf/util/stat-shadow.c | 4 |
9 files changed, 34 insertions, 8 deletions
diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c index 0735dc2a167a..81f2ef3b15cf 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -292,7 +292,8 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) static int print_events_table_entry(void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, char *unit, char *perpkg, - char *metric_expr) + char *metric_expr, + char *metric_name) { struct perf_entry_data *pd = data; FILE *outfp = pd->outfp; @@ -318,6 +319,8 @@ static int print_events_table_entry(void *data, char *name, char *event, fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg); if (metric_expr) fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr); + if (metric_name) + fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name); fprintf(outfp, "},\n"); return 0; @@ -366,7 +369,8 @@ int json_events(const char *fn, int (*func)(void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, char *unit, char *perpkg, - char *metric_expr), + char *metric_expr, + char *metric_name), void *data) { int err = -EIO; @@ -393,6 +397,7 @@ int json_events(const char *fn, char *perpkg = NULL; char *unit = NULL; char *metric_expr = NULL; + char *metric_name = NULL; unsigned long long eventcode = 0; struct msrmap *msr = NULL; jsmntok_t *msrval = NULL; @@ -469,6 +474,8 @@ int json_events(const char *fn, addfield(map, &unit, "", "", val); } else if (json_streq(map, field, "PerPkg")) { addfield(map, &perpkg, "", "", val); + } else if (json_streq(map, field, "MetricName")) { + addfield(map, &metric_name, "", "", val); } else if (json_streq(map, field, "MetricExpr")) { addfield(map, &metric_expr, "", "", val); for (s = metric_expr; *s; s++) @@ -497,7 +504,7 @@ int json_events(const char *fn, fixname(name); err = func(data, name, real_event(name, event), desc, long_desc, - pmu, unit, perpkg, metric_expr); + pmu, unit, perpkg, metric_expr, metric_name); free(event); free(desc); free(name); @@ -508,6 +515,7 @@ int json_events(const char *fn, free(perpkg); free(unit); free(metric_expr); + free(metric_name); if (err) break; tok += j; diff --git a/tools/perf/pmu-events/jevents.h b/tools/perf/pmu-events/jevents.h index 57e111bf2168..611fac01913d 100644 --- a/tools/perf/pmu-events/jevents.h +++ b/tools/perf/pmu-events/jevents.h @@ -5,7 +5,8 @@ int json_events(const char *fn, int (*func)(void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, - char *unit, char *perpkg, char *metric_expr), + char *unit, char *perpkg, char *metric_expr, + char *metric_name), void *data); char *get_cpu_str(void); diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index d046e3a4ce46..569eab3688dd 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -14,6 +14,7 @@ struct pmu_event { const char *unit; const char *perpkg; const char *metric_expr; + const char *metric_name; }; /* diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ef2a31f6dd06..9dc7e2d6e48a 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -237,6 +237,7 @@ void perf_evsel__init(struct perf_evsel *evsel, perf_evsel__calc_id_pos(evsel); evsel->cmdline_group_boundary = false; evsel->metric_expr = NULL; + evsel->metric_name = NULL; evsel->metric_events = NULL; evsel->collect_stat = false; } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 8f1f61826fdf..d101695c482c 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -133,6 +133,7 @@ struct perf_evsel { int bpf_fd; bool merged_stat; const char * metric_expr; + const char * metric_name; struct perf_evsel **metric_events; bool collect_stat; }; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 91b8e83e307d..119eb0b65876 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1256,6 +1256,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data, evsel->per_pkg = info.per_pkg; evsel->snapshot = info.snapshot; evsel->metric_expr = info.metric_expr; + evsel->metric_name = info.metric_name; } return evsel ? 0 : -ENOMEM; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f819ad162b7c..bcf752fa345b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -232,7 +232,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, char *desc, char *val, char *long_desc, char *topic, char *unit, char *perpkg, - char *metric_expr) + char *metric_expr, + char *metric_name) { struct perf_pmu_alias *alias; int ret; @@ -267,6 +268,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, } alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL; + alias->metric_name = metric_name ? strdup(metric_name): NULL; alias->desc = desc ? strdup(desc) : NULL; alias->long_desc = long_desc ? strdup(long_desc) : desc ? strdup(desc) : NULL; @@ -296,7 +298,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI buf[ret] = 0; return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL); } static inline bool pmu_alias_info_file(char *name) @@ -567,7 +569,8 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name) (char *)pe->desc, (char *)pe->event, (char *)pe->long_desc, (char *)pe->topic, (char *)pe->unit, (char *)pe->perpkg, - (char *)pe->metric_expr); + (char *)pe->metric_expr, + (char *)pe->metric_name); } out: @@ -995,6 +998,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, info->scale = 0.0; info->snapshot = false; info->metric_expr = NULL; + info->metric_name = NULL; list_for_each_entry_safe(term, h, head_terms, list) { alias = pmu_find_alias(pmu, term); @@ -1011,6 +1015,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, if (alias->per_pkg) info->per_pkg = true; info->metric_expr = alias->metric_expr; + info->metric_name = alias->metric_name; list_del(&term->list); free(term); @@ -1106,6 +1111,7 @@ struct sevent { char *str; char *pmu; char *metric_expr; + char *metric_name; }; static int cmp_sevent(const void *a, const void *b) @@ -1205,6 +1211,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, aliases[j].str = alias->str; aliases[j].pmu = pmu->name; aliases[j].metric_expr = alias->metric_expr; + aliases[j].metric_name = alias->metric_name; j++; } if (pmu->selectable && @@ -1241,6 +1248,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, printf("]\n"); if (verbose > 0) { printf("%*s%s/%s/ ", 8, "", aliases[j].pmu, aliases[j].str); + if (aliases[j].metric_name) + printf(" MetricName: %s", aliases[j].metric_name); if (aliases[j].metric_expr) printf(" MetricExpr: %s", aliases[j].metric_expr); putchar('\n'); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 27f078ccc594..3d4b703f5d89 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -32,6 +32,7 @@ struct perf_pmu { struct perf_pmu_info { const char *unit; const char *metric_expr; + const char *metric_name; double scale; bool per_pkg; bool snapshot; @@ -52,6 +53,7 @@ struct perf_pmu_alias { bool per_pkg; bool snapshot; char *metric_expr; + char *metric_name; }; struct perf_pmu *perf_pmu__find(const char *name); diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index c323cce97d98..ac10cc675d39 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -803,7 +803,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel, if (expr__parse(&ratio, &pctx, &p) == 0) print_metric(ctxp, NULL, "%8.1f", - out->force_header ? evsel->name : "", + evsel->metric_name ? + evsel->metric_name : + out->force_header ? evsel->name : "", ratio); else print_metric(ctxp, NULL, NULL, "", 0); |