]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
perf pmu: Add support for MetricName JSON attribute
authorAndi Kleen <ak@linux.intel.com>
Mon, 20 Mar 2017 20:17:10 +0000 (13:17 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 23 Mar 2017 14:42:31 +0000 (11:42 -0300)
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>
tools/perf/pmu-events/jevents.c
tools/perf/pmu-events/jevents.h
tools/perf/pmu-events/pmu-events.h
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/parse-events.c
tools/perf/util/pmu.c
tools/perf/util/pmu.h
tools/perf/util/stat-shadow.c

index 0735dc2a167a44b6e1954f0feeb9e4cc82aa190a..81f2ef3b15cf7878c841c367a322d232a5809502 100644 (file)
@@ -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;
index 57e111bf216864368c613ec28454e986f59a35e1..611fac01913de14335924f1b7e02a86263fa377e 100644 (file)
@@ -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);
 
index d046e3a4ce46f1e0c4fc8bb0db7353eebb35f029..569eab3688dd084236e6261d7511a31a40dc7117 100644 (file)
@@ -14,6 +14,7 @@ struct pmu_event {
        const char *unit;
        const char *perpkg;
        const char *metric_expr;
+       const char *metric_name;
 };
 
 /*
index ef2a31f6dd066453babd13abb8123c1c0e28365f..9dc7e2d6e48a6bc970c41435490ddf71cac82791 100644 (file)
@@ -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;
 }
index 8f1f61826fdf6c68cd80d74d6b4b088b902325bb..d101695c482cfb288db70b1f268372d4f4323f65 100644 (file)
@@ -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;
 };
index 91b8e83e307dab51a85bcbc1d80f928a95ce9aa4..119eb0b6587689a650de62f010b1ff8ca8462746 100644 (file)
@@ -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;
index f819ad162b7c7d5cd3bb47d4b86970dd2757d55f..bcf752fa345b8971096687db4b1c4285317a8e5d 100644 (file)
@@ -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');
index 27f078ccc5946a97d93b44b9a1736fc7fb953933..3d4b703f5d89c21b4c20eb4eb22f3b019e971f73 100644 (file)
@@ -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);
index c323cce97d983fdd417cd15a0468d345bc66a6aa..ac10cc675d39579bfca249abbc4353e7c9accc6e 100644 (file)
@@ -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);