Skip to content

Commit 40218da

Browse files
mhiramathitachiacmel
authored andcommitted
perf list: Show SDT and pre-cached events
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 <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Brendan Gregg <[email protected]> Cc: Hemant Kumar <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/20160624090646.25421.44225.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 1de7b8b commit 40218da

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

tools/perf/builtin-list.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
2525
OPT_END()
2626
};
2727
const char * const list_usage[] = {
28-
"perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
28+
"perf list [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
2929
NULL
3030
};
3131

@@ -62,6 +62,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
6262
print_hwcache_events(NULL, raw_dump);
6363
else if (strcmp(argv[i], "pmu") == 0)
6464
print_pmu_events(NULL, raw_dump);
65+
else if (strcmp(argv[i], "sdt") == 0)
66+
print_sdt_events(NULL, NULL, raw_dump);
6567
else if ((sep = strchr(argv[i], ':')) != NULL) {
6668
int sep_idx;
6769

@@ -76,6 +78,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
7678

7779
s[sep_idx] = '\0';
7880
print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
81+
print_sdt_events(s, s + sep_idx + 1, raw_dump);
7982
free(s);
8083
} else {
8184
if (asprintf(&s, "*%s*", argv[i]) < 0) {
@@ -89,6 +92,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
8992
print_hwcache_events(s, raw_dump);
9093
print_pmu_events(s, raw_dump);
9194
print_tracepoint_events(NULL, s, raw_dump);
95+
print_sdt_events(NULL, s, raw_dump);
9296
free(s);
9397
}
9498
}

tools/perf/util/parse-events.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "pmu.h"
2121
#include "thread_map.h"
2222
#include "cpumap.h"
23+
#include "probe-file.h"
2324
#include "asm/bug.h"
2425

2526
#define MAX_NAME_LEN 100
@@ -1984,6 +1985,85 @@ static bool is_event_supported(u8 type, unsigned config)
19841985
return ret;
19851986
}
19861987

1988+
void print_sdt_events(const char *subsys_glob, const char *event_glob,
1989+
bool name_only)
1990+
{
1991+
struct probe_cache *pcache;
1992+
struct probe_cache_entry *ent;
1993+
struct strlist *bidlist, *sdtlist;
1994+
struct strlist_config cfg = {.dont_dupstr = true};
1995+
struct str_node *nd, *nd2;
1996+
char *buf, *path, *ptr = NULL;
1997+
bool show_detail = false;
1998+
int ret;
1999+
2000+
sdtlist = strlist__new(NULL, &cfg);
2001+
if (!sdtlist) {
2002+
pr_debug("Failed to allocate new strlist for SDT\n");
2003+
return;
2004+
}
2005+
bidlist = build_id_cache__list_all(true);
2006+
if (!bidlist) {
2007+
pr_debug("Failed to get buildids: %d\n", errno);
2008+
return;
2009+
}
2010+
strlist__for_each_entry(nd, bidlist) {
2011+
pcache = probe_cache__new(nd->s);
2012+
if (!pcache)
2013+
continue;
2014+
list_for_each_entry(ent, &pcache->entries, node) {
2015+
if (!ent->sdt)
2016+
continue;
2017+
if (subsys_glob &&
2018+
!strglobmatch(ent->pev.group, subsys_glob))
2019+
continue;
2020+
if (event_glob &&
2021+
!strglobmatch(ent->pev.event, event_glob))
2022+
continue;
2023+
ret = asprintf(&buf, "%s:%s@%s", ent->pev.group,
2024+
ent->pev.event, nd->s);
2025+
if (ret > 0)
2026+
strlist__add(sdtlist, buf);
2027+
}
2028+
probe_cache__delete(pcache);
2029+
}
2030+
strlist__delete(bidlist);
2031+
2032+
strlist__for_each_entry(nd, sdtlist) {
2033+
buf = strchr(nd->s, '@');
2034+
if (buf)
2035+
*(buf++) = '\0';
2036+
if (name_only) {
2037+
printf("%s ", nd->s);
2038+
continue;
2039+
}
2040+
nd2 = strlist__next(nd);
2041+
if (nd2) {
2042+
ptr = strchr(nd2->s, '@');
2043+
if (ptr)
2044+
*ptr = '\0';
2045+
if (strcmp(nd->s, nd2->s) == 0)
2046+
show_detail = true;
2047+
}
2048+
if (show_detail) {
2049+
path = build_id_cache__origname(buf);
2050+
ret = asprintf(&buf, "%s@%s(%.12s)", nd->s, path, buf);
2051+
if (ret > 0) {
2052+
printf(" %-50s [%s]\n", buf, "SDT event");
2053+
free(buf);
2054+
}
2055+
} else
2056+
printf(" %-50s [%s]\n", nd->s, "SDT event");
2057+
if (nd2) {
2058+
if (strcmp(nd->s, nd2->s) != 0)
2059+
show_detail = false;
2060+
if (ptr)
2061+
*ptr = '@';
2062+
}
2063+
}
2064+
strlist__delete(sdtlist);
2065+
}
2066+
19872067
int print_hwcache_events(const char *event_glob, bool name_only)
19882068
{
19892069
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)
21662246
}
21672247

21682248
print_tracepoint_events(NULL, NULL, name_only);
2249+
2250+
print_sdt_events(NULL, NULL, name_only);
21692251
}
21702252

21712253
int parse_events__is_hardcoded_term(struct parse_events_term *term)

tools/perf/util/parse-events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ void print_symbol_events(const char *event_glob, unsigned type,
183183
void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
184184
bool name_only);
185185
int print_hwcache_events(const char *event_glob, bool name_only);
186+
void print_sdt_events(const char *subsys_glob, const char *event_glob,
187+
bool name_only);
186188
int is_valid_tracepoint(const char *event_string);
187189

188190
int valid_event_mount(const char *eventfs);

tools/perf/util/probe-file.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct probe_cache {
2424
#define for_each_probe_cache_entry(entry, pcache) \
2525
list_for_each_entry(entry, &pcache->entries, node)
2626

27+
/* probe-file.c depends on libelf */
28+
#ifdef HAVE_LIBELF_SUPPORT
2729
int probe_file__open(int flag);
2830
int probe_file__open_both(int *kfd, int *ufd, int flag);
2931
struct strlist *probe_file__get_namelist(int fd);
@@ -52,4 +54,11 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
5254
struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
5355
const char *group, const char *event);
5456
int probe_cache__show_all_caches(struct strfilter *filter);
57+
#else /* ! HAVE_LIBELF_SUPPORT */
58+
static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
59+
{
60+
return NULL;
61+
}
62+
#define probe_cache__delete(pcache) do {} while (0)
63+
#endif
5564
#endif

0 commit comments

Comments
 (0)