perf list: List kernel supplied event aliases
authorAndi Kleen <ak@linux.intel.com>
Sat, 20 Apr 2013 18:02:29 +0000 (11:02 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 12 Jul 2013 16:53:53 +0000 (13:53 -0300)
List the kernel supplied pmu event aliases in perf list

It's better when the users can actually see them.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1366480949-32292-2-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-list.txt
tools/perf/builtin-list.c
tools/perf/util/parse-events.c
tools/perf/util/pmu.c
tools/perf/util/pmu.h

index d1e39dc8c81077071cc7e6a1976c0ef7028982e5..826f3d6d1d289ee34480ca977e097f7243e70719 100644 (file)
@@ -8,7 +8,7 @@ perf-list - List all symbolic event types
 SYNOPSIS
 --------
 [verse]
-'perf list' [hw|sw|cache|tracepoint|event_glob]
+'perf list' [hw|sw|cache|tracepoint|pmu|event_glob]
 
 DESCRIPTION
 -----------
@@ -104,6 +104,8 @@ To limit the list use:
   'subsys_glob:event_glob' to filter by tracepoint subsystems such as sched,
   block, etc.
 
+. 'pmu' to print the kernel supplied PMU events.
+
 . If none of the above is matched, it will apply the supplied glob to all
   events, printing the ones that match.
 
index 1948eceb517a6dcf18c974552f08d4ba1c515461..e79f423cc3022fff357e132d11d573a66f5ad7a6 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "util/parse-events.h"
 #include "util/cache.h"
+#include "util/pmu.h"
 
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
@@ -37,6 +38,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
                        else if (strcmp(argv[i], "cache") == 0 ||
                                 strcmp(argv[i], "hwcache") == 0)
                                print_hwcache_events(NULL, false);
+                       else if (strcmp(argv[i], "pmu") == 0)
+                               print_pmu_events(NULL, false);
                        else if (strcmp(argv[i], "--raw-dump") == 0)
                                print_events(NULL, true);
                        else {
index a5076f4f6016372361dbc4855dc123082a809292..2c460ede0a69de878b71d187ec74b59568117d92 100644 (file)
@@ -1110,6 +1110,8 @@ int print_hwcache_events(const char *event_glob, bool name_only)
                }
        }
 
+       if (printed)
+               printf("\n");
        return printed;
 }
 
@@ -1164,11 +1166,12 @@ void print_events(const char *event_glob, bool name_only)
 
        print_hwcache_events(event_glob, name_only);
 
+       print_pmu_events(event_glob, name_only);
+
        if (event_glob != NULL)
                return;
 
        if (!name_only) {
-               printf("\n");
                printf("  %-50s [%s]\n",
                       "rNNN",
                       event_type_descriptors[PERF_TYPE_RAW]);
index 1d1862dcbbbc6a863932da4d02ff0bd53a6abf55..bc9d8069d37637835758d02e13ec3bc751d0f5e3 100644 (file)
@@ -564,3 +564,76 @@ void perf_pmu__set_format(unsigned long *bits, long from, long to)
        for (b = from; b <= to; b++)
                set_bit(b, bits);
 }
+
+static char *format_alias(char *buf, int len, struct perf_pmu *pmu,
+                         struct perf_pmu_alias *alias)
+{
+       snprintf(buf, len, "%s/%s/", pmu->name, alias->name);
+       return buf;
+}
+
+static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,
+                            struct perf_pmu_alias *alias)
+{
+       snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name);
+       return buf;
+}
+
+static int cmp_string(const void *a, const void *b)
+{
+       const char * const *as = a;
+       const char * const *bs = b;
+       return strcmp(*as, *bs);
+}
+
+void print_pmu_events(const char *event_glob, bool name_only)
+{
+       struct perf_pmu *pmu;
+       struct perf_pmu_alias *alias;
+       char buf[1024];
+       int printed = 0;
+       int len, j;
+       char **aliases;
+
+       pmu = NULL;
+       len = 0;
+       while ((pmu = perf_pmu__scan(pmu)) != NULL)
+               list_for_each_entry(alias, &pmu->aliases, list)
+                       len++;
+       aliases = malloc(sizeof(char *) * len);
+       if (!aliases)
+               return;
+       pmu = NULL;
+       j = 0;
+       while ((pmu = perf_pmu__scan(pmu)) != NULL)
+               list_for_each_entry(alias, &pmu->aliases, list) {
+                       char *name = format_alias(buf, sizeof(buf), pmu, alias);
+                       bool is_cpu = !strcmp(pmu->name, "cpu");
+
+                       if (event_glob != NULL &&
+                           !(strglobmatch(name, event_glob) ||
+                             (!is_cpu && strglobmatch(alias->name,
+                                                      event_glob))))
+                               continue;
+                       aliases[j] = name;
+                       if (is_cpu && !name_only)
+                               aliases[j] = format_alias_or(buf, sizeof(buf),
+                                                             pmu, alias);
+                       aliases[j] = strdup(aliases[j]);
+                       j++;
+               }
+       len = j;
+       qsort(aliases, len, sizeof(char *), cmp_string);
+       for (j = 0; j < len; j++) {
+               if (name_only) {
+                       printf("%s ", aliases[j]);
+                       continue;
+               }
+               printf("  %-50s [Kernel PMU event]\n", aliases[j]);
+               free(aliases[j]);
+               printed++;
+       }
+       if (printed)
+               printf("\n");
+       free(aliases);
+}
index d17b5656bacf07344c0ad2c57313a661f602bdf6..6b2cbe2d4cc3a6d59a3d692770793c19ea984930 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/bitops.h>
 #include <linux/perf_event.h>
+#include <stdbool.h>
 
 enum {
        PERF_PMU_FORMAT_VALUE_CONFIG,
@@ -40,5 +41,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);
 
 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
 
+void print_pmu_events(const char *event_glob, bool name_only);
+
 int perf_pmu__test(void);
 #endif /* __PMU_H */