From 42bba263eb58800b6239a0cb35ac17fd29379277 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Tue, 12 Jul 2016 19:05:18 +0900 Subject: perf probe: Allow wildcard for cached events Allo glob wildcard for reusing cached/SDT events. E.g. # perf probe -x /usr/lib64/libc-2.20.so -a %sdt_libc:\* This example adds probes for all SDT in libc. Note that the SDTs must have been scanned by perf buildid-cache. Committer note: Using it to check what of those SDT probes would take place when doing a cargo run (rust): # trace --no-sys --event sdt_libc:* cargo run 0.000 sdt_libc:setjmp:(7f326b69c4d1)) 28.423 sdt_libc:setjmp:(7f4b0a5364d1)) 29.000 sdt_libc:setjmp:(7f4b0a5364d1)) 88.597 sdt_libc:setjmp:(7fc01fd414d1)) 89.220 sdt_libc:setjmp:(7fc01fd414d1)) 95.501 sdt_libc:setjmp:(7f326b69c4d1)) Running `target/debug/hello_world` 97.110 sdt_libc:setjmp:(7f95e09234d1)) Hello, world! # Signed-off-by: Masami Hiramatsu Tested-by: Arnaldo Carvalho de Melo Cc: Ananth N Mavinakayanahalli Cc: Brendan Gregg Cc: Hemant Kumar Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/146831791813.17065.17846564230840594888.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/probe-file.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'tools/perf/util/probe-file.c') diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index abfb05cf135b..9aed9c332da6 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -362,13 +362,38 @@ probe_cache_entry__new(struct perf_probe_event *pev) return entry; } -/* For the kernel probe caches, pass target = NULL */ +int probe_cache_entry__get_event(struct probe_cache_entry *entry, + struct probe_trace_event **tevs) +{ + struct probe_trace_event *tev; + struct str_node *node; + int ret, i; + + ret = strlist__nr_entries(entry->tevlist); + if (ret > probe_conf.max_probes) + return -E2BIG; + + *tevs = zalloc(ret * sizeof(*tev)); + if (!*tevs) + return -ENOMEM; + + i = 0; + strlist__for_each_entry(node, entry->tevlist) { + tev = &(*tevs)[i++]; + ret = parse_probe_trace_command(node->s, tev); + if (ret < 0) + break; + } + return i; +} + +/* For the kernel probe caches, pass target = NULL or DSO__NAME_KALLSYMS */ static int probe_cache__open(struct probe_cache *pcache, const char *target) { char cpath[PATH_MAX]; char sbuildid[SBUILD_ID_SIZE]; char *dir_name = NULL; - bool is_kallsyms = !target; + bool is_kallsyms = false; int ret, fd; if (target && build_id_cache__cached(target)) { @@ -378,12 +403,13 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target) goto found; } - if (target) - ret = filename__sprintf_build_id(target, sbuildid); - else { + if (!target || !strcmp(target, DSO__NAME_KALLSYMS)) { target = DSO__NAME_KALLSYMS; + is_kallsyms = true; ret = sysfs__sprintf_build_id("/", sbuildid); - } + } else + ret = filename__sprintf_build_id(target, sbuildid); + if (ret < 0) { pr_debug("Failed to get build-id from %s.\n", target); return ret; -- cgit v1.2.1