]> git.karo-electronics.de Git - linux-beck.git/commitdiff
perf: make perf stat print user provided full event names
authorStephane Eranian <eranian@google.com>
Wed, 16 Feb 2011 13:10:01 +0000 (15:10 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Feb 2011 12:29:19 +0000 (10:29 -0200)
This patch changes the way perf stat prints event names at the end of a
run. Until now, it was trying to reconstruct the event name from its
encoding. The problem is that it would only print generic events without
their modifiers (u, k, pp).

This patch saves the event name as passed by the user in the evsel
struct and uses it to print the final event name.

This would also work in case perf is linked with a library (such as
libpfm4) which provides full PMU event tables.

$ perf stat -e cycles:u,cycles:k date
Wed Feb 16 14:58:52 CET 2011

 Performance counter stats for 'date':

            568600 cycles:u
           2779715 cycles:k

        0.001908182  seconds time elapsed

Cc: Arun Sharma <arun@sharma-home.net>
Cc: David S. Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@gmail.com>
LPU-Reference: <4d5bdc64.98a1df0a.7aa3.06c2@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
[ committer note: Fixed a merge problem with 023695d "Add cgroup support" ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/parse-events.c

index c974e08d07abc39ea1257e3d614f674b6882f3e8..63cadaf3e2083f8f131f2cd1343556e578ed8fbc 100644 (file)
@@ -86,6 +86,7 @@ void perf_evsel__delete(struct perf_evsel *evsel)
 {
        perf_evsel__exit(evsel);
        close_cgroup(evsel->cgrp);
+       free(evsel->name);
        free(evsel);
 }
 
index 1d3d5a3dbe603d13ce92539b57481fc8f4a489b9..f6fc8f651a256c91d9a7429cf52fbb396cb544a3 100644 (file)
@@ -37,6 +37,12 @@ struct perf_sample_id {
        struct perf_evsel       *evsel;
 };
 
+/** struct perf_evsel - event selector
+ *
+ * @name - Can be set to retain the original event name passed by the user,
+ *         so that when showing results in tools such as 'perf stat', we
+ *         show the name used, not some alias.
+ */
 struct perf_evsel {
        struct list_head        node;
        struct perf_event_attr  attr;
@@ -45,6 +51,7 @@ struct perf_evsel {
        struct xyarray          *id;
        struct perf_counts      *counts;
        int                     idx;
+       char                    *name;
        void                    *priv;
        struct cgroup_sel       *cgrp;
 };
index cf082daa43e3a61a7b2c225cd0aec874a494ef4d..80a3dd5ef5735b132b873c6327c99ea1f78c4ce1 100644 (file)
@@ -268,6 +268,9 @@ const char *event_name(struct perf_evsel *evsel)
        u64 config = evsel->attr.config;
        int type = evsel->attr.type;
 
+       if (evsel->name)
+               return evsel->name;
+
        return __event_name(type, config);
 }
 
@@ -782,8 +785,10 @@ int parse_events(const struct option *opt, const char *str, int unset __used)
        struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
        struct perf_event_attr attr;
        enum event_result ret;
+       const char *ostr;
 
        for (;;) {
+               ostr = str;
                memset(&attr, 0, sizeof(attr));
                ret = parse_event_symbols(opt, &str, &attr);
                if (ret == EVT_FAILED)
@@ -798,6 +803,11 @@ int parse_events(const struct option *opt, const char *str, int unset __used)
                        if (evsel == NULL)
                                return -1;
                        perf_evlist__add(evlist, evsel);
+
+                       evsel->name = calloc(str - ostr + 1, 1);
+                       if (!evsel->name)
+                               return -1;
+                       strncpy(evsel->name, ostr, str - ostr);
                }
 
                if (*str == 0)