perf list: Show SDT and pre-cached events
authorMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Fri, 24 Jun 2016 09:06:46 +0000 (18:06 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 14 Jul 2016 02:09:07 +0000 (23:09 -0300)
Show SDT and pre-cached events by perf-list with "sdt". This also shows
the binary and build-id where the events are placed only when there are
same name events on different binaries.

e.g.:

  # perf list sdt

  List of pre-defined events (to be used in -e):

    sdt_libc:lll_futex_wake                            [SDT event]
    sdt_libc:lll_lock_wait_private                     [SDT event]
    sdt_libc:longjmp                                   [SDT event]
    sdt_libc:longjmp_target                            [SDT event]
  ...
    sdt_libstdcxx:rethrow@/usr/bin/gcc(0cc207fc4b27)   [SDT event]
    sdt_libstdcxx:rethrow@/usr/lib64/libstdc++.so.6.0.20(91c7a88fdf49)
    sdt_libstdcxx:throw@/usr/bin/gcc(0cc207fc4b27)     [SDT event]
    sdt_libstdcxx:throw@/usr/lib64/libstdc++.so.6.0.20(91c7a88fdf49)

The binary path and build-id are shown in below format;

  <GROUP>:<EVENT>@<PATH>(<BUILD-ID>)

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20160624090646.25421.44225.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-list.c
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/probe-file.h

index 5e22db4684b86a7a226c5d070594f160f2bc9237..88ee419e518925de5523fa08899e6935447630c3 100644 (file)
@@ -25,7 +25,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
                OPT_END()
        };
        const char * const list_usage[] = {
-               "perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
+               "perf list [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
                NULL
        };
 
@@ -62,6 +62,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
                        print_hwcache_events(NULL, raw_dump);
                else if (strcmp(argv[i], "pmu") == 0)
                        print_pmu_events(NULL, raw_dump);
+               else if (strcmp(argv[i], "sdt") == 0)
+                       print_sdt_events(NULL, NULL, raw_dump);
                else if ((sep = strchr(argv[i], ':')) != NULL) {
                        int sep_idx;
 
@@ -76,6 +78,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 
                        s[sep_idx] = '\0';
                        print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
+                       print_sdt_events(s, s + sep_idx + 1, raw_dump);
                        free(s);
                } else {
                        if (asprintf(&s, "*%s*", argv[i]) < 0) {
@@ -89,6 +92,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
                        print_hwcache_events(s, raw_dump);
                        print_pmu_events(s, raw_dump);
                        print_tracepoint_events(NULL, s, raw_dump);
+                       print_sdt_events(NULL, s, raw_dump);
                        free(s);
                }
        }
index 6b4fff375d9955a6d1e12773ff65f1e194ee9c5e..375af0e02831e603bd4b2f1d36aea0d7822be795 100644 (file)
@@ -20,6 +20,7 @@
 #include "pmu.h"
 #include "thread_map.h"
 #include "cpumap.h"
+#include "probe-file.h"
 #include "asm/bug.h"
 
 #define MAX_NAME_LEN 100
@@ -1984,6 +1985,85 @@ static bool is_event_supported(u8 type, unsigned config)
        return ret;
 }
 
+void print_sdt_events(const char *subsys_glob, const char *event_glob,
+                     bool name_only)
+{
+       struct probe_cache *pcache;
+       struct probe_cache_entry *ent;
+       struct strlist *bidlist, *sdtlist;
+       struct strlist_config cfg = {.dont_dupstr = true};
+       struct str_node *nd, *nd2;
+       char *buf, *path, *ptr = NULL;
+       bool show_detail = false;
+       int ret;
+
+       sdtlist = strlist__new(NULL, &cfg);
+       if (!sdtlist) {
+               pr_debug("Failed to allocate new strlist for SDT\n");
+               return;
+       }
+       bidlist = build_id_cache__list_all(true);
+       if (!bidlist) {
+               pr_debug("Failed to get buildids: %d\n", errno);
+               return;
+       }
+       strlist__for_each_entry(nd, bidlist) {
+               pcache = probe_cache__new(nd->s);
+               if (!pcache)
+                       continue;
+               list_for_each_entry(ent, &pcache->entries, node) {
+                       if (!ent->sdt)
+                               continue;
+                       if (subsys_glob &&
+                           !strglobmatch(ent->pev.group, subsys_glob))
+                               continue;
+                       if (event_glob &&
+                           !strglobmatch(ent->pev.event, event_glob))
+                               continue;
+                       ret = asprintf(&buf, "%s:%s@%s", ent->pev.group,
+                                       ent->pev.event, nd->s);
+                       if (ret > 0)
+                               strlist__add(sdtlist, buf);
+               }
+               probe_cache__delete(pcache);
+       }
+       strlist__delete(bidlist);
+
+       strlist__for_each_entry(nd, sdtlist) {
+               buf = strchr(nd->s, '@');
+               if (buf)
+                       *(buf++) = '\0';
+               if (name_only) {
+                       printf("%s ", nd->s);
+                       continue;
+               }
+               nd2 = strlist__next(nd);
+               if (nd2) {
+                       ptr = strchr(nd2->s, '@');
+                       if (ptr)
+                               *ptr = '\0';
+                       if (strcmp(nd->s, nd2->s) == 0)
+                               show_detail = true;
+               }
+               if (show_detail) {
+                       path = build_id_cache__origname(buf);
+                       ret = asprintf(&buf, "%s@%s(%.12s)", nd->s, path, buf);
+                       if (ret > 0) {
+                               printf("  %-50s [%s]\n", buf, "SDT event");
+                               free(buf);
+                       }
+               } else
+                       printf("  %-50s [%s]\n", nd->s, "SDT event");
+               if (nd2) {
+                       if (strcmp(nd->s, nd2->s) != 0)
+                               show_detail = false;
+                       if (ptr)
+                               *ptr = '@';
+               }
+       }
+       strlist__delete(sdtlist);
+}
+
 int print_hwcache_events(const char *event_glob, bool name_only)
 {
        unsigned int type, op, i, evt_i = 0, evt_num = 0;
@@ -2166,6 +2246,8 @@ void print_events(const char *event_glob, bool name_only)
        }
 
        print_tracepoint_events(NULL, NULL, name_only);
+
+       print_sdt_events(NULL, NULL, name_only);
 }
 
 int parse_events__is_hardcoded_term(struct parse_events_term *term)
index 0bd664dfa53cdf9f293c165c0585f379e8fdaf78..b4aa7eb2df7312781f59dcf8e31f00a66f46dc54 100644 (file)
@@ -183,6 +183,8 @@ void print_symbol_events(const char *event_glob, unsigned type,
 void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
                             bool name_only);
 int print_hwcache_events(const char *event_glob, bool name_only);
+void print_sdt_events(const char *subsys_glob, const char *event_glob,
+                     bool name_only);
 int is_valid_tracepoint(const char *event_string);
 
 int valid_event_mount(const char *eventfs);
index cafbe1d3f3bfcf2821ca2d499cbddc46b1bea415..9577b5c0b487ee6adb017555521ad6dcd497a621 100644 (file)
@@ -24,6 +24,8 @@ struct probe_cache {
 #define for_each_probe_cache_entry(entry, pcache) \
        list_for_each_entry(entry, &pcache->entries, node)
 
+/* probe-file.c depends on libelf */
+#ifdef HAVE_LIBELF_SUPPORT
 int probe_file__open(int flag);
 int probe_file__open_both(int *kfd, int *ufd, int flag);
 struct strlist *probe_file__get_namelist(int fd);
@@ -52,4 +54,11 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
 struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
                                        const char *group, const char *event);
 int probe_cache__show_all_caches(struct strfilter *filter);
+#else  /* ! HAVE_LIBELF_SUPPORT */
+static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
+{
+       return NULL;
+}
+#define probe_cache__delete(pcache) do {} while (0)
+#endif
 #endif