Hi,
Here is the 2nd version of the patchset for probe-cache and
initial SDT support which are going to be perf-cache finally.
The perf-probe is useful for debugging, but it strongly depends
on the debuginfo. Without debuginfo, it is just a frontend of
ftrace's dynamic events. This can usually happen in server
farms or on cloud system, since no one wants to distribute
big debuginfo packages.
To solve this issue, I had tried to make a pre-analyzed probes
( https://lkml.org/lkml/2014/10/31/207 ) but it has a problm
that we can't ensure the probed binary is same as what we analyzed.
Arnaldo gave me an idea to reuse build-id cache for that perpose
and this series is the first prototype of that.
At the same time, Hemant has started to support SDT probes which
also use the cache file of SDT info. So I decided to merge this
into the same build-id cache.
In this version, SDT support is still very limited, it works
as a part of probe-cache.
In this version, perf probe supports --cache option which means
that perf probe manipulate probe caches, for example,
# perf probe --cache --add "probe-desc"
does not only add probe events but also add "probe-desc" and
it's result on the cache. (Note that the cached entry is always
referred even without --cache)
The --list and --del commands also support --cache. Note that
both are only manipulate caches, not real events.
To use SDT, we have to scan the target binary at first by using
perf-buildid-cache, e.g.
# perf buildid-cache --add /lib/libc-2.17.so
And perf probe --cache --list shows what SDTs are scanned.
# perf probe --cache --list
/usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
libc:setjmp=setjmp
libc:longjmp=longjmp
libc:longjmp_target=longjmp_target
libc:memory_heap_new=memory_heap_new
libc:memory_sbrk_less=memory_sbrk_less
libc:memory_arena_reuse_free_list=memory_arena_reuse_free_list
libc:memory_arena_reuse=memory_arena_reuse
...
To use the SDT events, perf probe -x BIN %SDTEVENT allows you to
add a probe on SDTEVENT@BIN.
# perf probe -x /lib/libc-2.17.so %memory_heap_new
If you define a cached probe with event name, you can also reuse
it as same as SDT events.
# perf probe -x ./perf --cache -n 'myevent=dso__load $params'
(Note that "-n" option only updates caches)
To use the above "myevent", you just have to add "%myevent".
# perf probe -x ./perf %myevent
TODOs:
- Show available cached/SDT events by perf-list
- Allow perf-record to use cached/SDT events directly
Thank you,
---
Hemant Kumar (1):
perf/sdt: ELF support for SDT
Masami Hiramatsu (15):
perf probe: Simplify __add_probe_trace_events code
perf probe: Move ftrace probe-event operations to probe-file.c
perf probe: Use strbuf for making strings in probe-event.c
perf-buildid-cache: Use path/to/bin/buildid/elf instead of path/to/bin/buildid
perf buildid: Use SBUILD_ID_SIZE macro
perf buildid: Introduce sysfs/filename__sprintf_build_id
perf: Add lsdir to read a directory
perf-buildid-cache: Use lsdir for looking up buildid caches
perf probe: Add --cache option to cache the probe definitions
perf probe: Use cache entry if possible
perf probe: Show all cached probes
perf probe: Remove caches when --cache is given
perf probe: Add group name support
perf buildid-cache: Scan and import user SDT events to probe cache
perf probe: Accept %sdt and %cached event name
tools/perf/Documentation/perf-probe.txt | 14
tools/perf/builtin-buildid-cache.c | 22 -
tools/perf/builtin-buildid-list.c | 28 -
tools/perf/builtin-probe.c | 3
tools/perf/util/Build | 1
tools/perf/util/build-id.c | 230 ++++++--
tools/perf/util/build-id.h | 11
tools/perf/util/dso.h | 5
tools/perf/util/probe-event.c | 918 ++++++++++++++-----------------
tools/perf/util/probe-event.h | 16 -
tools/perf/util/probe-file.c | 763 ++++++++++++++++++++++++++
tools/perf/util/probe-file.h | 46 ++
tools/perf/util/probe-finder.c | 10
tools/perf/util/symbol-elf.c | 252 +++++++++
tools/perf/util/symbol.c | 2
tools/perf/util/symbol.h | 22 +
tools/perf/util/util.c | 34 +
tools/perf/util/util.h | 4
18 files changed, 1781 insertions(+), 600 deletions(-)
create mode 100644 tools/perf/util/probe-file.c
create mode 100644 tools/perf/util/probe-file.h
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Simplify the __add_probe_trace_events() code by taking out the
probe_trace_event__set_name() and updating show_perf_probe_event()
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/probe-event.c | 70 +++++++++++++++++++++++++----------------
1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 381f23a..1e1afe0 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2478,16 +2478,54 @@ out:
free(buf);
}
+/* Set new name from original perf_probe_event and namelist */
+static int probe_trace_event__set_name(struct probe_trace_event *tev,
+ struct perf_probe_event *pev,
+ struct strlist *namelist,
+ bool allow_suffix)
+{
+ const char *event, *group;
+ char buf[64];
+ int ret;
+
+ if (pev->event)
+ event = pev->event;
+ else
+ if (pev->point.function && !strisglob(pev->point.function))
+ event = pev->point.function;
+ else
+ event = tev->point.realname;
+ if (pev->group)
+ group = pev->group;
+ else
+ group = PERFPROBE_GROUP;
+
+ /* Get an unused new event name */
+ ret = get_new_event_name(buf, 64, event,
+ namelist, allow_suffix);
+ if (ret < 0)
+ return ret;
+
+ event = buf;
+
+ tev->event = strdup(event);
+ tev->group = strdup(group);
+ if (tev->event == NULL || tev->group == NULL)
+ return -ENOMEM;
+
+ /* Add added event name to namelist */
+ strlist__add(namelist, event);
+ return 0;
+}
+
static int __add_probe_trace_events(struct perf_probe_event *pev,
struct probe_trace_event *tevs,
int ntevs, bool allow_suffix)
{
int i, fd, ret;
struct probe_trace_event *tev = NULL;
- char buf[64];
const char *event = NULL, *group = NULL;
struct strlist *namelist;
- bool safename;
if (pev->uprobes)
fd = open_uprobe_events(true);
@@ -2507,7 +2545,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
goto close_out;
}
- safename = (pev->point.function && !strisglob(pev->point.function));
ret = 0;
pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
for (i = 0; i < ntevs; i++) {
@@ -2516,36 +2553,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
if (!tev->point.symbol)
continue;
- if (pev->event)
- event = pev->event;
- else
- if (safename)
- event = pev->point.function;
- else
- event = tev->point.realname;
- if (pev->group)
- group = pev->group;
- else
- group = PERFPROBE_GROUP;
-
- /* Get an unused new event name */
- ret = get_new_event_name(buf, 64, event,
- namelist, allow_suffix);
+ /* Set new name for tev (and update namelist) */
+ ret = probe_trace_event__set_name(tev, pev, namelist,
+ allow_suffix);
if (ret < 0)
break;
- event = buf;
- tev->event = strdup(event);
- tev->group = strdup(group);
- if (tev->event == NULL || tev->group == NULL) {
- ret = -ENOMEM;
- break;
- }
ret = write_probe_trace_event(fd, tev);
if (ret < 0)
break;
- /* Add added event name to namelist */
- strlist__add(namelist, event);
/* We use tev's name for showing new events */
show_perf_probe_event(tev->group, tev->event, pev,
Move ftrace probe-event operations to probe-file.c from probe-event.c.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/Build | 1
tools/perf/util/probe-event.c | 318 +++--------------------------------------
tools/perf/util/probe-event.h | 7 +
tools/perf/util/probe-file.c | 302 +++++++++++++++++++++++++++++++++++++++
tools/perf/util/probe-file.h | 18 ++
5 files changed, 354 insertions(+), 292 deletions(-)
create mode 100644 tools/perf/util/probe-file.c
create mode 100644 tools/perf/util/probe-file.h
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 601d114..8d1bdf8 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -79,6 +79,7 @@ libperf-$(CONFIG_AUXTRACE) += auxtrace.o
libperf-y += parse-branch-options.o
libperf-$(CONFIG_LIBELF) += symbol-elf.o
+libperf-$(CONFIG_LIBELF) += probe-file.o
libperf-$(CONFIG_LIBELF) += probe-event.o
ifndef CONFIG_LIBELF
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 1e1afe0..fe4941a 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -45,6 +45,7 @@
#include "trace-event.h" /* For __maybe_unused */
#include "probe-event.h"
#include "probe-finder.h"
+#include "probe-file.h"
#include "session.h"
#define MAX_CMDLEN 256
@@ -55,11 +56,7 @@ struct probe_conf probe_conf;
#define semantic_error(msg ...) pr_err("Semantic error :" msg)
-/* If there is no space to write, returns -E2BIG. */
-static int e_snprintf(char *str, size_t size, const char *format, ...)
- __attribute__((format(printf, 3, 4)));
-
-static int e_snprintf(char *str, size_t size, const char *format, ...)
+int e_snprintf(char *str, size_t size, const char *format, ...)
{
int ret;
va_list ap;
@@ -72,7 +69,6 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
}
static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
-static void clear_probe_trace_event(struct probe_trace_event *tev);
static struct machine *host_machine;
/* Initialize symbol maps and path of vmlinux/modules */
@@ -1467,8 +1463,7 @@ bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
}
/* Parse probe_events event into struct probe_point */
-static int parse_probe_trace_command(const char *cmd,
- struct probe_trace_event *tev)
+int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
{
struct probe_trace_point *tp = &tev->point;
char pr;
@@ -1951,7 +1946,7 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
memset(pev, 0, sizeof(*pev));
}
-static void clear_probe_trace_event(struct probe_trace_event *tev)
+void clear_probe_trace_event(struct probe_trace_event *tev)
{
struct probe_trace_arg_ref *ref, *next;
int i;
@@ -1976,119 +1971,6 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
memset(tev, 0, sizeof(*tev));
}
-static void print_open_warning(int err, bool is_kprobe)
-{
- char sbuf[STRERR_BUFSIZE];
-
- if (err == -ENOENT) {
- const char *config;
-
- if (!is_kprobe)
- config = "CONFIG_UPROBE_EVENTS";
- else
- config = "CONFIG_KPROBE_EVENTS";
-
- pr_warning("%cprobe_events file does not exist"
- " - please rebuild kernel with %s.\n",
- is_kprobe ? 'k' : 'u', config);
- } else if (err == -ENOTSUP)
- pr_warning("Tracefs or debugfs is not mounted.\n");
- else
- pr_warning("Failed to open %cprobe_events: %s\n",
- is_kprobe ? 'k' : 'u',
- strerror_r(-err, sbuf, sizeof(sbuf)));
-}
-
-static void print_both_open_warning(int kerr, int uerr)
-{
- /* Both kprobes and uprobes are disabled, warn it. */
- if (kerr == -ENOTSUP && uerr == -ENOTSUP)
- pr_warning("Tracefs or debugfs is not mounted.\n");
- else if (kerr == -ENOENT && uerr == -ENOENT)
- pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
- "or/and CONFIG_UPROBE_EVENTS.\n");
- else {
- char sbuf[STRERR_BUFSIZE];
- pr_warning("Failed to open kprobe events: %s.\n",
- strerror_r(-kerr, sbuf, sizeof(sbuf)));
- pr_warning("Failed to open uprobe events: %s.\n",
- strerror_r(-uerr, sbuf, sizeof(sbuf)));
- }
-}
-
-static int open_probe_events(const char *trace_file, bool readwrite)
-{
- char buf[PATH_MAX];
- const char *__debugfs;
- const char *tracing_dir = "";
- int ret;
-
- __debugfs = tracefs_find_mountpoint();
- if (__debugfs == NULL) {
- tracing_dir = "tracing/";
-
- __debugfs = debugfs_find_mountpoint();
- if (__debugfs == NULL)
- return -ENOTSUP;
- }
-
- ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
- __debugfs, tracing_dir, trace_file);
- if (ret >= 0) {
- pr_debug("Opening %s write=%d\n", buf, readwrite);
- if (readwrite && !probe_event_dry_run)
- ret = open(buf, O_RDWR | O_APPEND, 0);
- else
- ret = open(buf, O_RDONLY, 0);
-
- if (ret < 0)
- ret = -errno;
- }
- return ret;
-}
-
-static int open_kprobe_events(bool readwrite)
-{
- return open_probe_events("kprobe_events", readwrite);
-}
-
-static int open_uprobe_events(bool readwrite)
-{
- return open_probe_events("uprobe_events", readwrite);
-}
-
-/* Get raw string list of current kprobe_events or uprobe_events */
-static struct strlist *get_probe_trace_command_rawlist(int fd)
-{
- int ret, idx;
- FILE *fp;
- char buf[MAX_CMDLEN];
- char *p;
- struct strlist *sl;
-
- sl = strlist__new(true, NULL);
-
- fp = fdopen(dup(fd), "r");
- while (!feof(fp)) {
- p = fgets(buf, MAX_CMDLEN, fp);
- if (!p)
- break;
-
- idx = strlen(p) - 1;
- if (p[idx] == '\n')
- p[idx] = '\0';
- ret = strlist__add(sl, buf);
- if (ret < 0) {
- pr_debug("strlist__add failed (%d)\n", ret);
- strlist__delete(sl);
- return NULL;
- }
- }
- fclose(fp);
-
- return sl;
-}
-
struct kprobe_blacklist_node {
struct list_head list;
unsigned long start;
@@ -2284,7 +2166,7 @@ static int __show_perf_probe_events(int fd, bool is_kprobe,
memset(&tev, 0, sizeof(tev));
memset(&pev, 0, sizeof(pev));
- rawlist = get_probe_trace_command_rawlist(fd);
+ rawlist = probe_file__get_rawlist(fd);
if (!rawlist)
return -ENOMEM;
@@ -2325,89 +2207,20 @@ int show_perf_probe_events(struct strfilter *filter)
if (ret < 0)
return ret;
- kp_fd = open_kprobe_events(false);
- if (kp_fd >= 0) {
- ret = __show_perf_probe_events(kp_fd, true, filter);
- close(kp_fd);
- if (ret < 0)
- goto out;
- }
-
- up_fd = open_uprobe_events(false);
- if (kp_fd < 0 && up_fd < 0) {
- print_both_open_warning(kp_fd, up_fd);
- ret = kp_fd;
- goto out;
- }
+ ret = probe_file__open_both(&kp_fd, &up_fd, 0);
+ if (ret < 0)
+ return ret;
- if (up_fd >= 0) {
+ if (kp_fd >= 0)
+ ret = __show_perf_probe_events(kp_fd, true, filter);
+ if (up_fd >= 0 && ret >= 0)
ret = __show_perf_probe_events(up_fd, false, filter);
+ if (kp_fd > 0)
+ close(kp_fd);
+ if (up_fd > 0)
close(up_fd);
- }
-out:
exit_symbol_maps();
- return ret;
-}
-/* Get current perf-probe event names */
-static struct strlist *get_probe_trace_event_names(int fd, bool include_group)
-{
- char buf[128];
- struct strlist *sl, *rawlist;
- struct str_node *ent;
- struct probe_trace_event tev;
- int ret = 0;
-
- memset(&tev, 0, sizeof(tev));
- rawlist = get_probe_trace_command_rawlist(fd);
- if (!rawlist)
- return NULL;
- sl = strlist__new(true, NULL);
- strlist__for_each(ent, rawlist) {
- ret = parse_probe_trace_command(ent->s, &tev);
- if (ret < 0)
- break;
- if (include_group) {
- ret = e_snprintf(buf, 128, "%s:%s", tev.group,
- tev.event);
- if (ret >= 0)
- ret = strlist__add(sl, buf);
- } else
- ret = strlist__add(sl, tev.event);
- clear_probe_trace_event(&tev);
- if (ret < 0)
- break;
- }
- strlist__delete(rawlist);
-
- if (ret < 0) {
- strlist__delete(sl);
- return NULL;
- }
- return sl;
-}
-
-static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
-{
- int ret = 0;
- char *buf = synthesize_probe_trace_command(tev);
- char sbuf[STRERR_BUFSIZE];
-
- if (!buf) {
- pr_debug("Failed to synthesize probe trace event.\n");
- return -EINVAL;
- }
-
- pr_debug("Writing event: %s\n", buf);
- if (!probe_event_dry_run) {
- ret = write(fd, buf, strlen(buf));
- if (ret <= 0) {
- ret = -errno;
- pr_warning("Failed to write event: %s\n",
- strerror_r(errno, sbuf, sizeof(sbuf)));
- }
- }
- free(buf);
return ret;
}
@@ -2527,18 +2340,12 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
const char *event = NULL, *group = NULL;
struct strlist *namelist;
- if (pev->uprobes)
- fd = open_uprobe_events(true);
- else
- fd = open_kprobe_events(true);
-
- if (fd < 0) {
- print_open_warning(fd, !pev->uprobes);
+ fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));
+ if (fd < 0)
return fd;
- }
/* Get current event names */
- namelist = get_probe_trace_event_names(fd, false);
+ namelist = probe_file__get_namelist(fd);
if (!namelist) {
pr_debug("Failed to get current event list.\n");
ret = -ENOMEM;
@@ -2559,7 +2366,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
if (ret < 0)
break;
- ret = write_probe_trace_event(fd, tev);
+ ret = probe_file__add_event(fd, tev);
if (ret < 0)
break;
@@ -2854,68 +2661,9 @@ end:
return ret;
}
-static int __del_trace_probe_event(int fd, struct str_node *ent)
-{
- char *p;
- char buf[128];
- int ret;
-
- /* Convert from perf-probe event to trace-probe event */
- ret = e_snprintf(buf, 128, "-:%s", ent->s);
- if (ret < 0)
- goto error;
-
- p = strchr(buf + 2, ':');
- if (!p) {
- pr_debug("Internal error: %s should have ':' but not.\n",
- ent->s);
- ret = -ENOTSUP;
- goto error;
- }
- *p = '/';
-
- pr_debug("Writing event: %s\n", buf);
- ret = write(fd, buf, strlen(buf));
- if (ret < 0) {
- ret = -errno;
- goto error;
- }
-
- pr_info("Removed event: %s\n", ent->s);
- return 0;
-error:
- pr_warning("Failed to delete event: %s\n",
- strerror_r(-ret, buf, sizeof(buf)));
- return ret;
-}
-
-static int del_trace_probe_events(int fd, struct strfilter *filter,
- struct strlist *namelist)
-{
- struct str_node *ent;
- const char *p;
- int ret = -ENOENT;
-
- if (!namelist)
- return -ENOENT;
-
- strlist__for_each(ent, namelist) {
- p = strchr(ent->s, ':');
- if ((p && strfilter__compare(filter, p + 1)) ||
- strfilter__compare(filter, ent->s)) {
- ret = __del_trace_probe_event(fd, ent);
- if (ret < 0)
- break;
- }
- }
-
- return ret;
-}
-
int del_perf_probe_events(struct strfilter *filter)
{
int ret, ret2, ufd = -1, kfd = -1;
- struct strlist *namelist = NULL, *unamelist = NULL;
char *str = strfilter__string(filter);
if (!str)
@@ -2924,25 +2672,15 @@ int del_perf_probe_events(struct strfilter *filter)
pr_debug("Delete filter: \'%s\'\n", str);
/* Get current event names */
- kfd = open_kprobe_events(true);
- if (kfd >= 0)
- namelist = get_probe_trace_event_names(kfd, true);
-
- ufd = open_uprobe_events(true);
- if (ufd >= 0)
- unamelist = get_probe_trace_event_names(ufd, true);
-
- if (kfd < 0 && ufd < 0) {
- print_both_open_warning(kfd, ufd);
- ret = kfd;
- goto error;
- }
+ ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);
+ if (ret < 0)
+ goto out;
- ret = del_trace_probe_events(kfd, filter, namelist);
+ ret = probe_file__del_events(kfd, filter);
if (ret < 0 && ret != -ENOENT)
goto error;
- ret2 = del_trace_probe_events(ufd, filter, unamelist);
+ ret2 = probe_file__del_events(ufd, filter);
if (ret2 < 0 && ret2 != -ENOENT) {
ret = ret2;
goto error;
@@ -2953,15 +2691,11 @@ int del_perf_probe_events(struct strfilter *filter)
ret = 0;
error:
- if (kfd >= 0) {
- strlist__delete(namelist);
+ if (kfd >= 0)
close(kfd);
- }
-
- if (ufd >= 0) {
- strlist__delete(unamelist);
+ if (ufd >= 0)
close(ufd);
- }
+out:
free(str);
return ret;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 31db6ee..20f555d 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -109,6 +109,8 @@ struct variable_list {
/* Command string to events */
extern int parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev);
+extern int parse_probe_trace_command(const char *cmd,
+ struct probe_trace_event *tev);
/* Events to command string */
extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
@@ -121,6 +123,7 @@ extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
/* Release event contents */
extern void clear_perf_probe_event(struct perf_probe_event *pev);
+extern void clear_probe_trace_event(struct probe_trace_event *tev);
/* Command string to line-range */
extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
@@ -144,6 +147,10 @@ bool arch__prefers_symtab(void);
void arch__fix_tev_from_maps(struct perf_probe_event *pev,
struct probe_trace_event *tev, struct map *map);
+/* If there is no space to write, returns -E2BIG. */
+int e_snprintf(char *str, size_t size, const char *format, ...)
+ __attribute__((format(printf, 3, 4)));
+
/* Maximum index number of event-name postfix */
#define MAX_EVENT_INDEX 1024
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
new file mode 100644
index 0000000..2a7cc8c
--- /dev/null
+++ b/tools/perf/util/probe-file.c
@@ -0,0 +1,302 @@
+/*
+ * probe-file.c : operate ftrace k/uprobe events files
+ *
+ * Written by Masami Hiramatsu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include "util.h"
+#include "event.h"
+#include "strlist.h"
+#include "debug.h"
+#include "cache.h"
+#include "color.h"
+#include "symbol.h"
+#include "thread.h"
+#include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
+#include "probe-event.h"
+#include "probe-file.h"
+#include "session.h"
+
+#define MAX_CMDLEN 256
+
+static void print_open_warning(int err, bool uprobe)
+{
+ char sbuf[STRERR_BUFSIZE];
+
+ if (err == -ENOENT) {
+ const char *config;
+
+ if (uprobe)
+ config = "CONFIG_UPROBE_EVENTS";
+ else
+ config = "CONFIG_KPROBE_EVENTS";
+
+ pr_warning("%cprobe_events file does not exist"
+ " - please rebuild kernel with %s.\n",
+ uprobe ? 'u' : 'k', config);
+ } else if (err == -ENOTSUP)
+ pr_warning("Tracefs or debugfs is not mounted.\n");
+ else
+ pr_warning("Failed to open %cprobe_events: %s\n",
+ uprobe ? 'u' : 'k',
+ strerror_r(-err, sbuf, sizeof(sbuf)));
+}
+
+static void print_both_open_warning(int kerr, int uerr)
+{
+ /* Both kprobes and uprobes are disabled, warn it. */
+ if (kerr == -ENOTSUP && uerr == -ENOTSUP)
+ pr_warning("Tracefs or debugfs is not mounted.\n");
+ else if (kerr == -ENOENT && uerr == -ENOENT)
+ pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
+ "or/and CONFIG_UPROBE_EVENTS.\n");
+ else {
+ char sbuf[STRERR_BUFSIZE];
+ pr_warning("Failed to open kprobe events: %s.\n",
+ strerror_r(-kerr, sbuf, sizeof(sbuf)));
+ pr_warning("Failed to open uprobe events: %s.\n",
+ strerror_r(-uerr, sbuf, sizeof(sbuf)));
+ }
+}
+
+static int open_probe_events(const char *trace_file, bool readwrite)
+{
+ char buf[PATH_MAX];
+ const char *__debugfs;
+ const char *tracing_dir = "";
+ int ret;
+
+ __debugfs = tracefs_find_mountpoint();
+ if (__debugfs == NULL) {
+ tracing_dir = "tracing/";
+
+ __debugfs = debugfs_find_mountpoint();
+ if (__debugfs == NULL)
+ return -ENOTSUP;
+ }
+
+ ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
+ __debugfs, tracing_dir, trace_file);
+ if (ret >= 0) {
+ pr_debug("Opening %s write=%d\n", buf, readwrite);
+ if (readwrite && !probe_event_dry_run)
+ ret = open(buf, O_RDWR | O_APPEND, 0);
+ else
+ ret = open(buf, O_RDONLY, 0);
+
+ if (ret < 0)
+ ret = -errno;
+ }
+ return ret;
+}
+
+static int open_kprobe_events(bool readwrite)
+{
+ return open_probe_events("kprobe_events", readwrite);
+}
+
+static int open_uprobe_events(bool readwrite)
+{
+ return open_probe_events("uprobe_events", readwrite);
+}
+
+int probe_file__open(int flag)
+{
+ int fd;
+
+ if (flag & PF_FL_UPROBE)
+ fd = open_uprobe_events(flag & PF_FL_RW);
+ else
+ fd = open_kprobe_events(flag & PF_FL_RW);
+ if (fd < 0)
+ print_open_warning(fd, flag & PF_FL_UPROBE);
+
+ return fd;
+}
+
+int probe_file__open_both(int *kfd, int *ufd, int flag)
+{
+ if (!kfd || !ufd)
+ return -EINVAL;
+
+ *kfd = open_kprobe_events(flag & PF_FL_RW);
+ *ufd = open_uprobe_events(flag & PF_FL_RW);
+ if (*kfd < 0 && *ufd < 0) {
+ print_both_open_warning(*kfd, *ufd);
+ return *kfd;
+ }
+
+ return 0;
+}
+
+/* Get raw string list of current kprobe_events or uprobe_events */
+struct strlist *probe_file__get_rawlist(int fd)
+{
+ int ret, idx;
+ FILE *fp;
+ char buf[MAX_CMDLEN];
+ char *p;
+ struct strlist *sl;
+
+ sl = strlist__new(true, NULL);
+
+ fp = fdopen(dup(fd), "r");
+ while (!feof(fp)) {
+ p = fgets(buf, MAX_CMDLEN, fp);
+ if (!p)
+ break;
+
+ idx = strlen(p) - 1;
+ if (p[idx] == '\n')
+ p[idx] = '\0';
+ ret = strlist__add(sl, buf);
+ if (ret < 0) {
+ pr_debug("strlist__add failed (%d)\n", ret);
+ strlist__delete(sl);
+ return NULL;
+ }
+ }
+ fclose(fp);
+
+ return sl;
+}
+
+static struct strlist *__probe_file__get_namelist(int fd, bool include_group)
+{
+ char buf[128];
+ struct strlist *sl, *rawlist;
+ struct str_node *ent;
+ struct probe_trace_event tev;
+ int ret = 0;
+
+ memset(&tev, 0, sizeof(tev));
+ rawlist = probe_file__get_rawlist(fd);
+ if (!rawlist)
+ return NULL;
+ sl = strlist__new(true, NULL);
+ strlist__for_each(ent, rawlist) {
+ ret = parse_probe_trace_command(ent->s, &tev);
+ if (ret < 0)
+ break;
+ if (include_group) {
+ ret = e_snprintf(buf, 128, "%s:%s", tev.group,
+ tev.event);
+ if (ret >= 0)
+ ret = strlist__add(sl, buf);
+ } else
+ ret = strlist__add(sl, tev.event);
+ clear_probe_trace_event(&tev);
+ if (ret < 0)
+ break;
+ }
+ strlist__delete(rawlist);
+
+ if (ret < 0) {
+ strlist__delete(sl);
+ return NULL;
+ }
+ return sl;
+}
+
+/* Get current perf-probe event names */
+struct strlist *probe_file__get_namelist(int fd)
+{
+ return __probe_file__get_namelist(fd, false);
+}
+
+int probe_file__add_event(int fd, struct probe_trace_event *tev)
+{
+ int ret = 0;
+ char *buf = synthesize_probe_trace_command(tev);
+ char sbuf[STRERR_BUFSIZE];
+
+ if (!buf) {
+ pr_debug("Failed to synthesize probe trace event.\n");
+ return -EINVAL;
+ }
+
+ pr_debug("Writing event: %s\n", buf);
+ if (!probe_event_dry_run) {
+ ret = write(fd, buf, strlen(buf));
+ if (ret <= 0) {
+ ret = -errno;
+ pr_warning("Failed to write event: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
+ }
+ }
+ free(buf);
+
+ return ret;
+}
+
+static int __del_trace_probe_event(int fd, struct str_node *ent)
+{
+ char *p;
+ char buf[128];
+ int ret;
+
+ /* Convert from perf-probe event to trace-probe event */
+ ret = e_snprintf(buf, 128, "-:%s", ent->s);
+ if (ret < 0)
+ goto error;
+
+ p = strchr(buf + 2, ':');
+ if (!p) {
+ pr_debug("Internal error: %s should have ':' but not.\n",
+ ent->s);
+ ret = -ENOTSUP;
+ goto error;
+ }
+ *p = '/';
+
+ pr_debug("Writing event: %s\n", buf);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ ret = -errno;
+ goto error;
+ }
+
+ pr_info("Removed event: %s\n", ent->s);
+ return 0;
+error:
+ pr_warning("Failed to delete event: %s\n",
+ strerror_r(-ret, buf, sizeof(buf)));
+ return ret;
+}
+
+int probe_file__del_events(int fd, struct strfilter *filter)
+{
+ struct strlist *namelist;
+ struct str_node *ent;
+ const char *p;
+ int ret = -ENOENT;
+
+ namelist = __probe_file__get_namelist(fd, true);
+ if (!namelist)
+ return -ENOENT;
+
+ strlist__for_each(ent, namelist) {
+ p = strchr(ent->s, ':');
+ if ((p && strfilter__compare(filter, p + 1)) ||
+ strfilter__compare(filter, ent->s)) {
+ ret = __del_trace_probe_event(fd, ent);
+ if (ret < 0)
+ break;
+ }
+ }
+ strlist__delete(namelist);
+
+ return ret;
+}
+
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
new file mode 100644
index 0000000..ada94a2
--- /dev/null
+++ b/tools/perf/util/probe-file.h
@@ -0,0 +1,18 @@
+#ifndef __PROBE_FILE_H
+#define __PROBE_FILE_H
+
+#include "strlist.h"
+#include "strfilter.h"
+#include "probe-event.h"
+
+#define PF_FL_UPROBE 1
+#define PF_FL_RW 2
+
+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);
+struct strlist *probe_file__get_rawlist(int fd);
+int probe_file__add_event(int fd, struct probe_trace_event *tev);
+int probe_file__del_events(int fd, struct strfilter *filter);
+
+#endif
Replace many fixed-length char array with strbuf to
stringify perf_probe_event and probe_trace_event etc. in
util/probe-event.c.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v2:
- Make perf_probe_event__sprintf() simpler.
---
tools/perf/util/probe-event.c | 242 ++++++++++++++--------------------------
tools/perf/util/probe-event.h | 3
tools/perf/util/probe-finder.c | 10 +-
3 files changed, 92 insertions(+), 163 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index fe4941a..b6ed15e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1562,69 +1562,52 @@ out:
}
/* Compose only probe arg */
-int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
+char *synthesize_perf_probe_arg(struct perf_probe_arg *pa)
{
struct perf_probe_arg_field *field = pa->field;
- int ret;
- char *tmp = buf;
+ struct strbuf buf;
+ char *ret;
+ strbuf_init(&buf, 64);
if (pa->name && pa->var)
- ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var);
+ strbuf_addf(&buf, "%s=%s", pa->name, pa->var);
else
- ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var);
- if (ret <= 0)
- goto error;
- tmp += ret;
- len -= ret;
+ strbuf_addstr(&buf, pa->name ?: pa->var);
while (field) {
if (field->name[0] == '[')
- ret = e_snprintf(tmp, len, "%s", field->name);
+ strbuf_addstr(&buf, field->name);
else
- ret = e_snprintf(tmp, len, "%s%s",
- field->ref ? "->" : ".", field->name);
- if (ret <= 0)
- goto error;
- tmp += ret;
- len -= ret;
+ strbuf_addf(&buf, "%s%s", field->ref ? "->" : ".",
+ field->name);
field = field->next;
}
- if (pa->type) {
- ret = e_snprintf(tmp, len, ":%s", pa->type);
- if (ret <= 0)
- goto error;
- tmp += ret;
- len -= ret;
- }
+ if (pa->type)
+ strbuf_addf(&buf, ":%s", pa->type);
+
+ ret = strbuf_detach(&buf, NULL);
+ strbuf_release(&buf);
- return tmp - buf;
-error:
- pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
return ret;
}
/* Compose only probe point (not argument) */
static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
{
- char *buf, *tmp;
- char offs[32] = "", line[32] = "", file[32] = "";
- int ret, len;
-
- buf = zalloc(MAX_CMDLEN);
- if (buf == NULL) {
- ret = -ENOMEM;
- goto error;
- }
- if (pp->offset) {
- ret = e_snprintf(offs, 32, "+%lu", pp->offset);
- if (ret <= 0)
- goto error;
- }
- if (pp->line) {
- ret = e_snprintf(line, 32, ":%d", pp->line);
- if (ret <= 0)
- goto error;
+ struct strbuf buf;
+ char *tmp;
+ int len;
+
+ strbuf_init(&buf, 64);
+ if (pp->function) {
+ strbuf_addstr(&buf, pp->function);
+ if (pp->offset)
+ strbuf_addf(&buf, "+%lu", pp->offset);
+ else if (pp->line)
+ strbuf_addf(&buf, ":%d", pp->line);
+ else if (pp->retprobe)
+ strbuf_addstr(&buf, "%return");
}
if (pp->file) {
tmp = pp->file;
@@ -1633,25 +1616,14 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
tmp = strchr(pp->file + len - 30, '/');
tmp = tmp ? tmp + 1 : pp->file + len - 30;
}
- ret = e_snprintf(file, 32, "@%s", tmp);
- if (ret <= 0)
- goto error;
+ strbuf_addf(&buf, "@%s", tmp);
+ if (!pp->function && pp->line)
+ strbuf_addf(&buf, ":%d", pp->line);
}
- if (pp->function)
- ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
- offs, pp->retprobe ? "%return" : "", line,
- file);
- else
- ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
- if (ret <= 0)
- goto error;
-
- return buf;
-error:
- pr_debug("Failed to synthesize perf probe point: %d\n", ret);
- free(buf);
- return NULL;
+ tmp = strbuf_detach(&buf, NULL);
+ strbuf_release(&buf);
+ return tmp;
}
#if 0
@@ -1680,45 +1652,30 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
#endif
static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref,
- char **buf, size_t *buflen,
- int depth)
+ struct strbuf *buf, int depth)
{
- int ret;
if (ref->next) {
depth = __synthesize_probe_trace_arg_ref(ref->next, buf,
- buflen, depth + 1);
+ depth + 1);
if (depth < 0)
goto out;
}
-
- ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset);
- if (ret < 0)
- depth = ret;
- else {
- *buf += ret;
- *buflen -= ret;
- }
+ strbuf_addf(buf, "%+ld(", ref->offset);
out:
return depth;
-
}
static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
- char *buf, size_t buflen)
+ struct strbuf *buf)
{
struct probe_trace_arg_ref *ref = arg->ref;
- int ret, depth = 0;
- char *tmp = buf;
+ int depth = 0;
/* Argument name or separator */
if (arg->name)
- ret = e_snprintf(buf, buflen, " %s=", arg->name);
+ strbuf_addf(buf, " %s=", arg->name);
else
- ret = e_snprintf(buf, buflen, " ");
- if (ret < 0)
- return ret;
- buf += ret;
- buflen -= ret;
+ strbuf_addch(buf, ' ');
/* Special case: @XXX */
if (arg->value[0] == '@' && arg->ref)
@@ -1726,86 +1683,58 @@ static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
/* Dereferencing arguments */
if (ref) {
- depth = __synthesize_probe_trace_arg_ref(ref, &buf,
- &buflen, 1);
+ depth = __synthesize_probe_trace_arg_ref(ref, buf, 1);
if (depth < 0)
return depth;
}
/* Print argument value */
if (arg->value[0] == '@' && arg->ref)
- ret = e_snprintf(buf, buflen, "%s%+ld", arg->value,
- arg->ref->offset);
+ strbuf_addf(buf, "%s%+ld", arg->value, arg->ref->offset);
else
- ret = e_snprintf(buf, buflen, "%s", arg->value);
- if (ret < 0)
- return ret;
- buf += ret;
- buflen -= ret;
+ strbuf_addstr(buf, arg->value);
/* Closing */
- while (depth--) {
- ret = e_snprintf(buf, buflen, ")");
- if (ret < 0)
- return ret;
- buf += ret;
- buflen -= ret;
- }
+ while (depth--)
+ strbuf_addch(buf, ')');
/* Print argument type */
- if (arg->type) {
- ret = e_snprintf(buf, buflen, ":%s", arg->type);
- if (ret <= 0)
- return ret;
- buf += ret;
- }
+ if (arg->type)
+ strbuf_addf(buf, ":%s", arg->type);
- return buf - tmp;
+ return 0;
}
char *synthesize_probe_trace_command(struct probe_trace_event *tev)
{
struct probe_trace_point *tp = &tev->point;
- char *buf;
- int i, len, ret;
-
- buf = zalloc(MAX_CMDLEN);
- if (buf == NULL)
- return NULL;
-
- len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
- tev->group, tev->event);
- if (len <= 0)
- goto error;
+ struct strbuf buf;
+ char *ret = NULL;
+ int i;
/* Uprobes must have tp->address and tp->module */
if (tev->uprobes && (!tp->address || !tp->module))
- goto error;
+ return NULL;
+
+ strbuf_init(&buf, 32);
+ strbuf_addf(&buf, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
+ tev->group, tev->event);
/* Use the tp->address for uprobes */
if (tev->uprobes)
- ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx",
- tp->module, tp->address);
+ strbuf_addf(&buf, "%s:0x%lx", tp->module, tp->address);
else
- ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu",
- tp->module ?: "", tp->module ? ":" : "",
- tp->symbol, tp->offset);
-
- if (ret <= 0)
- goto error;
- len += ret;
+ strbuf_addf(&buf, "%s%s%s+%lu", tp->module ?: "",
+ tp->module ? ":" : "", tp->symbol, tp->offset);
for (i = 0; i < tev->nargs; i++) {
- ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
- MAX_CMDLEN - len);
- if (ret <= 0)
+ if (synthesize_probe_trace_arg(&tev->args[i], &buf) < 0)
goto error;
- len += ret;
}
- return buf;
+ ret = strbuf_detach(&buf, NULL);
error:
- free(buf);
- return NULL;
+ strbuf_release(&buf);
+ return ret;
}
static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
@@ -1883,7 +1812,7 @@ static int convert_to_perf_probe_point(struct probe_trace_point *tp,
static int convert_to_perf_probe_event(struct probe_trace_event *tev,
struct perf_probe_event *pev, bool is_kprobe)
{
- char buf[64] = "";
+ struct strbuf buf = STRBUF_INIT;
int i, ret;
/* Convert event/group name */
@@ -1906,9 +1835,10 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
if (tev->args[i].name)
pev->args[i].name = strdup(tev->args[i].name);
else {
- ret = synthesize_probe_trace_arg(&tev->args[i],
- buf, 64);
- pev->args[i].name = strdup(buf);
+ strbuf_init(&buf, 32);
+ ret = synthesize_probe_trace_arg(&tev->args[i], &buf);
+ pev->args[i].name = strbuf_detach(&buf, NULL);
+ strbuf_release(&buf);
}
if (pev->args[i].name == NULL && ret >= 0)
ret = -ENOMEM;
@@ -2086,37 +2016,37 @@ static int perf_probe_event__sprintf(const char *group, const char *event,
const char *module,
struct strbuf *result)
{
- int i, ret;
- char buf[128];
- char *place;
+ int i;
+ char *buf;
- /* Synthesize only event probe point */
- place = synthesize_perf_probe_point(&pev->point);
- if (!place)
- return -EINVAL;
+ if (asprintf(&buf, "%s:%s", group, event) < 0)
+ return -errno;
+ strbuf_addf(result, " %-20s (on ", buf);
+ free(buf);
- ret = e_snprintf(buf, 128, "%s:%s", group, event);
- if (ret < 0)
- goto out;
+ /* Synthesize only event probe point */
+ buf = synthesize_perf_probe_point(&pev->point);
+ if (!buf)
+ return -ENOMEM;
+ strbuf_addstr(result, buf);
+ free(buf);
- strbuf_addf(result, " %-20s (on %s", buf, place);
if (module)
strbuf_addf(result, " in %s", module);
if (pev->nargs > 0) {
strbuf_addstr(result, " with");
for (i = 0; i < pev->nargs; i++) {
- ret = synthesize_perf_probe_arg(&pev->args[i],
- buf, 128);
- if (ret < 0)
- goto out;
+ buf = synthesize_perf_probe_arg(&pev->args[i]);
+ if (!buf)
+ return -ENOMEM;
strbuf_addf(result, " %s", buf);
+ free(buf);
}
}
strbuf_addch(result, ')');
-out:
- free(place);
- return ret;
+
+ return 0;
}
/* Show an event */
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 20f555d..4cff6be 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -115,8 +115,7 @@ extern int parse_probe_trace_command(const char *cmd,
/* Events to command string */
extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
extern char *synthesize_probe_trace_command(struct probe_trace_event *tev);
-extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf,
- size_t len);
+extern char *synthesize_perf_probe_arg(struct perf_probe_arg *pa);
/* Check the perf_probe_event needs debuginfo */
extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 2da65a7..f7beb3c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -550,7 +550,7 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
{
Dwarf_Die vr_die;
- char buf[32], *ptr;
+ char *buf, *ptr;
int ret = 0;
if (!is_c_varname(pf->pvar->var)) {
@@ -575,13 +575,13 @@ static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
if (pf->pvar->name)
pf->tvar->name = strdup(pf->pvar->name);
else {
- ret = synthesize_perf_probe_arg(pf->pvar, buf, 32);
- if (ret < 0)
- return ret;
+ buf = synthesize_perf_probe_arg(pf->pvar);
+ if (!buf)
+ return -ENOMEM;
ptr = strchr(buf, ':'); /* Change type separator to _ */
if (ptr)
*ptr = '_';
- pf->tvar->name = strdup(buf);
+ pf->tvar->name = buf;
}
if (pf->tvar->name == NULL)
return -ENOMEM;
Use path/to/bin/buildid/elf instead of path/to/bin/buildid
to store corresponding elf binary.
This also stores vdso in buildid/vdso, kallsyms in buildid/kallsyms.
Note that the build-id based symlink changes to point to the
path/to/bin/buildid, not path/to/bin/buildid/elf.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/build-id.c | 61 ++++++++++++++++++++++++++++++++------------
tools/perf/util/dso.h | 5 ++++
tools/perf/util/symbol.c | 2 +
3 files changed, 50 insertions(+), 18 deletions(-)
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 1f6fc23..204d23d 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -112,7 +112,8 @@ static int asnprintf(char **strp, size_t size, const char *fmt, ...)
return ret;
}
-static char *build_id__filename(const char *sbuild_id, char *bf, size_t size)
+static char *build_id_cache__linkname(const char *sbuild_id, char *bf,
+ size_t size)
{
char *tmp = bf;
int ret = asnprintf(&bf, size, "%s/.build-id/%.2s/%s", buildid_dir,
@@ -122,15 +123,35 @@ static char *build_id__filename(const char *sbuild_id, char *bf, size_t size)
return bf;
}
+static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso)
+{
+ return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : "elf");
+}
+
char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size)
{
+ bool is_kallsyms = dso__is_kallsyms((struct dso *)dso);
+ bool is_vdso = dso__is_vdso((struct dso *)dso);
char build_id_hex[BUILD_ID_SIZE * 2 + 1];
+ char *linkname;
+ bool alloc = (bf == NULL);
+ int ret;
if (!dso->has_build_id)
return NULL;
build_id__sprintf(dso->build_id, sizeof(dso->build_id), build_id_hex);
- return build_id__filename(build_id_hex, bf, size);
+ linkname = build_id_cache__linkname(build_id_hex, NULL, 0);
+ if (!linkname)
+ return NULL;
+
+ ret = asnprintf(&bf, size, "%s/%s", linkname,
+ build_id_cache__basename(is_kallsyms, is_vdso));
+ if (ret < 0 || (!alloc && size < (unsigned int)ret))
+ bf = NULL;
+ free(linkname);
+
+ return bf;
}
#define dsos__for_each_with_build_id(pos, head) \
@@ -261,7 +282,8 @@ void disable_buildid_cache(void)
}
static char *build_id_cache__dirname_from_path(const char *name,
- bool is_kallsyms, bool is_vdso)
+ bool is_kallsyms, bool is_vdso,
+ const char *sbuild_id)
{
char *realname = (char *)name, *filename;
bool slash = is_kallsyms || is_vdso;
@@ -272,8 +294,9 @@ static char *build_id_cache__dirname_from_path(const char *name,
return NULL;
}
- if (asprintf(&filename, "%s%s%s", buildid_dir, slash ? "/" : "",
- is_vdso ? DSO__NAME_VDSO : realname) < 0)
+ if (asprintf(&filename, "%s%s%s%s%s", buildid_dir, slash ? "/" : "",
+ is_vdso ? DSO__NAME_VDSO : realname,
+ sbuild_id ? "/" : "", sbuild_id ?: "") < 0)
filename = NULL;
if (!slash)
@@ -292,7 +315,8 @@ int build_id_cache__list_build_ids(const char *pathname,
int ret = 0;
list = strlist__new(true, NULL);
- dir_name = build_id_cache__dirname_from_path(pathname, false, false);
+ dir_name = build_id_cache__dirname_from_path(pathname, false, false,
+ NULL);
if (!list || !dir_name) {
ret = -ENOMEM;
goto out;
@@ -327,7 +351,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
{
const size_t size = PATH_MAX;
char *realname = NULL, *filename = NULL, *dir_name = NULL,
- *linkname = zalloc(size), *targetname, *tmp;
+ *linkname = zalloc(size), *tmp;
int err = -1;
if (!is_kallsyms) {
@@ -336,14 +360,17 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
goto out_free;
}
- dir_name = build_id_cache__dirname_from_path(name, is_kallsyms, is_vdso);
+ dir_name = build_id_cache__dirname_from_path(name, is_kallsyms,
+ is_vdso, sbuild_id);
if (!dir_name)
goto out_free;
if (mkdir_p(dir_name, 0755))
goto out_free;
- if (asprintf(&filename, "%s/%s", dir_name, sbuild_id) < 0) {
+ /* Save the allocated buildid dirname */
+ if (asprintf(&filename, "%s/%s", dir_name,
+ build_id_cache__basename(is_kallsyms, is_vdso)) < 0) {
filename = NULL;
goto out_free;
}
@@ -357,7 +384,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
goto out_free;
}
- if (!build_id__filename(sbuild_id, linkname, size))
+ if (!build_id_cache__linkname(sbuild_id, linkname, size))
goto out_free;
tmp = strrchr(linkname, '/');
*tmp = '\0';
@@ -366,10 +393,10 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
goto out_free;
*tmp = '/';
- targetname = filename + strlen(buildid_dir) - 5;
- memcpy(targetname, "../..", 5);
+ tmp = dir_name + strlen(buildid_dir) - 5;
+ memcpy(tmp, "../..", 5);
- if (symlink(targetname, linkname) == 0)
+ if (symlink(tmp, linkname) == 0)
err = 0;
out_free:
if (!is_kallsyms)
@@ -394,7 +421,7 @@ static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
bool build_id_cache__cached(const char *sbuild_id)
{
bool ret = false;
- char *filename = build_id__filename(sbuild_id, NULL, 0);
+ char *filename = build_id_cache__linkname(sbuild_id, NULL, 0);
if (filename && !access(filename, F_OK))
ret = true;
@@ -413,7 +440,7 @@ int build_id_cache__remove_s(const char *sbuild_id)
if (filename == NULL || linkname == NULL)
goto out_free;
- if (!build_id__filename(sbuild_id, linkname, size))
+ if (!build_id_cache__linkname(sbuild_id, linkname, size))
goto out_free;
if (access(linkname, F_OK))
@@ -431,7 +458,7 @@ int build_id_cache__remove_s(const char *sbuild_id)
tmp = strrchr(linkname, '/') + 1;
snprintf(tmp, size - (tmp - linkname), "%s", filename);
- if (unlink(linkname))
+ if (rm_rf(linkname))
goto out_free;
err = 0;
@@ -443,7 +470,7 @@ out_free:
static int dso__cache_build_id(struct dso *dso, struct machine *machine)
{
- bool is_kallsyms = dso->kernel && dso->long_name[0] != '/';
+ bool is_kallsyms = dso__is_kallsyms(dso);
bool is_vdso = dso__is_vdso(dso);
const char *name = dso->long_name;
char nm[PATH_MAX];
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 2fe98bb..2b83e36 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -341,6 +341,11 @@ static inline bool dso__is_kcore(struct dso *dso)
dso->binary_type == DSO_BINARY_TYPE__GUEST_KCORE;
}
+static inline bool dso__is_kallsyms(struct dso *dso)
+{
+ return dso->kernel && dso->long_name[0] != '/';
+}
+
void dso__free_a2l(struct dso *dso);
enum dso_type dso__type(struct dso *dso, struct machine *machine);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 48b588c..72db742 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1702,7 +1702,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
if (!find_matching_kcore(map, path, sizeof(path)))
return strdup(path);
- scnprintf(path, sizeof(path), "%s/[kernel.kallsyms]/%s",
+ scnprintf(path, sizeof(path), "%s/[kernel.kallsyms]/%s/kallsyms",
buildid_dir, sbuild_id);
if (access(path, F_OK)) {
Introduce SBUILD_ID_SIZE macro and use it instead of using
BUILD_ID_SIZE * 2 + 1.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/builtin-buildid-cache.c | 8 ++++----
tools/perf/builtin-buildid-list.c | 4 ++--
tools/perf/util/build-id.c | 4 ++--
tools/perf/util/build-id.h | 3 ++-
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index d47a0cd..9845c2d 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -127,7 +127,7 @@ static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
static int build_id_cache__add_kcore(const char *filename, bool force)
{
- char dir[32], sbuildid[BUILD_ID_SIZE * 2 + 1];
+ char dir[32], sbuildid[SBUILD_ID_SIZE];
char from_dir[PATH_MAX], to_dir[PATH_MAX];
char *p;
@@ -184,7 +184,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
static int build_id_cache__add_file(const char *filename)
{
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
u8 build_id[BUILD_ID_SIZE];
int err;
@@ -204,7 +204,7 @@ static int build_id_cache__add_file(const char *filename)
static int build_id_cache__remove_file(const char *filename)
{
u8 build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
int err;
@@ -276,7 +276,7 @@ static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *f
static int build_id_cache__update_file(const char *filename)
{
u8 build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
int err = 0;
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 9fe93c8..b5ca988 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -20,7 +20,7 @@
static int sysfs__fprintf_build_id(FILE *fp)
{
u8 kallsyms_build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
sizeof(kallsyms_build_id)) != 0)
@@ -35,7 +35,7 @@ static int sysfs__fprintf_build_id(FILE *fp)
static int filename__fprintf_build_id(const char *name, FILE *fp)
{
u8 build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
if (filename__read_build_id(name, build_id,
sizeof(build_id)) != sizeof(build_id))
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 204d23d..1edb7c7 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -132,7 +132,7 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size)
{
bool is_kallsyms = dso__is_kallsyms((struct dso *)dso);
bool is_vdso = dso__is_vdso((struct dso *)dso);
- char build_id_hex[BUILD_ID_SIZE * 2 + 1];
+ char build_id_hex[SBUILD_ID_SIZE];
char *linkname;
bool alloc = (bf == NULL);
int ret;
@@ -411,7 +411,7 @@ static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
const char *name, bool is_kallsyms,
bool is_vdso)
{
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
build_id__sprintf(build_id, build_id_size, sbuild_id);
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 8501122..ce2f493 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -1,7 +1,8 @@
#ifndef PERF_BUILD_ID_H_
#define PERF_BUILD_ID_H_ 1
-#define BUILD_ID_SIZE 20
+#define BUILD_ID_SIZE 20
+#define SBUILD_ID_SIZE (BUILD_ID_SIZE * 2 + 1)
#include "tool.h"
#include "strlist.h"
Introduce sysfs/filename__sprintf_build_id for consolidating
similar code.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/builtin-buildid-cache.c | 14 ++------------
tools/perf/builtin-buildid-list.c | 24 ++++++++++--------------
tools/perf/util/build-id.c | 32 ++++++++++++++++++++++++++++++++
tools/perf/util/build-id.h | 3 +++
4 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 9845c2d..cd1196b 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -25,8 +25,6 @@
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
{
char root_dir[PATH_MAX];
- char notes[PATH_MAX];
- u8 build_id[BUILD_ID_SIZE];
char *p;
strlcpy(root_dir, proc_dir, sizeof(root_dir));
@@ -35,15 +33,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
if (!p)
return -1;
*p = '\0';
-
- scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
-
- if (sysfs__read_build_id(notes, build_id, sizeof(build_id)))
- return -1;
-
- build_id__sprintf(build_id, sizeof(build_id), sbuildid);
-
- return 0;
+ return sysfs__sprintf_build_id(root_dir, sbuildid);
}
static int build_id_cache__kcore_dir(char *dir, size_t sz)
@@ -138,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
return -1;
*p = '\0';
- if (build_id_cache__kcore_buildid(from_dir, sbuildid))
+ if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0)
return -1;
scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s",
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index b5ca988..918b4de 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -19,29 +19,25 @@
static int sysfs__fprintf_build_id(FILE *fp)
{
- u8 kallsyms_build_id[BUILD_ID_SIZE];
char sbuild_id[SBUILD_ID_SIZE];
+ int ret;
- if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
- sizeof(kallsyms_build_id)) != 0)
- return -1;
+ ret = sysfs__sprintf_build_id("/", sbuild_id);
+ if (ret != sizeof(sbuild_id))
+ return ret < 0 ? ret : -EINVAL;
- build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id),
- sbuild_id);
- fprintf(fp, "%s\n", sbuild_id);
- return 0;
+ return fprintf(fp, "%s\n", sbuild_id);
}
static int filename__fprintf_build_id(const char *name, FILE *fp)
{
- u8 build_id[BUILD_ID_SIZE];
char sbuild_id[SBUILD_ID_SIZE];
+ int ret;
- if (filename__read_build_id(name, build_id,
- sizeof(build_id)) != sizeof(build_id))
- return 0;
+ ret = filename__sprintf_build_id(name, sbuild_id);
+ if (ret != sizeof(sbuild_id))
+ return ret < 0 ? ret : -EINVAL;
- build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
return fprintf(fp, "%s\n", sbuild_id);
}
@@ -63,7 +59,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
/*
* See if this is an ELF file first:
*/
- if (filename__fprintf_build_id(input_name, stdout))
+ if (filename__fprintf_build_id(input_name, stdout) > 0)
goto out;
session = perf_session__new(&file, false, &build_id__mark_dso_hit_ops);
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 1edb7c7..8c40133 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -93,6 +93,38 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
return raw - build_id;
}
+int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
+{
+ char notes[PATH_MAX];
+ u8 build_id[BUILD_ID_SIZE];
+ int ret;
+
+ if (!root_dir)
+ root_dir = "";
+
+ scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
+
+ ret = sysfs__read_build_id(notes, build_id, sizeof(build_id));
+ if (ret < 0)
+ return ret;
+
+ return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+}
+
+int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
+{
+ u8 build_id[BUILD_ID_SIZE];
+ int ret;
+
+ ret = filename__read_build_id(pathname, build_id, sizeof(build_id));
+ if (ret < 0)
+ return ret;
+ else if (ret != sizeof(build_id))
+ return -EINVAL;
+
+ return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+}
+
/* asnprintf consolidates asprintf and snprintf */
static int asnprintf(char **strp, size_t size, const char *fmt, ...)
{
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index ce2f493..27a14a8 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -12,6 +12,9 @@ extern struct perf_tool build_id__mark_dso_hit_ops;
struct dso;
int build_id__sprintf(const u8 *build_id, int len, char *bf);
+int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id);
+int filename__sprintf_build_id(const char *pathname, char *sbuild_id);
+
char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
As a utility function, add lsdir() which reads given
directory and store entry name into a strlist.
lsdir accepts a filter function so that user can
filter out unneeded entries.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/util.c | 34 ++++++++++++++++++++++++++++++++++
tools/perf/util/util.h | 4 ++++
2 files changed, 38 insertions(+)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index edc2d63..69694dd 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -115,6 +115,40 @@ int rm_rf(char *path)
return rmdir(path);
}
+/* A filter which removes dot files */
+bool lsdir_no_dot_filter(const char *dirname __maybe_unused, struct dirent *d)
+{
+ return d->d_name[0] != '.';
+}
+
+/* lsdir reads a directory and store it in strlist */
+struct strlist *lsdir(const char *dirname,
+ bool (*filter)(const char *, struct dirent *))
+{
+ struct strlist *list = NULL;
+ DIR *dir;
+ struct dirent *d;
+
+ dir = opendir(dirname);
+ if (!dir)
+ return NULL;
+
+ list = strlist__new(true, NULL);
+ if (!list) {
+ errno = -ENOMEM;
+ goto out;
+ }
+
+ while ((d = readdir(dir)) != NULL) {
+ if (!filter || filter(dirname, d))
+ strlist__add(list, d->d_name);
+ }
+
+out:
+ closedir(dir);
+ return list;
+}
+
static int slow_copyfile(const char *from, const char *to)
{
int err = -1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 20d625a..fb5401b 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -79,6 +79,7 @@
#include <termios.h>
#include <linux/bitops.h>
#include <termios.h>
+#include "strlist.h"
extern const char *graph_line;
extern const char *graph_dotted_line;
@@ -250,6 +251,9 @@ static inline int sane_case(int x, int high)
int mkdir_p(char *path, mode_t mode);
int rm_rf(char *path);
+struct strlist *lsdir(const char *dirname,
+ bool (*filter)(const char *, struct dirent *));
+bool lsdir_no_dot_filter(const char *dirname __maybe_unused, struct dirent *d);
int copyfile(const char *from, const char *to);
int copyfile_mode(const char *from, const char *to, mode_t mode);
int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
Use new lsdir() for looking up buildid caches. This changes
logic a bit to ignore all dot files, since the build-id
cache must not start with dot.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/build-id.c | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 8c40133..02a5e0d 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -342,38 +342,18 @@ int build_id_cache__list_build_ids(const char *pathname,
{
struct strlist *list;
char *dir_name;
- DIR *dir;
- struct dirent *d;
int ret = 0;
- list = strlist__new(true, NULL);
dir_name = build_id_cache__dirname_from_path(pathname, false, false,
NULL);
- if (!list || !dir_name) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!dir_name)
+ return -ENOMEM;
- /* List up all dirents */
- dir = opendir(dir_name);
- if (!dir) {
+ list = lsdir(dir_name, lsdir_no_dot_filter);
+ if (!list)
ret = -errno;
- goto out;
- }
-
- while ((d = readdir(dir)) != NULL) {
- if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
- continue;
- strlist__add(list, d->d_name);
- }
- closedir(dir);
-
-out:
+ *result = list;
free(dir_name);
- if (ret)
- strlist__delete(list);
- else
- *result = list;
return ret;
}
Add --cache option to cache the probe definitions. This
just saves the result of the dwarf analysis to probe cache.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v2:
- Update documentations/perf-probe.txt.
---
tools/perf/Documentation/perf-probe.txt | 4
tools/perf/builtin-probe.c | 1
tools/perf/util/build-id.c | 13 +
tools/perf/util/build-id.h | 2
tools/perf/util/probe-event.c | 136 ++++++++++++--
tools/perf/util/probe-event.h | 5 +
tools/perf/util/probe-file.c | 298 +++++++++++++++++++++++++++++++
tools/perf/util/probe-file.h | 20 ++
8 files changed, 447 insertions(+), 32 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 3a8a9ba..947db6f 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -109,6 +109,10 @@ OPTIONS
Dry run. With this option, --add and --del doesn't execute actual
adding and removal operations.
+--cache::
+ Cache the probes (with --add option). Any events which successfully added
+ are also stored in the cache file.
+
--max-probes=NUM::
Set the maximum number of probe points for an event. Default is 128.
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index b81cec3..5ac8a79 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -396,6 +396,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
opt_set_filter),
OPT_CALLBACK('x', "exec", NULL, "executable|path",
"target executable name or path", opt_set_target),
+ OPT_BOOLEAN(0, "cache", &probe_conf.cache, "Manipulate probe cache"),
OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
"Enable symbol demangling"),
OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 02a5e0d..169639e 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -313,9 +313,8 @@ void disable_buildid_cache(void)
no_buildid_cache = true;
}
-static char *build_id_cache__dirname_from_path(const char *name,
- bool is_kallsyms, bool is_vdso,
- const char *sbuild_id)
+char *build_id_cache__dirname_from_path(const char *sbuild_id, const char *name,
+ bool is_kallsyms, bool is_vdso)
{
char *realname = (char *)name, *filename;
bool slash = is_kallsyms || is_vdso;
@@ -344,8 +343,8 @@ int build_id_cache__list_build_ids(const char *pathname,
char *dir_name;
int ret = 0;
- dir_name = build_id_cache__dirname_from_path(pathname, false, false,
- NULL);
+ dir_name = build_id_cache__dirname_from_path(NULL, pathname,
+ false, false);
if (!dir_name)
return -ENOMEM;
@@ -372,8 +371,8 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
goto out_free;
}
- dir_name = build_id_cache__dirname_from_path(name, is_kallsyms,
- is_vdso, sbuild_id);
+ dir_name = build_id_cache__dirname_from_path(sbuild_id, name,
+ is_kallsyms, is_vdso);
if (!dir_name)
goto out_free;
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 27a14a8..a1f428d 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -27,6 +27,8 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits);
int perf_session__write_buildid_table(struct perf_session *session, int fd);
int perf_session__cache_build_ids(struct perf_session *session);
+char *build_id_cache__dirname_from_path(const char *sbuild_id, const char *name,
+ bool is_kallsyms, bool is_vdso);
int build_id_cache__list_build_ids(const char *pathname,
struct strlist **result);
bool build_id_cache__cached(const char *sbuild_id);
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index b6ed15e..fc30c2d 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -68,7 +68,6 @@ int e_snprintf(char *str, size_t size, const char *format, ...)
return ret;
}
-static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
static struct machine *host_machine;
/* Initialize symbol maps and path of vmlinux/modules */
@@ -1593,7 +1592,7 @@ char *synthesize_perf_probe_arg(struct perf_probe_arg *pa)
}
/* Compose only probe point (not argument) */
-static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
+char *synthesize_perf_probe_point(struct perf_probe_point *pp)
{
struct strbuf buf;
char *tmp;
@@ -1626,30 +1625,36 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
return tmp;
}
-#if 0
char *synthesize_perf_probe_command(struct perf_probe_event *pev)
{
- char *buf;
- int i, len, ret;
+ struct strbuf buf;
+ char *tmp;
+ int i;
- buf = synthesize_perf_probe_point(&pev->point);
- if (!buf)
- return NULL;
+ strbuf_init(&buf, 64);
+ if (pev->event)
+ strbuf_addf(&buf, "%s:%s=", pev->group ?: PERFPROBE_GROUP,
+ pev->event);
+
+ tmp = synthesize_perf_probe_point(&pev->point);
+ if (!tmp)
+ goto out;
+ strbuf_addstr(&buf, tmp);
+ free(tmp);
- len = strlen(buf);
for (i = 0; i < pev->nargs; i++) {
- ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
- pev->args[i].name);
- if (ret <= 0) {
- free(buf);
- return NULL;
- }
- len += ret;
+ tmp = synthesize_perf_probe_arg(pev->args + i);
+ if (!tmp)
+ goto out;
+ strbuf_addf(&buf, " %s", tmp);
+ free(tmp);
}
- return buf;
+ tmp = strbuf_detach(&buf, NULL);
+out:
+ strbuf_release(&buf);
+ return tmp;
}
-#endif
static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref,
struct strbuf *buf, int depth)
@@ -1730,7 +1735,6 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev)
if (synthesize_probe_trace_arg(&tev->args[i], &buf) < 0)
goto error;
}
-
ret = strbuf_detach(&buf, NULL);
error:
strbuf_release(&buf);
@@ -1876,6 +1880,79 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
memset(pev, 0, sizeof(*pev));
}
+#define strdup_or_goto(str, label) \
+({ char *__p = NULL; if (str && !(__p = strdup(str))) goto label; __p; })
+
+static int perf_probe_point__copy(struct perf_probe_point *dst,
+ struct perf_probe_point *src)
+{
+ dst->file = strdup_or_goto(src->file, out_err);
+ dst->function = strdup_or_goto(src->function, out_err);
+ dst->lazy_line = strdup_or_goto(src->lazy_line, out_err);
+ dst->line = src->line;
+ dst->retprobe = src->retprobe;
+ dst->offset = src->offset;
+ return 0;
+
+out_err:
+ clear_perf_probe_point(dst);
+ return -ENOMEM;
+}
+
+static int perf_probe_arg__copy(struct perf_probe_arg *dst,
+ struct perf_probe_arg *src)
+{
+ struct perf_probe_arg_field *field, **ppfield;
+
+ dst->name = strdup_or_goto(src->name, out_err);
+ dst->var = strdup_or_goto(src->var, out_err);
+ dst->type = strdup_or_goto(src->type, out_err);
+
+ field = src->field;
+ ppfield = &(dst->field);
+ while (field) {
+ *ppfield = zalloc(sizeof(*field));
+ if (!*ppfield)
+ goto out_err;
+ (*ppfield)->name = strdup_or_goto(field->name, out_err);
+ (*ppfield)->index = field->index;
+ (*ppfield)->ref = field->ref;
+ field = field->next;
+ ppfield = &((*ppfield)->next);
+ }
+ return 0;
+out_err:
+ return -ENOMEM;
+}
+
+int perf_probe_event__copy(struct perf_probe_event *dst,
+ struct perf_probe_event *src)
+{
+ int i;
+
+ dst->event = strdup_or_goto(src->event, out_err);
+ dst->group = strdup_or_goto(src->group, out_err);
+ dst->target = strdup_or_goto(src->target, out_err);
+ dst->uprobes = src->uprobes;
+
+ if (perf_probe_point__copy(&dst->point, &src->point) < 0)
+ goto out_err;
+
+ dst->args = zalloc(sizeof(struct perf_probe_arg) * src->nargs);
+ if (!dst->args)
+ goto out_err;
+ dst->nargs = src->nargs;
+
+ for (i = 0; i < src->nargs; i++)
+ if (perf_probe_arg__copy(&dst->args[i], &src->args[i]) < 0)
+ goto out_err;
+ return 0;
+
+out_err:
+ clear_perf_probe_event(dst);
+ return -ENOMEM;
+}
+
void clear_probe_trace_event(struct probe_trace_event *tev)
{
struct probe_trace_arg_ref *ref, *next;
@@ -2262,15 +2339,17 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
}
static int __add_probe_trace_events(struct perf_probe_event *pev,
- struct probe_trace_event *tevs,
- int ntevs, bool allow_suffix)
+ struct probe_trace_event *tevs,
+ int ntevs, bool allow_suffix)
{
int i, fd, ret;
struct probe_trace_event *tev = NULL;
const char *event = NULL, *group = NULL;
+ struct probe_cache *cache = NULL;
struct strlist *namelist;
+ int flag = PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0);
- fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));
+ fd = probe_file__open(flag);
if (fd < 0)
return fd;
@@ -2320,6 +2399,16 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
/* Note that it is possible to skip all events because of blacklist */
if (ret >= 0 && event) {
+ if (probe_conf.cache) {
+ cache = probe_cache__new(pev->target);
+ if (!cache)
+ pr_info("Warning: Failed to add cache\n");
+ else {
+ probe_cache__add_entry(cache, pev, tevs, ntevs);
+ probe_cache__commit(cache);
+ probe_cache__delete(cache);
+ }
+ }
/* Show how to use the event. */
pr_info("\nYou can now use it in all perf tools, such as:\n\n");
pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
@@ -2352,9 +2441,6 @@ static int find_probe_functions(struct map *map, char *name,
return found;
}
-#define strdup_or_goto(str, label) \
- ({ char *__p = strdup(str); if (!__p) goto label; __p; })
-
void __weak arch__fix_tev_from_maps(struct perf_probe_event *pev __maybe_unused,
struct probe_trace_event *tev __maybe_unused,
struct map *map __maybe_unused) { }
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 4cff6be..9aceba3 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -12,6 +12,7 @@ struct probe_conf {
bool show_location_range;
bool force_add;
bool no_inlines;
+ bool cache;
int max_probes;
};
extern struct probe_conf probe_conf;
@@ -116,6 +117,10 @@ extern int parse_probe_trace_command(const char *cmd,
extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
extern char *synthesize_probe_trace_command(struct probe_trace_event *tev);
extern char *synthesize_perf_probe_arg(struct perf_probe_arg *pa);
+char *synthesize_perf_probe_point(struct perf_probe_point *pp);
+
+int perf_probe_event__copy(struct perf_probe_event *dst,
+ struct perf_probe_event *src);
/* Check the perf_probe_event needs debuginfo */
extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 2a7cc8c..572e8c2 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -14,6 +14,7 @@
* GNU General Public License for more details.
*
*/
+#include <sys/uio.h>
#include "util.h"
#include "event.h"
#include "strlist.h"
@@ -300,3 +301,300 @@ int probe_file__del_events(int fd, struct strfilter *filter)
return ret;
}
+static void probe_cache_entry__delete(struct probe_cache_entry *node)
+{
+ if (!list_empty(&node->list))
+ list_del(&node->list);
+ if (node->tevlist)
+ strlist__delete(node->tevlist);
+ clear_perf_probe_event(&node->pev);
+ free(node->spev);
+ free(node);
+}
+
+static struct probe_cache_entry *
+probe_cache_entry__new(struct perf_probe_event *pev)
+{
+ struct probe_cache_entry *ret = zalloc(sizeof(*ret));
+
+ if (ret) {
+ INIT_LIST_HEAD(&ret->list);
+ ret->tevlist = strlist__new(true, NULL);
+ if (!ret->tevlist)
+ zfree(&ret);
+ if (ret && pev) {
+ ret->spev = synthesize_perf_probe_command(pev);
+ if (!ret->spev ||
+ perf_probe_event__copy(&ret->pev, pev) < 0) {
+ probe_cache_entry__delete(ret);
+ return NULL;
+ }
+ }
+ }
+
+ return ret;
+}
+
+/* For the kernel probe caches, pass target = NULL */
+static int probe_cache__open(struct probe_cache *pcache, const char *target)
+{
+ char cpath[PATH_MAX];
+ char sbuildid[SBUILD_ID_SIZE];
+ char *dir_name;
+ bool is_kallsyms = !target;
+ int ret, fd;
+
+ if (target)
+ ret = filename__sprintf_build_id(target, sbuildid);
+ else {
+ target = "[kernel.kallsyms]";
+ ret = sysfs__sprintf_build_id("/", sbuildid);
+ }
+ if (ret < 0) {
+ pr_warning("Failed to get build-id from %s.\n", target ?: "kernel");
+ return ret;
+ }
+
+ /* If we have no buildid cache, make it */
+ if (!build_id_cache__cached(sbuildid)) {
+ ret = build_id_cache__add_s(sbuildid, target,
+ is_kallsyms, NULL);
+ if (ret < 0) {
+ pr_warning("Failed to add cache: %s\n", target);
+ return ret;
+ }
+ }
+
+ dir_name = build_id_cache__dirname_from_path(sbuildid, target,
+ is_kallsyms, false);
+ if (!dir_name)
+ return -ENOMEM;
+
+ snprintf(cpath, PATH_MAX, "%s/probes", dir_name);
+ fd = open(cpath, O_CREAT | O_RDWR | O_APPEND, 0644);
+ if (fd < 0)
+ pr_warning("Failed to open cache(%d): %s\n", fd, cpath);
+ free(dir_name);
+ pcache->fd = fd;
+
+ return fd;
+}
+
+static int probe_cache__load(struct probe_cache *pcache)
+{
+ struct probe_cache_entry *entry = NULL;
+ char buf[MAX_CMDLEN], *p;
+ int ret = 0;
+ FILE *fp;
+
+ fp = fdopen(dup(pcache->fd), "r");
+ while (!feof(fp)) {
+ if (!fgets(buf, MAX_CMDLEN, fp))
+ break;
+ p = strchr(buf, '\n');
+ if (p)
+ *p = '\0';
+ if (buf[0] == '#') { /* #perf_probe_event */
+ entry = probe_cache_entry__new(NULL);
+ entry->spev = strdup(buf + 1);
+ ret = parse_perf_probe_command(buf + 1, &entry->pev);
+ if (!entry->spev || ret < 0) {
+ probe_cache_entry__delete(entry);
+ goto out;
+ }
+ list_add_tail(&entry->list, &pcache->list);
+ } else { /* trace_probe_event */
+ if (!entry) {
+ ret = -EINVAL;
+ goto out;
+ }
+ strlist__add(entry->tevlist, buf);
+ }
+ }
+out:
+ fclose(fp);
+ return ret;
+}
+
+static struct probe_cache *probe_cache__alloc(void)
+{
+ struct probe_cache *ret = zalloc(sizeof(*ret));
+
+ if (ret) {
+ INIT_LIST_HEAD(&ret->list);
+ ret->fd = -EINVAL;
+ }
+ return ret;
+}
+
+void probe_cache__delete(struct probe_cache *pcache)
+{
+ struct probe_cache_entry *entry;
+
+ if (!pcache)
+ return;
+
+ while (!list_empty(&pcache->list)) {
+ entry = list_first_entry(&pcache->list, typeof(*entry), list);
+ probe_cache_entry__delete(entry);
+ }
+ if (pcache->fd > 0)
+ close(pcache->fd);
+ free(pcache);
+}
+
+struct probe_cache *probe_cache__new(const char *target)
+{
+ struct probe_cache *pcache = probe_cache__alloc();
+ int ret;
+
+ if (!pcache)
+ return NULL;
+
+ ret = probe_cache__open(pcache, target);
+ if (ret < 0) {
+ pr_debug("Cache open error: %d\n", ret);
+ goto out_err;
+ }
+
+ ret = probe_cache__load(pcache);
+ if (ret < 0) {
+ pr_debug("Cache read error: %d\n", ret);
+ goto out_err;
+ }
+
+ return pcache;
+
+out_err:
+ probe_cache__delete(pcache);
+ return NULL;
+}
+
+static bool streql(const char *a, const char *b)
+{
+ if (a == b)
+ return true;
+
+ if (!a || !b)
+ return false;
+
+ return !strcmp(a, b);
+}
+
+static struct probe_cache_entry *
+probe_cache__find(struct probe_cache *pcache, struct perf_probe_event *pev)
+{
+ struct probe_cache_entry *entry = NULL;
+ char *cmd = NULL;
+
+ cmd = synthesize_perf_probe_command(pev);
+ if (!cmd)
+ return NULL;
+
+ list_for_each_entry(entry, &pcache->list, list) {
+ /* Hit if same event name or same command-string */
+ if ((pev->event &&
+ (streql(entry->pev.group, pev->group) &&
+ streql(entry->pev.event, pev->event))) ||
+ (!strcmp(entry->spev, cmd)))
+ goto found;
+ }
+ entry = NULL;
+
+found:
+ free(cmd);
+ return entry;
+}
+
+int probe_cache__add_entry(struct probe_cache *pcache,
+ struct perf_probe_event *pev,
+ struct probe_trace_event *tevs, int ntevs)
+{
+ struct probe_cache_entry *entry = NULL;
+ char *command;
+ int i, ret = 0;
+
+ if (!pcache || !pev || !tevs || ntevs <= 0) {
+ ret = -EINVAL;
+ goto out_err;
+ }
+
+ /* Remove old cache entry */
+ entry = probe_cache__find(pcache, pev);
+ if (entry)
+ probe_cache_entry__delete(entry);
+
+ ret = -ENOMEM;
+ entry = probe_cache_entry__new(pev);
+ if (!entry)
+ goto out_err;
+
+ for (i = 0; i < ntevs; i++) {
+ if (!tevs[i].point.symbol)
+ continue;
+
+ command = synthesize_probe_trace_command(&tevs[i]);
+ if (!command)
+ goto out_err;
+ strlist__add(entry->tevlist, command);
+ free(command);
+ }
+ list_add_tail(&entry->list, &pcache->list);
+ pr_debug("Added probe cache: %d\n", ntevs);
+ return 0;
+
+out_err:
+ pr_debug("Failed to add probe caches\n");
+ if (entry)
+ probe_cache_entry__delete(entry);
+ return ret;
+}
+
+static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
+{
+ struct str_node *snode;
+ struct iovec iov[3];
+ int ret;
+
+ pr_debug("Writing cache: #%s\n", entry->spev);
+ iov[0].iov_base = (void *)"#"; iov[0].iov_len = 1;
+ iov[1].iov_base = entry->spev; iov[1].iov_len = strlen(entry->spev);
+ iov[2].iov_base = (void *)"\n"; iov[2].iov_len = 1;
+ ret = writev(fd, iov, 3);
+ if (ret < 0)
+ return ret;
+
+ strlist__for_each(snode, entry->tevlist) {
+ iov[0].iov_base = (void *)snode->s;
+ iov[0].iov_len = strlen(snode->s);
+ iov[1].iov_base = (void *)"\n"; iov[1].iov_len = 1;
+ ret = writev(fd, iov, 2);
+ if (ret < 0)
+ return ret;
+ }
+ return 0;
+}
+
+int probe_cache__commit(struct probe_cache *pcache)
+{
+ struct probe_cache_entry *entry;
+ int ret = 0;
+
+ /* TBD: if we do not update existing entries, skip it */
+ ret = lseek(pcache->fd, 0, SEEK_SET);
+ if (ret < 0)
+ goto out;
+
+ ret = ftruncate(pcache->fd, 0);
+ if (ret < 0)
+ goto out;
+
+ list_for_each_entry(entry, &pcache->list, list) {
+ ret = probe_cache_entry__write(entry, pcache->fd);
+ pr_debug("Cache committed: %d\n", ret);
+ if (ret < 0)
+ break;
+ }
+out:
+ return ret;
+}
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index ada94a2..7b473b39 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -15,4 +15,24 @@ struct strlist *probe_file__get_rawlist(int fd);
int probe_file__add_event(int fd, struct probe_trace_event *tev);
int probe_file__del_events(int fd, struct strfilter *filter);
+/* Cache of probe definitions */
+struct probe_cache_entry {
+ struct list_head list;
+ struct perf_probe_event pev;
+ char *spev;
+ struct strlist *tevlist;
+};
+
+struct probe_cache {
+ int fd;
+ struct list_head list;
+};
+
+struct probe_cache *probe_cache__new(const char *target);
+int probe_cache__add_entry(struct probe_cache *pcache,
+ struct perf_probe_event *pev,
+ struct probe_trace_event *tevs, int ntevs);
+int probe_cache__commit(struct probe_cache *pcache);
+void probe_cache__delete(struct probe_cache *pcache);
+
#endif
Before analyzing debuginfo, try to find a corresponding entry
from probe cache always. This does not depend on --cache,
the --cache enables to store/update cache, but looking up
the cache is always enabled.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v2:
- Reuse tev->event and tev->group as base event name if possible,
since when using the cache entry with wildcard, pev will not
have its name/symbol.
- Do not skip trace events whose tev->point.symbol == NULL if
pev->uprobes is set, since cached uprobe event doesn't know
the original symbols.
- Fix to set tev->uprobes attribute flag from the pev->uprobes.
---
tools/perf/util/probe-event.c | 70 ++++++++++++++++++++++++++++++++++++++++-
tools/perf/util/probe-file.c | 20 +++++++++++-
tools/perf/util/probe-file.h | 5 ++-
3 files changed, 91 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index fc30c2d..c71b16b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2310,13 +2310,18 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
if (pev->event)
event = pev->event;
- else
+ else if (tev->event)
+ event = tev->event;
+ else {
if (pev->point.function && !strisglob(pev->point.function))
event = pev->point.function;
else
event = tev->point.realname;
+ }
if (pev->group)
group = pev->group;
+ else if (tev->group)
+ group = tev->group;
else
group = PERFPROBE_GROUP;
@@ -2366,7 +2371,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
for (i = 0; i < ntevs; i++) {
tev = &tevs[i];
/* Skip if the symbol is out of .text or blacklisted */
- if (!tev->point.symbol)
+ if (!tev->point.symbol && !pev->uprobes)
continue;
/* Set new name for tev (and update namelist) */
@@ -2589,6 +2594,62 @@ err_out:
bool __weak arch__prefers_symtab(void) { return false; }
+static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
+ struct probe_trace_event **tevs)
+{
+ struct probe_cache *cache;
+ struct probe_cache_entry *entry;
+ struct probe_trace_event *tev;
+ struct str_node *node;
+ int ret, i;
+
+ cache = probe_cache__new(pev->target);
+ if (!cache)
+ return 0;
+
+ entry = probe_cache__find(cache, pev);
+
+ if (!entry && !pev->event &&
+ (!pev->point.file && pev->point.function && !pev->point.retprobe &&
+ !pev->point.line && !pev->point.offset && !pev->point.lazy_line)) {
+ entry = probe_cache__find_by_name(cache, pev->group,
+ pev->point.function);
+ }
+ if (!entry) {
+ ret = 0;
+ goto out;
+ }
+
+ ret = strlist__nr_entries(entry->tevlist);
+ if (ret > probe_conf.max_probes) {
+ pr_debug("Too many entries matched in the cache of %s\n",
+ pev->target ? : "kernel");
+ ret = -E2BIG;
+ goto out;
+ }
+
+ *tevs = zalloc(ret * sizeof(*tev));
+ if (!*tevs) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ i = 0;
+ strlist__for_each(node, entry->tevlist) {
+ tev = &(*tevs)[i++];
+ ret = parse_probe_trace_command(node->s, tev);
+ if (ret < 0)
+ goto out;
+ /* Set the uprobes attribute as same as original */
+ tev->uprobes = pev->uprobes;
+ }
+ ret = i;
+
+out:
+ probe_cache__delete(cache);
+ return ret;
+}
+
static int convert_to_probe_trace_events(struct perf_probe_event *pev,
struct probe_trace_event **tevs)
{
@@ -2603,6 +2664,11 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
}
}
+ /* At first, we need to lookup cache entry */
+ ret = find_probe_trace_events_from_cache(pev, tevs);
+ if (ret > 0)
+ return ret; /* Found in probe cache */
+
if (arch__prefers_symtab() && !perf_probe_event_need_dwarf(pev)) {
ret = find_probe_trace_events_from_map(pev, tevs);
if (ret > 0)
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 572e8c2..984f690 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -481,7 +481,7 @@ static bool streql(const char *a, const char *b)
return !strcmp(a, b);
}
-static struct probe_cache_entry *
+struct probe_cache_entry *
probe_cache__find(struct probe_cache *pcache, struct perf_probe_event *pev)
{
struct probe_cache_entry *entry = NULL;
@@ -506,6 +506,24 @@ found:
return entry;
}
+struct probe_cache_entry *
+probe_cache__find_by_name(struct probe_cache *pcache,
+ const char *group, const char *event)
+{
+ struct probe_cache_entry *entry = NULL;
+
+ list_for_each_entry(entry, &pcache->list, list) {
+ /* Hit if same event name or same command-string */
+ if (streql(entry->pev.group, group) &&
+ streql(entry->pev.event, event))
+ goto found;
+ }
+ entry = NULL;
+
+found:
+ return entry;
+}
+
int probe_cache__add_entry(struct probe_cache *pcache,
struct perf_probe_event *pev,
struct probe_trace_event *tevs, int ntevs)
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 7b473b39..833e061 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -34,5 +34,8 @@ int probe_cache__add_entry(struct probe_cache *pcache,
struct probe_trace_event *tevs, int ntevs);
int probe_cache__commit(struct probe_cache *pcache);
void probe_cache__delete(struct probe_cache *pcache);
-
+struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
+ struct perf_probe_event *pev);
+struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
+ const char *group, const char *event);
#endif
perf probe --list shows all cached probes when --cache
is given. Each caches are shown with on which binary that
probed. e.g.
-----
# perf probe --cache vfs_read \$params
# perf probe --cache -x /lib64/libc-2.17.so getaddrinfo \$params
# ./perf probe --cache --list
/[kernel.kallsyms] (1466a0a250b5d0070c6d0f03c5fed30b237970a1):
vfs_read $params
/usr/lib64/libc-2.17.so (c31ffe7942bfd77b2fca8f9bd5709d387a86d3bc):
getaddrinfo $params
-----
Note that $params requires debuginfo.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v2:
- Fix to ignore if build-id list is failed to get with -ENOENT,
since this can happen when ~/.debug is not initialized.
- Do not show binary name if there is no cached entries.
- Update perf-probe.txt too.
---
tools/perf/Documentation/perf-probe.txt | 8 ++-
tools/perf/builtin-probe.c | 2 -
tools/perf/util/build-id.c | 79 ++++++++++++++++++++++++++++++-
tools/perf/util/build-id.h | 3 +
tools/perf/util/probe-event.c | 3 +
tools/perf/util/probe-file.c | 65 +++++++++++++++++++++++++-
tools/perf/util/probe-file.h | 1
7 files changed, 154 insertions(+), 7 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 947db6f..5a70d45 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -67,7 +67,10 @@ OPTIONS
-l::
--list[=[GROUP:]EVENT]::
- List up current probe events. This can also accept filtering patterns of event names.
+ List up current probe events. This can also accept filtering patterns of
+ event names.
+ When this is used with --cache, perf shows all cached probes instead of
+ the live probes.
-L::
--line=::
@@ -110,8 +113,9 @@ OPTIONS
adding and removal operations.
--cache::
- Cache the probes (with --add option). Any events which successfully added
+ (With --add) Cache the probes. Any events which successfully added
are also stored in the cache file.
+ (With --list) Show cached probes.
--max-probes=NUM::
Set the maximum number of probe points for an event. Default is 128.
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 5ac8a79..5d0c246 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -44,7 +44,7 @@
#define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"
#define DEFAULT_FUNC_FILTER "!_*"
-#define DEFAULT_LIST_FILTER "*:*"
+#define DEFAULT_LIST_FILTER "*"
/* Session management structure */
static struct {
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 169639e..63123c1 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -144,8 +144,7 @@ static int asnprintf(char **strp, size_t size, const char *fmt, ...)
return ret;
}
-static char *build_id_cache__linkname(const char *sbuild_id, char *bf,
- size_t size)
+char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size)
{
char *tmp = bf;
int ret = asnprintf(&bf, size, "%s/.build-id/%.2s/%s", buildid_dir,
@@ -155,6 +154,29 @@ static char *build_id_cache__linkname(const char *sbuild_id, char *bf,
return bf;
}
+char *build_id_cache__origname(const char *sbuild_id)
+{
+ char *linkname;
+ char buf[PATH_MAX];
+ char *ret = NULL, *p;
+
+ linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
+ if (!linkname)
+ return NULL;
+
+ if (readlink(linkname, buf, PATH_MAX) < 0)
+ goto out;
+ /* The link should be "../..<origpath>/<sbuild_id>" */
+ p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */
+ if (p) {
+ *p = '\0';
+ ret = strdup(buf + 5); /* Skip "../.." */
+ }
+out:
+ free(linkname);
+ return ret;
+}
+
static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso)
{
return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : "elf");
@@ -313,6 +335,59 @@ void disable_buildid_cache(void)
no_buildid_cache = true;
}
+int build_id_cache__list_all(struct strlist **result)
+{
+ struct strlist *toplist, *list, *bidlist;
+ struct str_node *nd, *nd2;
+ char *topdir, *linkdir;
+ char sbuild_id[SBUILD_ID_SIZE];
+ int ret = 0;
+
+ /* Open the top-level directory */
+ if (asprintf(&topdir, "%s/.build-id/", buildid_dir) < 0)
+ return -errno;
+ toplist = lsdir(topdir, lsdir_no_dot_filter);
+ if (!toplist) {
+ pr_debug("Failed to opendir %s\n", topdir);
+ ret = -errno;
+ goto out;
+ }
+ bidlist = strlist__new(true, NULL);
+ strlist__for_each(nd, toplist) {
+ if (asprintf(&linkdir, "%s/%s", topdir, nd->s) < 0) {
+ ret = -errno;
+ goto out;
+ }
+ /* Open the lower-level directory */
+ list = lsdir(linkdir, lsdir_no_dot_filter);
+ if (!list) {
+ pr_debug("Failed to open %s: %d\n", linkdir, -errno);
+ goto next;
+ }
+ strlist__for_each(nd2, list) {
+ ret = snprintf(sbuild_id, SBUILD_ID_SIZE, "%s%s",
+ nd->s, nd2->s);
+ if (ret != SBUILD_ID_SIZE - 1) {
+ pr_debug("%s/%s is not buildid cache\n",
+ nd->s, nd2->s);
+ continue;
+ }
+ strlist__add(bidlist, sbuild_id);
+ }
+ strlist__delete(list);
+next:
+ free(linkdir);
+ }
+
+ *result = bidlist;
+out:
+ if (toplist)
+ strlist__delete(toplist);
+ free(topdir);
+
+ return ret;
+}
+
char *build_id_cache__dirname_from_path(const char *sbuild_id, const char *name,
bool is_kallsyms, bool is_vdso)
{
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index a1f428d..2d5c61c 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -27,8 +27,11 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits);
int perf_session__write_buildid_table(struct perf_session *session, int fd);
int perf_session__cache_build_ids(struct perf_session *session);
+char *build_id_cache__origname(const char *sbuild_id);
+char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size);
char *build_id_cache__dirname_from_path(const char *sbuild_id, const char *name,
bool is_kallsyms, bool is_vdso);
+int build_id_cache__list_all(struct strlist **result);
int build_id_cache__list_build_ids(const char *pathname,
struct strlist **result);
bool build_id_cache__cached(const char *sbuild_id);
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index c71b16b..23b577b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2210,6 +2210,9 @@ int show_perf_probe_events(struct strfilter *filter)
setup_pager();
+ if (probe_conf.cache)
+ return probe_cache__show_all_caches(filter);
+
ret = init_symbol_maps(false);
if (ret < 0)
return ret;
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 984f690..da69ff7 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -340,10 +340,17 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target)
{
char cpath[PATH_MAX];
char sbuildid[SBUILD_ID_SIZE];
- char *dir_name;
+ char *dir_name = NULL;
bool is_kallsyms = !target;
int ret, fd;
+ if (target && build_id_cache__cached(target)) {
+ /* This is a cached buildid */
+ strncpy(sbuildid, target, SBUILD_ID_SIZE);
+ dir_name = build_id_cache__linkname(sbuildid, NULL, 0);
+ goto found;
+ }
+
if (target)
ret = filename__sprintf_build_id(target, sbuildid);
else {
@@ -367,8 +374,11 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target)
dir_name = build_id_cache__dirname_from_path(sbuildid, target,
is_kallsyms, false);
- if (!dir_name)
+found:
+ if (!dir_name) {
+ pr_debug("Failed to get cache from %s\n", target);
return -ENOMEM;
+ }
snprintf(cpath, PATH_MAX, "%s/probes", dir_name);
fd = open(cpath, O_CREAT | O_RDWR | O_APPEND, 0644);
@@ -616,3 +626,54 @@ int probe_cache__commit(struct probe_cache *pcache)
out:
return ret;
}
+
+static int probe_cache__show_entries(struct probe_cache *pcache,
+ struct strfilter *filter)
+{
+ struct probe_cache_entry *entry;
+ char buf[128], *ptr;
+
+ list_for_each_entry(entry, &pcache->list, list) {
+ if (entry->pev.event) {
+ ptr = buf;
+ snprintf(buf, 128, "%s:%s", entry->pev.group, entry->pev.event);
+ } else
+ ptr = entry->spev;
+ if (strfilter__compare(filter, ptr))
+ printf("%s\n", entry->spev);
+ }
+ return 0;
+}
+
+/* Show all cached probes */
+int probe_cache__show_all_caches(struct strfilter *filter)
+{
+ struct probe_cache *pcache;
+ struct strlist *bidlist;
+ struct str_node *nd;
+ char *buf;
+ int ret;
+
+ buf = strfilter__string(filter);
+ pr_debug("list cache with filter: %s\n", buf);
+ free(buf);
+
+ ret = build_id_cache__list_all(&bidlist);
+ if (ret < 0) {
+ pr_debug("Failed to get buildids: %d\n", ret);
+ return ret == -ENOENT ? 0 : ret;
+ }
+ strlist__for_each(nd, bidlist) {
+ pcache = probe_cache__new(nd->s);
+ if (!pcache)
+ continue;
+ if (!list_empty(&pcache->list)) {
+ buf = build_id_cache__origname(nd->s);
+ printf("%s (%s):\n", buf, nd->s);
+ free(buf);
+ probe_cache__show_entries(pcache, filter);
+ }
+ probe_cache__delete(pcache);
+ }
+ return 0;
+}
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 833e061..26dc4f7 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -38,4 +38,5 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
struct perf_probe_event *pev);
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);
#endif
perf-probe --del removes caches when --cache is given.
Note that the delete pattern is not same as normal events.
If you cached probes with event name, --del "eventname"
works as expected. However, if you skipped it, the cached
probes doesn't have actual event name. In that case
--del "probe-desc" is required (wildcard is acceptable).
For example a cache entry has the probe-desc "vfs_read $params",
you can remove it with --del 'vfs_read*'.
-----
# perf probe --cache --list
/[kernel.kallsyms] (1466a0a250b5d0070c6d0f03c5fed30b237970a1):
vfs_read $params
/usr/lib64/libc-2.17.so (c31ffe7942bfd77b2fca8f9bd5709d387a86d3bc):
getaddrinfo $params
# perf probe --cache --del vfs_read\*
Removed event: probe:vfs_read
# perf probe --cache --list
/[kernel.kallsyms] (1466a0a250b5d0070c6d0f03c5fed30b237970a1):
/usr/lib64/libc-2.17.so (c31ffe7942bfd77b2fca8f9bd5709d387a86d3bc):
getaddrinfo $params
-----
Signed-off-by: Masami Hiramatsu <[email protected]>
---
Changes in v2:
- Update perf-probe.txt
---
tools/perf/Documentation/perf-probe.txt | 1 +
tools/perf/util/probe-event.c | 26 ++++++++++++++++++++++++
tools/perf/util/probe-file.c | 33 +++++++++++++++++++++++--------
tools/perf/util/probe-file.h | 2 ++
4 files changed, 54 insertions(+), 8 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 5a70d45..8d09173 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -116,6 +116,7 @@ OPTIONS
(With --add) Cache the probes. Any events which successfully added
are also stored in the cache file.
(With --list) Show cached probes.
+ (With --del) Remove cached probes.
--max-probes=NUM::
Set the maximum number of probe points for an event. Default is 128.
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 23b577b..262f9d3 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2746,6 +2746,30 @@ end:
return ret;
}
+static int del_perf_probe_caches(struct strfilter *filter)
+{
+ struct probe_cache *cache;
+ struct strlist *bidlist;
+ struct str_node *nd;
+ int ret;
+
+ ret = build_id_cache__list_all(&bidlist);
+ if (ret < 0) {
+ pr_debug("Failed to get buildids: %d\n", ret);
+ return ret;
+ }
+
+ strlist__for_each(nd, bidlist) {
+ cache = probe_cache__new(nd->s);
+ if (!cache)
+ continue;
+ probe_cache__remove_entries(cache, filter);
+ probe_cache__commit(cache);
+ probe_cache__delete(cache);
+ }
+ return 0;
+}
+
int del_perf_probe_events(struct strfilter *filter)
{
int ret, ret2, ufd = -1, kfd = -1;
@@ -2755,6 +2779,8 @@ int del_perf_probe_events(struct strfilter *filter)
return -EINVAL;
pr_debug("Delete filter: \'%s\'\n", str);
+ if (probe_conf.cache)
+ return del_perf_probe_caches(filter);
/* Get current event names */
ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index da69ff7..b3a69a3 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -371,7 +371,6 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target)
return ret;
}
}
-
dir_name = build_id_cache__dirname_from_path(sbuildid, target,
is_kallsyms, false);
found:
@@ -627,19 +626,37 @@ out:
return ret;
}
+static bool probe_cache_entry__compare(struct probe_cache_entry *entry,
+ struct strfilter *filter)
+{
+ char buf[128], *ptr = entry->spev;
+
+ if (entry->pev.event) {
+ snprintf(buf, 128, "%s:%s", entry->pev.group, entry->pev.event);
+ ptr = buf;
+ }
+ return strfilter__compare(filter, ptr);
+}
+
+int probe_cache__remove_entries(struct probe_cache *pcache,
+ struct strfilter *filter)
+{
+ struct probe_cache_entry *entry, *tmp;
+
+ list_for_each_entry_safe(entry, tmp, &pcache->list, list) {
+ if (probe_cache_entry__compare(entry, filter))
+ probe_cache_entry__delete(entry);
+ }
+ return 0;
+}
+
static int probe_cache__show_entries(struct probe_cache *pcache,
struct strfilter *filter)
{
struct probe_cache_entry *entry;
- char buf[128], *ptr;
list_for_each_entry(entry, &pcache->list, list) {
- if (entry->pev.event) {
- ptr = buf;
- snprintf(buf, 128, "%s:%s", entry->pev.group, entry->pev.event);
- } else
- ptr = entry->spev;
- if (strfilter__compare(filter, ptr))
+ if (probe_cache_entry__compare(entry, filter))
printf("%s\n", entry->spev);
}
return 0;
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 26dc4f7..391fde0 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -34,6 +34,8 @@ int probe_cache__add_entry(struct probe_cache *pcache,
struct probe_trace_event *tevs, int ntevs);
int probe_cache__commit(struct probe_cache *pcache);
void probe_cache__delete(struct probe_cache *pcache);
+int probe_cache__remove_entries(struct probe_cache *pcache,
+ struct strfilter *filter);
struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
struct perf_probe_event *pev);
struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
From: Hemant Kumar <[email protected]>
This patch serves the initial support to identify and list SDT events in binaries.
When programs containing SDT markers are compiled, gcc with the help of assembler
directives identifies them and places them in the section ".note.stapsdt". To find
these markers from the binaries, one needs to traverse through this section and
parse the relevant details like the name, type and location of the marker. Also,
the original location could be skewed due to the effect of prelinking. If that is
the case, the locations need to be adjusted.
The functions in this patch open a given ELF, find out the SDT section, parse the
relevant details, adjust the location (if necessary) and populate them in a list.
A typical note entry in ".note.stapsdt" section is as follows :
|--nhdr.n_namesz--|
------------------------------------
| nhdr | "stapsdt" |
----- |----------------------------------|
| | <location> <base_address> |
| | <semaphore> |
nhdr.n_descsize | "provider_name" "note_name" |
| | <args> |
----- |----------------------------------|
| nhdr | "stapsdt" |
|...
The above shows an excerpt from the section ".note.stapsdt".
'nhdr' is a structure which has the note name size (n_namesz), note
description size (n_desc_sz) and note type (n_type). So, in order to
parse the note note info, we need nhdr to tell us where to start from.
As can be seen from <sys/sdt.h>, the name of the SDT notes given is "stapsdt".
But this is not the identifier of the note.
After that, we go to description of the note to find out its location, the
address of the ".stapsdt.base" section and the semaphore address.
Then, we find the provider name and the SDT marker name and then follow the
arguments.
Signed-off-by: Hemant Kumar <[email protected]>
Acked-by: Namhyung Kim <[email protected]>
---
tools/perf/util/symbol-elf.c | 252 ++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/symbol.h | 22 ++++
2 files changed, 274 insertions(+)
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 65f7e38..6bffa6a 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1775,6 +1775,258 @@ void kcore_extract__delete(struct kcore_extract *kce)
unlink(kce->extract_filename);
}
+/**
+ * populate_sdt_note : Parse raw data and identify SDT note
+ * @elf: elf of the opened file
+ * @data: raw data of a section with description offset applied
+ * @len: note description size
+ * @type: type of the note
+ * @sdt_notes: List to add the SDT note
+ *
+ * Responsible for parsing the @data in section .note.stapsdt in @elf and
+ * if its an SDT note, it appends to @sdt_notes list.
+ */
+static int populate_sdt_note(Elf **elf, const char *data, size_t len,
+ struct list_head *sdt_notes)
+{
+ const char *provider, *name;
+ struct sdt_note *tmp = NULL;
+ GElf_Ehdr ehdr;
+ GElf_Addr base_off = 0;
+ GElf_Shdr shdr;
+ int ret = -EINVAL;
+
+ union {
+ Elf64_Addr a64[NR_ADDR];
+ Elf32_Addr a32[NR_ADDR];
+ } buf;
+
+ Elf_Data dst = {
+ .d_buf = &buf, .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
+ .d_size = gelf_fsize((*elf), ELF_T_ADDR, NR_ADDR, EV_CURRENT),
+ .d_off = 0, .d_align = 0
+ };
+ Elf_Data src = {
+ .d_buf = (void *) data, .d_type = ELF_T_ADDR,
+ .d_version = EV_CURRENT, .d_size = dst.d_size, .d_off = 0,
+ .d_align = 0
+ };
+
+ tmp = (struct sdt_note *)calloc(1, sizeof(struct sdt_note));
+ if (!tmp) {
+ ret = -ENOMEM;
+ goto out_err;
+ }
+
+ INIT_LIST_HEAD(&tmp->note_list);
+
+ if (len < dst.d_size + 3)
+ goto out_free_note;
+
+ /* Translation from file representation to memory representation */
+ if (gelf_xlatetom(*elf, &dst, &src,
+ elf_getident(*elf, NULL)[EI_DATA]) == NULL) {
+ pr_err("gelf_xlatetom : %s\n", elf_errmsg(-1));
+ goto out_free_note;
+ }
+
+ /* Populate the fields of sdt_note */
+ provider = data + dst.d_size;
+
+ name = (const char *)memchr(provider, '\0', data + len - provider);
+ if (name++ == NULL)
+ goto out_free_note;
+
+ tmp->provider = strdup(provider);
+ if (!tmp->provider) {
+ ret = -ENOMEM;
+ goto out_free_note;
+ }
+ tmp->name = strdup(name);
+ if (!tmp->name) {
+ ret = -ENOMEM;
+ goto out_free_prov;
+ }
+
+ if (gelf_getclass(*elf) == ELFCLASS32) {
+ memcpy(&tmp->addr, &buf, 3 * sizeof(Elf32_Addr));
+ tmp->bit32 = true;
+ } else {
+ memcpy(&tmp->addr, &buf, 3 * sizeof(Elf64_Addr));
+ tmp->bit32 = false;
+ }
+
+ if (!gelf_getehdr(*elf, &ehdr)) {
+ pr_debug("%s : cannot get elf header.\n", __func__);
+ ret = -EBADF;
+ goto out_free_name;
+ }
+
+ /* Adjust the prelink effect :
+ * Find out the .stapsdt.base section.
+ * This scn will help us to handle prelinking (if present).
+ * Compare the retrieved file offset of the base section with the
+ * base address in the description of the SDT note. If its different,
+ * then accordingly, adjust the note location.
+ */
+ if (elf_section_by_name(*elf, &ehdr, &shdr, SDT_BASE_SCN, NULL)) {
+ base_off = shdr.sh_offset;
+ if (base_off) {
+ if (tmp->bit32)
+ tmp->addr.a32[0] = tmp->addr.a32[0] + base_off -
+ tmp->addr.a32[1];
+ else
+ tmp->addr.a64[0] = tmp->addr.a64[0] + base_off -
+ tmp->addr.a64[1];
+ }
+ }
+
+ list_add_tail(&tmp->note_list, sdt_notes);
+ return 0;
+
+out_free_name:
+ free(tmp->name);
+out_free_prov:
+ free(tmp->provider);
+out_free_note:
+ free(tmp);
+out_err:
+ return ret;
+}
+
+/**
+ * construct_sdt_notes_list : constructs a list of SDT notes
+ * @elf : elf to look into
+ * @sdt_notes : empty list_head
+ *
+ * Scans the sections in 'elf' for the section
+ * .note.stapsdt. It, then calls populate_sdt_note to find
+ * out the SDT events and populates the 'sdt_notes'.
+ */
+static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes)
+{
+ GElf_Ehdr ehdr;
+ Elf_Scn *scn = NULL;
+ Elf_Data *data;
+ GElf_Shdr shdr;
+ size_t shstrndx, next;
+ GElf_Nhdr nhdr;
+ size_t name_off, desc_off, offset;
+ int ret = 0;
+
+ if (gelf_getehdr(elf, &ehdr) == NULL) {
+ ret = -EBADF;
+ goto out_ret;
+ }
+ if (elf_getshdrstrndx(elf, &shstrndx) != 0) {
+ ret = -EBADF;
+ goto out_ret;
+ }
+
+ /* Look for the required section */
+ scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL);
+ if (!scn) {
+ ret = -ENOENT;
+ goto out_ret;
+ }
+
+ if ((shdr.sh_type != SHT_NOTE) || (shdr.sh_flags & SHF_ALLOC)) {
+ ret = -ENOENT;
+ goto out_ret;
+ }
+
+ data = elf_getdata(scn, NULL);
+
+ /* Get the SDT notes */
+ for (offset = 0; (next = gelf_getnote(data, offset, &nhdr, &name_off,
+ &desc_off)) > 0; offset = next) {
+ if (nhdr.n_namesz == sizeof(SDT_NOTE_NAME) &&
+ !memcmp(data->d_buf + name_off, SDT_NOTE_NAME,
+ sizeof(SDT_NOTE_NAME))) {
+ /* Check the type of the note */
+ if (nhdr.n_type != SDT_NOTE_TYPE)
+ goto out_ret;
+
+ ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off),
+ nhdr.n_descsz, sdt_notes);
+ if (ret < 0)
+ goto out_ret;
+ }
+ }
+ if (list_empty(sdt_notes))
+ ret = -ENOENT;
+
+out_ret:
+ return ret;
+}
+
+/**
+ * get_sdt_note_list : Wrapper to construct a list of sdt notes
+ * @head : empty list_head
+ * @target : file to find SDT notes from
+ *
+ * This opens the file, initializes
+ * the ELF and then calls construct_sdt_notes_list.
+ */
+int get_sdt_note_list(struct list_head *head, const char *target)
+{
+ Elf *elf;
+ int fd, ret;
+
+ fd = open(target, O_RDONLY);
+ if (fd < 0)
+ return -EBADF;
+
+ elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
+ if (!elf) {
+ ret = -EBADF;
+ goto out_close;
+ }
+ ret = construct_sdt_notes_list(elf, head);
+ elf_end(elf);
+out_close:
+ close(fd);
+ return ret;
+}
+
+/**
+ * cleanup_sdt_note_list : free the sdt notes' list
+ * @sdt_notes: sdt notes' list
+ *
+ * Free up the SDT notes in @sdt_notes.
+ * Returns the number of SDT notes free'd.
+ */
+int cleanup_sdt_note_list(struct list_head *sdt_notes)
+{
+ struct sdt_note *tmp, *pos;
+ int nr_free = 0;
+
+ list_for_each_entry_safe(pos, tmp, sdt_notes, note_list) {
+ list_del(&pos->note_list);
+ free(pos->name);
+ free(pos->provider);
+ free(pos);
+ nr_free++;
+ }
+ return nr_free;
+}
+
+/**
+ * sdt_notes__get_count: Counts the number of sdt events
+ * @start: list_head to sdt_notes list
+ *
+ * Returns the number of SDT notes in a list
+ */
+int sdt_notes__get_count(struct list_head *start)
+{
+ struct sdt_note *sdt_ptr;
+ int count = 0;
+
+ list_for_each_entry(sdt_ptr, start, note_list)
+ count++;
+ return count;
+}
+
void symbol__elf_init(void)
{
elf_version(EV_CURRENT);
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index bef47ead..c38af26 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -311,4 +311,26 @@ void arch__elf_sym_adjust(GElf_Sym *sym);
int arch__choose_best_symbol(struct symbol *syma, struct symbol *symb);
+/* structure containing an SDT note's info */
+struct sdt_note {
+ char *name; /* name of the note*/
+ char *provider; /* provider name */
+ bool bit32; /* whether the location is 32 bits? */
+ union { /* location, base and semaphore addrs */
+ Elf64_Addr a64[3];
+ Elf32_Addr a32[3];
+ } addr;
+ struct list_head note_list; /* SDT notes' list */
+};
+
+int get_sdt_note_list(struct list_head *head, const char *target);
+int cleanup_sdt_note_list(struct list_head *sdt_notes);
+int sdt_notes__get_count(struct list_head *start);
+
+#define SDT_BASE_SCN ".stapsdt.base"
+#define SDT_NOTE_SCN ".note.stapsdt"
+#define SDT_NOTE_TYPE 3
+#define SDT_NOTE_NAME "stapsdt"
+#define NR_ADDR 3
+
#endif /* __PERF_SYMBOL */
Allow user to set group name for adding new event.
Note that this can easily shot yourself in the foot.
E.g. Existing group name can conflict with other events.
Especially, using the group name reserved for kernel
modules can break something when loading/unloading
modules.
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/probe-event.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 262f9d3..c19a380 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1141,10 +1141,8 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
bool file_spec = false;
/*
* <Syntax>
- * perf probe [EVENT=]SRC[:LN|;PTN]
- * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
- *
- * TODO:Group name support
+ * perf probe [GRP:][EVENT=]SRC[:LN|;PTN]
+ * perf probe [GRP:][EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
*/
if (!arg)
return -EINVAL;
@@ -1153,11 +1151,19 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
if (ptr && *ptr == '=') { /* Event name */
*ptr = '\0';
tmp = ptr + 1;
- if (strchr(arg, ':')) {
- semantic_error("Group name is not supported yet.\n");
- return -ENOTSUP;
- }
+ ptr = strchr(arg, ':');
+ if (ptr) {
+ *ptr = '\0';
+ if (!is_c_func_name(arg))
+ goto not_fname;
+ pev->group = strdup(arg);
+ if (!pev->group)
+ return -ENOMEM;
+ arg = ptr + 1;
+ } else
+ pev->group = NULL;
if (!is_c_func_name(arg)) {
+not_fname:
semantic_error("%s is bad for event name -it must "
"follow C symbol-naming rule.\n", arg);
return -EINVAL;
@@ -1165,7 +1171,6 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
pev->event = strdup(arg);
if (pev->event == NULL)
return -ENOMEM;
- pev->group = NULL;
arg = tmp;
}
perf buildid-cache --add <binary> scans given binary and add
the SDT events to probe cache. It is possible to use the cached
SDT events as other cached events (perf probe <provider>:<event>=<event>).
e.g.
----
# perf buildid-cache --add /lib/libc-2.17.so
# perf probe --cache --list | head -n 5
/usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
libc:setjmp=setjmp
libc:longjmp=longjmp
libc:longjmp_target=longjmp_target
libc:memory_heap_new=memory_heap_new
# perf probe -x /usr/lib/libc-2.17.so \
-a libc:memory_heap_new=memory_heap_new
Added new event:
libc:memory_heap_new (on memory_heap_new
in /usr/lib/libc-2.17.so)
You can now use it in all perf tools, such as:
perf record -e libc:memory_heap_new -aR sleep 1
# perf probe -l
libc:memory_heap_new (on new_heap+183 in /usr/lib/libc-2.17.so)
----
Note that SDT event entries in probe-cache file is somewhat different
from normal cached events. Normal one starts with "#", but SDTs are
starting with "%".
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/util/build-id.c | 27 ++++++++++++++++--
tools/perf/util/probe-file.c | 64 ++++++++++++++++++++++++++++++++++++++++--
tools/perf/util/probe-file.h | 2 +
3 files changed, 87 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 63123c1..1adb2c0 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -17,6 +17,7 @@
#include "tool.h"
#include "header.h"
#include "vdso.h"
+#include "probe-file.h"
static bool no_buildid_cache;
@@ -432,6 +433,23 @@ int build_id_cache__list_build_ids(const char *pathname,
return ret;
}
+#ifdef CONFIG_LIBELF
+static void build_id_cache__add_sdt_cache(const char *sbuild_id,
+ const char *realname)
+{
+ struct probe_cache *cache;
+
+ cache = probe_cache__new(sbuild_id);
+ if (!cache)
+ return;
+ if (probe_cache__scan_sdt(cache, realname) >= 0)
+ probe_cache__commit(cache);
+ probe_cache__delete(cache);
+}
+#else
+#define build_id_cache__add_sdt_cache(sbuild_id, realname) do { } while (0)
+#endif
+
int build_id_cache__add_s(const char *sbuild_id, const char *name,
bool is_kallsyms, bool is_vdso)
{
@@ -470,20 +488,23 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name,
goto out_free;
}
+ /* Make a symbolic link */
if (!build_id_cache__linkname(sbuild_id, linkname, size))
goto out_free;
+
tmp = strrchr(linkname, '/');
*tmp = '\0';
-
if (access(linkname, X_OK) && mkdir_p(linkname, 0755))
goto out_free;
-
*tmp = '/';
tmp = dir_name + strlen(buildid_dir) - 5;
memcpy(tmp, "../..", 5);
-
if (symlink(tmp, linkname) == 0)
err = 0;
+
+ /* Update SDT cache */
+ build_id_cache__add_sdt_cache(sbuild_id, realname);
+
out_free:
if (!is_kallsyms)
free(realname);
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index b3a69a3..059f311 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -403,9 +403,12 @@ static int probe_cache__load(struct probe_cache *pcache)
p = strchr(buf, '\n');
if (p)
*p = '\0';
- if (buf[0] == '#') { /* #perf_probe_event */
+ /* #perf_probe_event or %sdt_event */
+ if (buf[0] == '#' || buf[0] == '%') {
entry = probe_cache_entry__new(NULL);
entry->spev = strdup(buf + 1);
+ if (buf[0] == '%')
+ entry->sdt = true;
ret = parse_perf_probe_command(buf + 1, &entry->pev);
if (!entry->spev || ret < 0) {
probe_cache_entry__delete(entry);
@@ -577,14 +580,69 @@ out_err:
return ret;
}
+static unsigned long long sdt_note__get_addr(struct sdt_note *note)
+{
+ return note->bit32 ? (unsigned long long)note->addr.a32[0]
+ : (unsigned long long)note->addr.a64[0];
+}
+
+int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
+{
+ struct probe_cache_entry *entry = NULL;
+ struct list_head sdtlist;
+ struct sdt_note *note;
+ char *buf;
+ int ret;
+
+ INIT_LIST_HEAD(&sdtlist);
+ ret = get_sdt_note_list(&sdtlist, pathname);
+ if (ret < 0) {
+ pr_debug("Failed to get sdt note: %d\n", ret);
+ return ret;
+ }
+ list_for_each_entry(note, &sdtlist, note_list) {
+ entry = probe_cache__find_by_name(pcache, note->provider,
+ note->name);
+ if (entry) /* We've already scanned */
+ continue;
+
+ entry = probe_cache_entry__new(NULL);
+ if (!entry) {
+ ret = -ENOMEM;
+ break;
+ }
+ entry->sdt = true;
+ ret = asprintf(&entry->spev, "%s:%s=%s", note->provider,
+ note->name, note->name);
+ if (ret < 0)
+ break;
+ entry->pev.event = strdup(note->name);
+ entry->pev.group = strdup(note->provider);
+ ret = asprintf(&buf, "p:%s/%s %s:0x%llx",
+ note->provider, note->name,
+ pathname, sdt_note__get_addr(note));
+ if (ret < 0)
+ break;
+ strlist__add(entry->tevlist, buf);
+ free(buf);
+ list_add_tail(&entry->list, &pcache->list);
+ entry = NULL;
+ }
+ if (entry)
+ probe_cache_entry__delete(entry);
+ cleanup_sdt_note_list(&sdtlist);
+ return ret;
+}
+
static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
{
struct str_node *snode;
struct iovec iov[3];
+ const char *prefix = entry->sdt ? "%" : "#";
int ret;
- pr_debug("Writing cache: #%s\n", entry->spev);
- iov[0].iov_base = (void *)"#"; iov[0].iov_len = 1;
+ pr_debug("Writing cache: %s%s\n", prefix, entry->spev);
+ iov[0].iov_base = (void *)prefix; iov[0].iov_len = 1;
iov[1].iov_base = entry->spev; iov[1].iov_len = strlen(entry->spev);
iov[2].iov_base = (void *)"\n"; iov[2].iov_len = 1;
ret = writev(fd, iov, 3);
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 391fde0..9a9b0c5 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -18,6 +18,7 @@ int probe_file__del_events(int fd, struct strfilter *filter);
/* Cache of probe definitions */
struct probe_cache_entry {
struct list_head list;
+ bool sdt;
struct perf_probe_event pev;
char *spev;
struct strlist *tevlist;
@@ -32,6 +33,7 @@ struct probe_cache *probe_cache__new(const char *target);
int probe_cache__add_entry(struct probe_cache *pcache,
struct perf_probe_event *pev,
struct probe_trace_event *tevs, int ntevs);
+int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname);
int probe_cache__commit(struct probe_cache *pcache);
void probe_cache__delete(struct probe_cache *pcache);
int probe_cache__remove_entries(struct probe_cache *pcache,
To improbe usability, support %[PROVIDER:]SDTEVENT format to
add new probes on SDT and cached events.
e.g.
----
# perf probe -x /lib/libc-2.17.so %lll_lock_wait_private
Added new event:
libc:lll_lock_wait_private (on %lll_lock_wait_private in
/usr/lib/libc-2.17.so)
You can now use it in all perf tools, such as:
perf record -e libc:lll_lock_wait_private -aR sleep 1
# perf probe -l | more
libc:lll_lock_wait_private (on __lll_lock_wait_private+21
in /usr/lib/libc-2.17.so)
----
Note that this is not only for SDT events, but also normal
events with event-name.
e.g. define "myevent" on cache (-n doesn't add the real probe)
----
# perf probe -x ./perf --cache -n --add 'myevent=dso__load $params'
----
Reuse the "myevent" from cache as below.
----
# perf probe -x ./perf %myevent
----
Signed-off-by: Masami Hiramatsu <[email protected]>
---
tools/perf/Documentation/perf-probe.txt | 3 +
tools/perf/util/probe-event.c | 78 ++++++++++++++++++++++---------
tools/perf/util/probe-event.h | 1
tools/perf/util/probe-file.c | 9 ++++
4 files changed, 69 insertions(+), 22 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 8d09173..1d38221 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -151,11 +151,14 @@ Probe points are defined by following syntax.
3) Define event based on source file with lazy pattern
[EVENT=]SRC;PTN [ARG ...]
+ 4) Pre-defined SDT events
+ %[PROVIDER:]SDTEVENT
'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'.
'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition. In addition, '@SRC' specifies a source file which has that function.
It is also possible to specify a probe point by the source line number or lazy matching by using 'SRC:ALN' or 'SRC;PTN' syntax, where 'SRC' is the source file path, ':ALN' is the line number and ';PTN' is the lazy matching pattern.
'ARG' specifies the arguments of this probe point, (see PROBE ARGUMENT).
+'SDTEVENT' and 'PROVIDER' is the pre-defined event name which is defined by user SDT (Statically Defined Tracing) or the pre-cached probes with event name.
PROBE ARGUMENT
--------------
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index c19a380..0aad70d 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1132,6 +1132,34 @@ err:
return err;
}
+static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
+{
+ char *ptr;
+
+ ptr = strchr(*arg, ':');
+ if (ptr) {
+ *ptr = '\0';
+ if (!is_c_func_name(*arg))
+ goto ng_name;
+ pev->group = strdup(*arg);
+ if (!pev->group)
+ return -ENOMEM;
+ *arg = ptr + 1;
+ } else
+ pev->group = NULL;
+ if (!is_c_func_name(*arg)) {
+ng_name:
+ semantic_error("%s is bad for event name -it must "
+ "follow C symbol-naming rule.\n", *arg);
+ return -EINVAL;
+ }
+ pev->event = strdup(*arg);
+ if (pev->event == NULL)
+ return -ENOMEM;
+
+ return 0;
+}
+
/* Parse probepoint definition. */
static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
{
@@ -1139,38 +1167,43 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
char *ptr, *tmp;
char c, nc = 0;
bool file_spec = false;
+ int ret;
+
/*
* <Syntax>
* perf probe [GRP:][EVENT=]SRC[:LN|;PTN]
* perf probe [GRP:][EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
+ * perf probe %[GRP:]SDT_EVENT
*/
if (!arg)
return -EINVAL;
+ if (arg[0] == '%') {
+ pev->sdt = true;
+ arg++;
+ }
+
ptr = strpbrk(arg, ";=@+%");
- if (ptr && *ptr == '=') { /* Event name */
- *ptr = '\0';
- tmp = ptr + 1;
- ptr = strchr(arg, ':');
+ if (pev->sdt) {
if (ptr) {
- *ptr = '\0';
- if (!is_c_func_name(arg))
- goto not_fname;
- pev->group = strdup(arg);
- if (!pev->group)
- return -ENOMEM;
- arg = ptr + 1;
- } else
- pev->group = NULL;
- if (!is_c_func_name(arg)) {
-not_fname:
- semantic_error("%s is bad for event name -it must "
- "follow C symbol-naming rule.\n", arg);
+ semantic_error("%s must contain only an SDT event name.\n", arg);
return -EINVAL;
}
- pev->event = strdup(arg);
- if (pev->event == NULL)
- return -ENOMEM;
+ ret = parse_perf_probe_event_name(&arg, pev);
+ if (ret == 0) {
+ if (asprintf(&pev->point.function, "%%%s", pev->event) < 0)
+ ret = -errno;
+ }
+ return ret;
+ }
+
+ if (ptr && *ptr == '=') { /* Event name */
+ *ptr = '\0';
+ tmp = ptr + 1;
+ ret = parse_perf_probe_event_name(&arg, pev);
+ if (ret < 0)
+ return ret;
+
arg = tmp;
}
@@ -2624,7 +2657,8 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
pev->point.function);
}
if (!entry) {
- ret = 0;
+ /* SDT must be in the cache */
+ ret = pev->sdt ? -ENOENT : 0;
goto out;
}
@@ -2663,7 +2697,7 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
{
int ret;
- if (pev->uprobes && !pev->group) {
+ if (pev->uprobes && !pev->sdt && !pev->group) {
/* Replace group name if not given */
ret = convert_exec_to_group(pev->target, &pev->group);
if (ret != 0) {
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 9aceba3..b290194 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -84,6 +84,7 @@ struct perf_probe_event {
char *group; /* Group name */
struct perf_probe_point point; /* Probe point */
int nargs; /* Number of arguments */
+ bool sdt; /* SDT/cached event flag */
bool uprobes; /* Uprobe event flag */
char *target; /* Target binary */
struct perf_probe_arg *args; /* Arguments */
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 059f311..8efad73 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -504,6 +504,15 @@ probe_cache__find(struct probe_cache *pcache, struct perf_probe_event *pev)
return NULL;
list_for_each_entry(entry, &pcache->list, list) {
+ if (pev->sdt) {
+ if (entry->pev.event &&
+ streql(entry->pev.event, pev->event) &&
+ (!pev->group ||
+ streql(entry->pev.group, pev->group)))
+ goto found;
+
+ continue;
+ }
/* Hit if same event name or same command-string */
if ((pev->event &&
(streql(entry->pev.group, pev->group) &&
Hi Masami,
On 07/15/2015 02:43 PM, Masami Hiramatsu wrote:
> Hi,
>
> Here is the 2nd version of the patchset for probe-cache and
> initial SDT support which are going to be perf-cache finally.
Thanks for adding the SDT support.
> The perf-probe is useful for debugging, but it strongly depends
> on the debuginfo. Without debuginfo, it is just a frontend of
> ftrace's dynamic events. This can usually happen in server
> farms or on cloud system, since no one wants to distribute
> big debuginfo packages.
>
> To solve this issue, I had tried to make a pre-analyzed probes
> ( https://lkml.org/lkml/2014/10/31/207 ) but it has a problm
> that we can't ensure the probed binary is same as what we analyzed.
> Arnaldo gave me an idea to reuse build-id cache for that perpose
> and this series is the first prototype of that.
>
> At the same time, Hemant has started to support SDT probes which
> also use the cache file of SDT info. So I decided to merge this
> into the same build-id cache.
> In this version, SDT support is still very limited, it works
> as a part of probe-cache.
>
> In this version, perf probe supports --cache option which means
> that perf probe manipulate probe caches, for example,
>
> # perf probe --cache --add "probe-desc"
>
> does not only add probe events but also add "probe-desc" and
> it's result on the cache. (Note that the cached entry is always
> referred even without --cache)
> The --list and --del commands also support --cache. Note that
> both are only manipulate caches, not real events.
>
> To use SDT, we have to scan the target binary at first by using
> perf-buildid-cache, e.g.
>
> # perf buildid-cache --add /lib/libc-2.17.so
>
> And perf probe --cache --list shows what SDTs are scanned.
>
> # perf probe --cache --list
> /usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
> libc:setjmp=setjmp
> libc:longjmp=longjmp
> libc:longjmp_target=longjmp_target
> libc:memory_heap_new=memory_heap_new
> libc:memory_sbrk_less=memory_sbrk_less
> libc:memory_arena_reuse_free_list=memory_arena_reuse_free_list
> libc:memory_arena_reuse=memory_arena_reuse
> ...
>
> To use the SDT events, perf probe -x BIN %SDTEVENT allows you to
> add a probe on SDTEVENT@BIN.
>
> # perf probe -x /lib/libc-2.17.so %memory_heap_new
>
> If you define a cached probe with event name, you can also reuse
> it as same as SDT events.
>
> # perf probe -x ./perf --cache -n 'myevent=dso__load $params'
>
> (Note that "-n" option only updates caches)
> To use the above "myevent", you just have to add "%myevent".
>
> # perf probe -x ./perf %myevent
>
>
> TODOs:
> - Show available cached/SDT events by perf-list
> - Allow perf-record to use cached/SDT events directly
As I was already working on SDT events' recording
https://lkml.org/lkml/2014/11/2/73,
I can re-spin the patches on top of your patchset and make the
required changes to implement the above TODOs.
What would you suggest?
> Thank you,
>
> ---
>
> Hemant Kumar (1):
> perf/sdt: ELF support for SDT
>
> Masami Hiramatsu (15):
> perf probe: Simplify __add_probe_trace_events code
> perf probe: Move ftrace probe-event operations to probe-file.c
> perf probe: Use strbuf for making strings in probe-event.c
> perf-buildid-cache: Use path/to/bin/buildid/elf instead of path/to/bin/buildid
> perf buildid: Use SBUILD_ID_SIZE macro
> perf buildid: Introduce sysfs/filename__sprintf_build_id
> perf: Add lsdir to read a directory
> perf-buildid-cache: Use lsdir for looking up buildid caches
> perf probe: Add --cache option to cache the probe definitions
> perf probe: Use cache entry if possible
> perf probe: Show all cached probes
> perf probe: Remove caches when --cache is given
> perf probe: Add group name support
> perf buildid-cache: Scan and import user SDT events to probe cache
> perf probe: Accept %sdt and %cached event name
>
>
> tools/perf/Documentation/perf-probe.txt | 14
> tools/perf/builtin-buildid-cache.c | 22 -
> tools/perf/builtin-buildid-list.c | 28 -
> tools/perf/builtin-probe.c | 3
> tools/perf/util/Build | 1
> tools/perf/util/build-id.c | 230 ++++++--
> tools/perf/util/build-id.h | 11
> tools/perf/util/dso.h | 5
> tools/perf/util/probe-event.c | 918 ++++++++++++++-----------------
> tools/perf/util/probe-event.h | 16 -
> tools/perf/util/probe-file.c | 763 ++++++++++++++++++++++++++
> tools/perf/util/probe-file.h | 46 ++
> tools/perf/util/probe-finder.c | 10
> tools/perf/util/symbol-elf.c | 252 +++++++++
> tools/perf/util/symbol.c | 2
> tools/perf/util/symbol.h | 22 +
> tools/perf/util/util.c | 34 +
> tools/perf/util/util.h | 4
> 18 files changed, 1781 insertions(+), 600 deletions(-)
> create mode 100644 tools/perf/util/probe-file.c
> create mode 100644 tools/perf/util/probe-file.h
>
>
--
Thanks,
Hemant Kumar
Hi Hemant,
On 2015/07/16 12:13, Hemant Kumar wrote:
> Hi Masami,
>
> On 07/15/2015 02:43 PM, Masami Hiramatsu wrote:
>> Hi,
>>
>> Here is the 2nd version of the patchset for probe-cache and
>> initial SDT support which are going to be perf-cache finally.
>
> Thanks for adding the SDT support.
>
>> The perf-probe is useful for debugging, but it strongly depends
>> on the debuginfo. Without debuginfo, it is just a frontend of
>> ftrace's dynamic events. This can usually happen in server
>> farms or on cloud system, since no one wants to distribute
>> big debuginfo packages.
>>
>> To solve this issue, I had tried to make a pre-analyzed probes
>> ( https://lkml.org/lkml/2014/10/31/207 ) but it has a problm
>> that we can't ensure the probed binary is same as what we analyzed.
>> Arnaldo gave me an idea to reuse build-id cache for that perpose
>> and this series is the first prototype of that.
>>
>> At the same time, Hemant has started to support SDT probes which
>> also use the cache file of SDT info. So I decided to merge this
>> into the same build-id cache.
>> In this version, SDT support is still very limited, it works
>> as a part of probe-cache.
>>
>> In this version, perf probe supports --cache option which means
>> that perf probe manipulate probe caches, for example,
>>
>> # perf probe --cache --add "probe-desc"
>>
>> does not only add probe events but also add "probe-desc" and
>> it's result on the cache. (Note that the cached entry is always
>> referred even without --cache)
>> The --list and --del commands also support --cache. Note that
>> both are only manipulate caches, not real events.
>>
>> To use SDT, we have to scan the target binary at first by using
>> perf-buildid-cache, e.g.
>>
>> # perf buildid-cache --add /lib/libc-2.17.so
>>
>> And perf probe --cache --list shows what SDTs are scanned.
>>
>> # perf probe --cache --list
>> /usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
>> libc:setjmp=setjmp
>> libc:longjmp=longjmp
>> libc:longjmp_target=longjmp_target
>> libc:memory_heap_new=memory_heap_new
>> libc:memory_sbrk_less=memory_sbrk_less
>> libc:memory_arena_reuse_free_list=memory_arena_reuse_free_list
>> libc:memory_arena_reuse=memory_arena_reuse
>> ...
>>
>> To use the SDT events, perf probe -x BIN %SDTEVENT allows you to
>> add a probe on SDTEVENT@BIN.
>>
>> # perf probe -x /lib/libc-2.17.so %memory_heap_new
>>
>> If you define a cached probe with event name, you can also reuse
>> it as same as SDT events.
>>
>> # perf probe -x ./perf --cache -n 'myevent=dso__load $params'
>>
>> (Note that "-n" option only updates caches)
>> To use the above "myevent", you just have to add "%myevent".
>>
>> # perf probe -x ./perf %myevent
>>
>>
>> TODOs:
>> - Show available cached/SDT events by perf-list
>> - Allow perf-record to use cached/SDT events directly
>
> As I was already working on SDT events' recording
> https://lkml.org/lkml/2014/11/2/73,
> I can re-spin the patches on top of your patchset and make the
> required changes to implement the above TODOs.
Sounds great! :)
Note that you'll need to re-implement almost from scratch, since
now the SDT is implemented on buildid-cache. Maybe I have to work
on the buildid-cache one more to filter out binaries which are gone
or different version from current running one (e.g. old vmlinux).
It could help you to get available SDTs when showing it via perf-list.
> What would you suggest?
Now I'm thinking that we should avoid using %event syntax for perf-list
and perf-record to avoid confusion. For example, suppose that we have
"libfoo:bar" SDT event, when we just scanned the libfoo binary and
use it via perf-record, we'll run perf record -e "%libfoo:bar".
However, after we set the probe via perf-probe, we have to run
perf record -e "libfoo:bar". That difference looks no good.
So, I think in both case it should accept -e "libfoo:bar" syntax.
In this series I've introduced %event syntax only to recall cached event
setting explicitly, because perf-probe is a lower layer tool to set up
new event. IMO, perf-list and perf-record should be higher tools which
handle abstract events.
Thanks!
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Hi Masami,
On Wed, Jul 15, 2015 at 06:14:14PM +0900, Masami Hiramatsu wrote:
> Replace many fixed-length char array with strbuf to
> stringify perf_probe_event and probe_trace_event etc. in
> util/probe-event.c.
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
> ---
[SNIP]
> + ret = strbuf_detach(&buf, NULL);
> + strbuf_release(&buf);
It seems that strbuf_release() is meaningless after strbuf_detach().
>
> - return tmp - buf;
> -error:
> - pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
> return ret;
> }
>
> /* Compose only probe point (not argument) */
> static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
> {
> - char *buf, *tmp;
> - char offs[32] = "", line[32] = "", file[32] = "";
> - int ret, len;
> -
> - buf = zalloc(MAX_CMDLEN);
> - if (buf == NULL) {
> - ret = -ENOMEM;
> - goto error;
> - }
> - if (pp->offset) {
> - ret = e_snprintf(offs, 32, "+%lu", pp->offset);
> - if (ret <= 0)
> - goto error;
> - }
> - if (pp->line) {
> - ret = e_snprintf(line, 32, ":%d", pp->line);
> - if (ret <= 0)
> - goto error;
> + struct strbuf buf;
> + char *tmp;
> + int len;
> +
> + strbuf_init(&buf, 64);
> + if (pp->function) {
> + strbuf_addstr(&buf, pp->function);
> + if (pp->offset)
> + strbuf_addf(&buf, "+%lu", pp->offset);
> + else if (pp->line)
> + strbuf_addf(&buf, ":%d", pp->line);
> + else if (pp->retprobe)
> + strbuf_addstr(&buf, "%return");
> }
> if (pp->file) {
> tmp = pp->file;
> @@ -1633,25 +1616,14 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
> tmp = strchr(pp->file + len - 30, '/');
> tmp = tmp ? tmp + 1 : pp->file + len - 30;
> }
> - ret = e_snprintf(file, 32, "@%s", tmp);
> - if (ret <= 0)
> - goto error;
> + strbuf_addf(&buf, "@%s", tmp);
> + if (!pp->function && pp->line)
> + strbuf_addf(&buf, ":%d", pp->line);
> }
>
> - if (pp->function)
> - ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
> - offs, pp->retprobe ? "%return" : "", line,
> - file);
> - else
> - ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
> - if (ret <= 0)
> - goto error;
> -
> - return buf;
> -error:
> - pr_debug("Failed to synthesize perf probe point: %d\n", ret);
> - free(buf);
> - return NULL;
> + tmp = strbuf_detach(&buf, NULL);
> + strbuf_release(&buf);
Ditto.
> + return tmp;
> }
[SNIP]
> char *synthesize_probe_trace_command(struct probe_trace_event *tev)
> {
> struct probe_trace_point *tp = &tev->point;
> - char *buf;
> - int i, len, ret;
> -
> - buf = zalloc(MAX_CMDLEN);
> - if (buf == NULL)
> - return NULL;
> -
> - len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
> - tev->group, tev->event);
> - if (len <= 0)
> - goto error;
> + struct strbuf buf;
> + char *ret = NULL;
> + int i;
>
> /* Uprobes must have tp->address and tp->module */
> if (tev->uprobes && (!tp->address || !tp->module))
> - goto error;
> + return NULL;
> +
> + strbuf_init(&buf, 32);
> + strbuf_addf(&buf, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
> + tev->group, tev->event);
>
> /* Use the tp->address for uprobes */
> if (tev->uprobes)
> - ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx",
> - tp->module, tp->address);
> + strbuf_addf(&buf, "%s:0x%lx", tp->module, tp->address);
> else
> - ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu",
> - tp->module ?: "", tp->module ? ":" : "",
> - tp->symbol, tp->offset);
> -
> - if (ret <= 0)
> - goto error;
> - len += ret;
> + strbuf_addf(&buf, "%s%s%s+%lu", tp->module ?: "",
> + tp->module ? ":" : "", tp->symbol, tp->offset);
>
> for (i = 0; i < tev->nargs; i++) {
> - ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
> - MAX_CMDLEN - len);
> - if (ret <= 0)
> + if (synthesize_probe_trace_arg(&tev->args[i], &buf) < 0)
> goto error;
> - len += ret;
> }
>
> - return buf;
> + ret = strbuf_detach(&buf, NULL);
> error:
> - free(buf);
> - return NULL;
> + strbuf_release(&buf);
This is necessary for the error path.
> + return ret;
> }
>
> static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
> @@ -1883,7 +1812,7 @@ static int convert_to_perf_probe_point(struct probe_trace_point *tp,
> static int convert_to_perf_probe_event(struct probe_trace_event *tev,
> struct perf_probe_event *pev, bool is_kprobe)
> {
> - char buf[64] = "";
> + struct strbuf buf = STRBUF_INIT;
> int i, ret;
>
> /* Convert event/group name */
> @@ -1906,9 +1835,10 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
> if (tev->args[i].name)
> pev->args[i].name = strdup(tev->args[i].name);
> else {
> - ret = synthesize_probe_trace_arg(&tev->args[i],
> - buf, 64);
> - pev->args[i].name = strdup(buf);
> + strbuf_init(&buf, 32);
> + ret = synthesize_probe_trace_arg(&tev->args[i], &buf);
> + pev->args[i].name = strbuf_detach(&buf, NULL);
> + strbuf_release(&buf);
Ditto.
Thanks,
Namhyung
> }
> if (pev->args[i].name == NULL && ret >= 0)
> ret = -ENOMEM;
On 2015/07/17 16:42, Namhyung Kim wrote:
> Hi Masami,
>
> On Wed, Jul 15, 2015 at 06:14:14PM +0900, Masami Hiramatsu wrote:
>> Replace many fixed-length char array with strbuf to
>> stringify perf_probe_event and probe_trace_event etc. in
>> util/probe-event.c.
>>
>> Signed-off-by: Masami Hiramatsu <[email protected]>
>> ---
>
> [SNIP]
>
>> + ret = strbuf_detach(&buf, NULL);
>> + strbuf_release(&buf);
>
> It seems that strbuf_release() is meaningless after strbuf_detach().
Ah, right! I'll remove those redundant strbuf_release.
Thanks!
>
>
>>
>> - return tmp - buf;
>> -error:
>> - pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
>> return ret;
>> }
>>
>> /* Compose only probe point (not argument) */
>> static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
>> {
>> - char *buf, *tmp;
>> - char offs[32] = "", line[32] = "", file[32] = "";
>> - int ret, len;
>> -
>> - buf = zalloc(MAX_CMDLEN);
>> - if (buf == NULL) {
>> - ret = -ENOMEM;
>> - goto error;
>> - }
>> - if (pp->offset) {
>> - ret = e_snprintf(offs, 32, "+%lu", pp->offset);
>> - if (ret <= 0)
>> - goto error;
>> - }
>> - if (pp->line) {
>> - ret = e_snprintf(line, 32, ":%d", pp->line);
>> - if (ret <= 0)
>> - goto error;
>> + struct strbuf buf;
>> + char *tmp;
>> + int len;
>> +
>> + strbuf_init(&buf, 64);
>> + if (pp->function) {
>> + strbuf_addstr(&buf, pp->function);
>> + if (pp->offset)
>> + strbuf_addf(&buf, "+%lu", pp->offset);
>> + else if (pp->line)
>> + strbuf_addf(&buf, ":%d", pp->line);
>> + else if (pp->retprobe)
>> + strbuf_addstr(&buf, "%return");
>> }
>> if (pp->file) {
>> tmp = pp->file;
>> @@ -1633,25 +1616,14 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
>> tmp = strchr(pp->file + len - 30, '/');
>> tmp = tmp ? tmp + 1 : pp->file + len - 30;
>> }
>> - ret = e_snprintf(file, 32, "@%s", tmp);
>> - if (ret <= 0)
>> - goto error;
>> + strbuf_addf(&buf, "@%s", tmp);
>> + if (!pp->function && pp->line)
>> + strbuf_addf(&buf, ":%d", pp->line);
>> }
>>
>> - if (pp->function)
>> - ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
>> - offs, pp->retprobe ? "%return" : "", line,
>> - file);
>> - else
>> - ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
>> - if (ret <= 0)
>> - goto error;
>> -
>> - return buf;
>> -error:
>> - pr_debug("Failed to synthesize perf probe point: %d\n", ret);
>> - free(buf);
>> - return NULL;
>> + tmp = strbuf_detach(&buf, NULL);
>> + strbuf_release(&buf);
>
> Ditto.
>
>
>> + return tmp;
>> }
>
>
> [SNIP]
>> char *synthesize_probe_trace_command(struct probe_trace_event *tev)
>> {
>> struct probe_trace_point *tp = &tev->point;
>> - char *buf;
>> - int i, len, ret;
>> -
>> - buf = zalloc(MAX_CMDLEN);
>> - if (buf == NULL)
>> - return NULL;
>> -
>> - len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
>> - tev->group, tev->event);
>> - if (len <= 0)
>> - goto error;
>> + struct strbuf buf;
>> + char *ret = NULL;
>> + int i;
>>
>> /* Uprobes must have tp->address and tp->module */
>> if (tev->uprobes && (!tp->address || !tp->module))
>> - goto error;
>> + return NULL;
>> +
>> + strbuf_init(&buf, 32);
>> + strbuf_addf(&buf, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
>> + tev->group, tev->event);
>>
>> /* Use the tp->address for uprobes */
>> if (tev->uprobes)
>> - ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx",
>> - tp->module, tp->address);
>> + strbuf_addf(&buf, "%s:0x%lx", tp->module, tp->address);
>> else
>> - ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu",
>> - tp->module ?: "", tp->module ? ":" : "",
>> - tp->symbol, tp->offset);
>> -
>> - if (ret <= 0)
>> - goto error;
>> - len += ret;
>> + strbuf_addf(&buf, "%s%s%s+%lu", tp->module ?: "",
>> + tp->module ? ":" : "", tp->symbol, tp->offset);
>>
>> for (i = 0; i < tev->nargs; i++) {
>> - ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
>> - MAX_CMDLEN - len);
>> - if (ret <= 0)
>> + if (synthesize_probe_trace_arg(&tev->args[i], &buf) < 0)
>> goto error;
>> - len += ret;
>> }
>>
>> - return buf;
>> + ret = strbuf_detach(&buf, NULL);
>> error:
>> - free(buf);
>> - return NULL;
>> + strbuf_release(&buf);
>
> This is necessary for the error path.
>
>
>> + return ret;
>> }
>>
>> static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
>> @@ -1883,7 +1812,7 @@ static int convert_to_perf_probe_point(struct probe_trace_point *tp,
>> static int convert_to_perf_probe_event(struct probe_trace_event *tev,
>> struct perf_probe_event *pev, bool is_kprobe)
>> {
>> - char buf[64] = "";
>> + struct strbuf buf = STRBUF_INIT;
>> int i, ret;
>>
>> /* Convert event/group name */
>> @@ -1906,9 +1835,10 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
>> if (tev->args[i].name)
>> pev->args[i].name = strdup(tev->args[i].name);
>> else {
>> - ret = synthesize_probe_trace_arg(&tev->args[i],
>> - buf, 64);
>> - pev->args[i].name = strdup(buf);
>> + strbuf_init(&buf, 32);
>> + ret = synthesize_probe_trace_arg(&tev->args[i], &buf);
>> + pev->args[i].name = strbuf_detach(&buf, NULL);
>> + strbuf_release(&buf);
>
> Ditto.
>
> Thanks,
> Namhyung
>
>> }
>> if (pev->args[i].name == NULL && ret >= 0)
>> ret = -ENOMEM;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Hi Masami,
On Fri, Jul 17, 2015 at 12:21:42PM +0900, Masami Hiramatsu wrote:
> Now I'm thinking that we should avoid using %event syntax for perf-list
> and perf-record to avoid confusion. For example, suppose that we have
> "libfoo:bar" SDT event, when we just scanned the libfoo binary and
> use it via perf-record, we'll run perf record -e "%libfoo:bar".
> However, after we set the probe via perf-probe, we have to run
> perf record -e "libfoo:bar". That difference looks no good.
> So, I think in both case it should accept -e "libfoo:bar" syntax.
I don't remember how the SDT events should be shown to users. Sorry
if I'm missing something here.
AFAIK an SDT event consists of a provider and an event name. So it
can be simply 'provider:event' like tracepoints or
'binary:provider_event' like uprobes.
I like the former because it's simpler but it needs to guarantee that
it doesn't clash with existing tracepoints/[ku]probes. So IIUC we
chose the '%' sign to distinguish them. But after setting a probe at
it, the group name should be the binary name. So the whole event name
might be changed, and this is not good.
So we should use the latter form. But in this case, I think we need a
way to distinguish provider and event names. Since the provider name
also can include '_' characters in it. And maybe it still needs to
distinguish an SDT event and its probe for some reason. In that case,
we might use 'sdt:provider_event' form or something like that.
Thanks,
Namhyung
>
> In this series I've introduced %event syntax only to recall cached event
> setting explicitly, because perf-probe is a lower layer tool to set up
> new event. IMO, perf-list and perf-record should be higher tools which
> handle abstract events.
On Wed, Jul 15, 2015 at 06:15:30PM +0900, Masami Hiramatsu wrote:
> Allow user to set group name for adding new event.
> Note that this can easily shot yourself in the foot.
> E.g. Existing group name can conflict with other events.
> Especially, using the group name reserved for kernel
> modules can break something when loading/unloading
> modules.
Yes, I agree that this can be dangerous. How about enforcing
[ku]probes to make the directory of dynamic events safely? I think
it'd be better putting all dynamic events in a single directory -
e.g. $tracefs/events/probe/. Any events lack group name are created
in the directory. Any events have group name create subdirectories as
group name under the directory. The perf tools (and others too)
should be changed to lookup the directory after the usual location.
What do you think?
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
> ---
> tools/perf/util/probe-event.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 262f9d3..c19a380 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -1141,10 +1141,8 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
> bool file_spec = false;
> /*
> * <Syntax>
> - * perf probe [EVENT=]SRC[:LN|;PTN]
> - * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
> - *
> - * TODO:Group name support
> + * perf probe [GRP:][EVENT=]SRC[:LN|;PTN]
Shouldn't it be
[[GRP:]EVENT=]
?
> + * perf probe [GRP:][EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
Ditto.
Thanks,
Namhyung
> */
> if (!arg)
> return -EINVAL;
> @@ -1153,11 +1151,19 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
> if (ptr && *ptr == '=') { /* Event name */
> *ptr = '\0';
> tmp = ptr + 1;
> - if (strchr(arg, ':')) {
> - semantic_error("Group name is not supported yet.\n");
> - return -ENOTSUP;
> - }
> + ptr = strchr(arg, ':');
> + if (ptr) {
> + *ptr = '\0';
> + if (!is_c_func_name(arg))
> + goto not_fname;
> + pev->group = strdup(arg);
> + if (!pev->group)
> + return -ENOMEM;
> + arg = ptr + 1;
> + } else
> + pev->group = NULL;
> if (!is_c_func_name(arg)) {
> +not_fname:
> semantic_error("%s is bad for event name -it must "
> "follow C symbol-naming rule.\n", arg);
> return -EINVAL;
> @@ -1165,7 +1171,6 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
> pev->event = strdup(arg);
> if (pev->event == NULL)
> return -ENOMEM;
> - pev->group = NULL;
> arg = tmp;
> }
>
>
>
On Wed, Jul 15, 2015 at 06:15:37PM +0900, Masami Hiramatsu wrote:
> perf buildid-cache --add <binary> scans given binary and add
> the SDT events to probe cache. It is possible to use the cached
> SDT events as other cached events (perf probe <provider>:<event>=<event>).
That means lookup the cached SDT events only using event name, right?
What if same event names are used by more than one providers?
>
> e.g.
> ----
> # perf buildid-cache --add /lib/libc-2.17.so
> # perf probe --cache --list | head -n 5
> /usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
> libc:setjmp=setjmp
> libc:longjmp=longjmp
> libc:longjmp_target=longjmp_target
> libc:memory_heap_new=memory_heap_new
I expected something like this instead..
libc:memory_heap_new=new_heap+183
Thanks,
Namhyung
> # perf probe -x /usr/lib/libc-2.17.so \
> -a libc:memory_heap_new=memory_heap_new
> Added new event:
> libc:memory_heap_new (on memory_heap_new
> in /usr/lib/libc-2.17.so)
>
> You can now use it in all perf tools, such as:
>
> perf record -e libc:memory_heap_new -aR sleep 1
>
> # perf probe -l
> libc:memory_heap_new (on new_heap+183 in /usr/lib/libc-2.17.so)
> ----
>
> Note that SDT event entries in probe-cache file is somewhat different
> from normal cached events. Normal one starts with "#", but SDTs are
> starting with "%".
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
On Wed, Jul 15, 2015 at 06:15:44PM +0900, Masami Hiramatsu wrote:
> To improbe usability, support %[PROVIDER:]SDTEVENT format to
> add new probes on SDT and cached events.
Ah, you meant we can skip the provider if the event name is unique..
>
> e.g.
> ----
> # perf probe -x /lib/libc-2.17.so %lll_lock_wait_private
Maybe we can also skip the target path (-x) too in this case.
Thanks,
Namhyung
> Added new event:
> libc:lll_lock_wait_private (on %lll_lock_wait_private in
> /usr/lib/libc-2.17.so)
>
> You can now use it in all perf tools, such as:
>
> perf record -e libc:lll_lock_wait_private -aR sleep 1
>
> # perf probe -l | more
> libc:lll_lock_wait_private (on __lll_lock_wait_private+21
> in /usr/lib/libc-2.17.so)
> ----
>
> Note that this is not only for SDT events, but also normal
> events with event-name.
>
> e.g. define "myevent" on cache (-n doesn't add the real probe)
> ----
> # perf probe -x ./perf --cache -n --add 'myevent=dso__load $params'
> ----
> Reuse the "myevent" from cache as below.
> ----
> # perf probe -x ./perf %myevent
> ----
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
On 2015/07/19 19:53, Namhyung Kim wrote:
> On Wed, Jul 15, 2015 at 06:15:44PM +0900, Masami Hiramatsu wrote:
>> To improbe usability, support %[PROVIDER:]SDTEVENT format to
>> add new probes on SDT and cached events.
>
> Ah, you meant we can skip the provider if the event name is unique..
Right, that's easier for users.
>>
>> e.g.
>> ----
>> # perf probe -x /lib/libc-2.17.so %lll_lock_wait_private
>
> Maybe we can also skip the target path (-x) too in this case.
Agreed. For that feature, we need to improve buildid-cache to get
all valid buildid caches (this means that it has to verify all the
cached binaries' buildid). Anyway, the same feature is required for
showing available cached probe-events on perf-list.
Thank you,
>
> Thanks,
> Namhyung
>
>
>> Added new event:
>> libc:lll_lock_wait_private (on %lll_lock_wait_private in
>> /usr/lib/libc-2.17.so)
>>
>> You can now use it in all perf tools, such as:
>>
>> perf record -e libc:lll_lock_wait_private -aR sleep 1
>>
>> # perf probe -l | more
>> libc:lll_lock_wait_private (on __lll_lock_wait_private+21
>> in /usr/lib/libc-2.17.so)
>> ----
>>
>> Note that this is not only for SDT events, but also normal
>> events with event-name.
>>
>> e.g. define "myevent" on cache (-n doesn't add the real probe)
>> ----
>> # perf probe -x ./perf --cache -n --add 'myevent=dso__load $params'
>> ----
>> Reuse the "myevent" from cache as below.
>> ----
>> # perf probe -x ./perf %myevent
>> ----
>>
>> Signed-off-by: Masami Hiramatsu <[email protected]>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
On 2015/07/19 19:46, Namhyung Kim wrote:
> On Wed, Jul 15, 2015 at 06:15:37PM +0900, Masami Hiramatsu wrote:
>> perf buildid-cache --add <binary> scans given binary and add
>> the SDT events to probe cache. It is possible to use the cached
>> SDT events as other cached events (perf probe <provider>:<event>=<event>).
>
> That means lookup the cached SDT events only using event name, right?
Right,
> What if same event names are used by more than one providers?
That's a good discussion point :)
What I'm thinking is that the real SDT is always prior to other
cached events. (currently not implemented yet)
- if someone gives a same event name, it overwrites previous one.
- if someone gives an event name same as existing SDT, it is not
cached (or rejected)
- if SDT scanned after cached same name events, SDT always overwrites
the entry.
So, the all SDT events will be treated as fixed events.
Note that this will be happen if we agree SDT and probe share the
same namespace :)
>>
>> e.g.
>> ----
>> # perf buildid-cache --add /lib/libc-2.17.so
>> # perf probe --cache --list | head -n 5
>> /usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
>> libc:setjmp=setjmp
>> libc:longjmp=longjmp
>> libc:longjmp_target=longjmp_target
>> libc:memory_heap_new=memory_heap_new
>
> I expected something like this instead..
>
> libc:memory_heap_new=new_heap+183
OK, that's much better :)
>
>
> Thanks,
> Namhyung
>
>
>> # perf probe -x /usr/lib/libc-2.17.so \
>> -a libc:memory_heap_new=memory_heap_new
>> Added new event:
>> libc:memory_heap_new (on memory_heap_new
>> in /usr/lib/libc-2.17.so)
>>
>> You can now use it in all perf tools, such as:
>>
>> perf record -e libc:memory_heap_new -aR sleep 1
>>
>> # perf probe -l
>> libc:memory_heap_new (on new_heap+183 in /usr/lib/libc-2.17.so)
>> ----
>>
>> Note that SDT event entries in probe-cache file is somewhat different
>> from normal cached events. Normal one starts with "#", but SDTs are
>> starting with "%".
>>
>> Signed-off-by: Masami Hiramatsu <[email protected]>
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
On 2015/07/19 19:16, Namhyung Kim wrote:
> On Wed, Jul 15, 2015 at 06:15:30PM +0900, Masami Hiramatsu wrote:
>> Allow user to set group name for adding new event.
>> Note that this can easily shot yourself in the foot.
>> E.g. Existing group name can conflict with other events.
>> Especially, using the group name reserved for kernel
>> modules can break something when loading/unloading
>> modules.
>
> Yes, I agree that this can be dangerous. How about enforcing
> [ku]probes to make the directory of dynamic events safely?
What the safety issue would you afraid?
> I think
> it'd be better putting all dynamic events in a single directory -
> e.g. $tracefs/events/probe/. Any events lack group name are created
> in the directory. Any events have group name create subdirectories as
> group name under the directory. The perf tools (and others too)
> should be changed to lookup the directory after the usual location.
That will be possible, but includes a big change on event namespace,
e.g. how we'll show the events by perf-list? Even if we can avoid
namespace conflict on tracefs, perf-list event namespace is still
fragile.
> What do you think?
I think there are 2 purposes of probe-event, one is just additional
debug points, another is an extensible event-set. The former will not
any namespace problem, we just add it into new namespace. But latter
requires to be treated as a part of existing (in-kernel) events.
And (userspace)SDT is clearly the latter one.
However, avoiding the conflict of namespace is also important, how
about simply using sdt_<PROVIDER>:<NAME> ?
- Give just a name on a userspace binary
perf probe -x <BIN> --add <NAME>=<PROBEDEF>
-> probe_<BIN>:<NAME>
- Give a pair of group and name on a userspace binary
perf probe -x <BIN> --add <GRP>:<NAME>=<PROBEDEF>
-> probe_<GRP>:<NAME>
- Set an sdt event on a userspace binary
perf probe -x <BIN> --add %<PROV>:<NAME> # or %sdt_<PROV> ?
-> sdt_<PROV>:<NAME>
- Set an cached event on a userspace binary
perf probe -x <BIN> --add %<GRP>:<NAME> # or %probe_<GRP> ?
-> probe_<GRP>:<NAME>
Thank you,
>
>>
>> Signed-off-by: Masami Hiramatsu <[email protected]>
>> ---
>> tools/perf/util/probe-event.c | 23 ++++++++++++++---------
>> 1 file changed, 14 insertions(+), 9 deletions(-)
>>
>> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
>> index 262f9d3..c19a380 100644
>> --- a/tools/perf/util/probe-event.c
>> +++ b/tools/perf/util/probe-event.c
>> @@ -1141,10 +1141,8 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
>> bool file_spec = false;
>> /*
>> * <Syntax>
>> - * perf probe [EVENT=]SRC[:LN|;PTN]
>> - * perf probe [EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
>> - *
>> - * TODO:Group name support
>> + * perf probe [GRP:][EVENT=]SRC[:LN|;PTN]
>
> Shouldn't it be
> [[GRP:]EVENT=]
>
> ?
>
>> + * perf probe [GRP:][EVENT=]FUNC[@SRC][+OFFS|%return|:LN|;PAT]
>
> Ditto.
>
> Thanks,
> Namhyung
>
>
>> */
>> if (!arg)
>> return -EINVAL;
>> @@ -1153,11 +1151,19 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
>> if (ptr && *ptr == '=') { /* Event name */
>> *ptr = '\0';
>> tmp = ptr + 1;
>> - if (strchr(arg, ':')) {
>> - semantic_error("Group name is not supported yet.\n");
>> - return -ENOTSUP;
>> - }
>> + ptr = strchr(arg, ':');
>> + if (ptr) {
>> + *ptr = '\0';
>> + if (!is_c_func_name(arg))
>> + goto not_fname;
>> + pev->group = strdup(arg);
>> + if (!pev->group)
>> + return -ENOMEM;
>> + arg = ptr + 1;
>> + } else
>> + pev->group = NULL;
>> if (!is_c_func_name(arg)) {
>> +not_fname:
>> semantic_error("%s is bad for event name -it must "
>> "follow C symbol-naming rule.\n", arg);
>> return -EINVAL;
>> @@ -1165,7 +1171,6 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
>> pev->event = strdup(arg);
>> if (pev->event == NULL)
>> return -ENOMEM;
>> - pev->group = NULL;
>> arg = tmp;
>> }
>>
>>
>>
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
G'Day Masami-san, Namhyung,
I'm really looking forward to this feature -- very useful, thanks!...
On Sat, Jul 18, 2015 at 9:24 PM, Namhyung Kim <[email protected]> wrote:
> Hi Masami,
>
> On Fri, Jul 17, 2015 at 12:21:42PM +0900, Masami Hiramatsu wrote:
>> Now I'm thinking that we should avoid using %event syntax for perf-list
>> and perf-record to avoid confusion. For example, suppose that we have
>> "libfoo:bar" SDT event, when we just scanned the libfoo binary and
>> use it via perf-record, we'll run perf record -e "%libfoo:bar".
>> However, after we set the probe via perf-probe, we have to run
>> perf record -e "libfoo:bar". That difference looks no good.
>> So, I think in both case it should accept -e "libfoo:bar" syntax.
>
> I don't remember how the SDT events should be shown to users. Sorry
> if I'm missing something here.
>
> AFAIK an SDT event consists of a provider and an event name. So it
> can be simply 'provider:event' like tracepoints or
> 'binary:provider_event' like uprobes.
>
> I like the former because it's simpler but it needs to guarantee that
> it doesn't clash with existing tracepoints/[ku]probes. So IIUC we
> chose the '%' sign to distinguish them. But after setting a probe at
> it, the group name should be the binary name. So the whole event name
> might be changed, and this is not good.
I don't think we should worry about the clash, as the provider name
should differentiate. So I think "libfoo:bar" with perf record is
better. After adding them to the cache (via % if needed), I'd think
they would be best looking like tracepoints. Eg, listing them together
they can be differentiated, something like:
# perf list
[...]
block:block_rq_abort [Tracepoint event]
block:block_rq_requeue [Tracepoint event]
block:block_rq_complete [Tracepoint event]
[...]
libc:memory_heap_new [User tracepoint event]
libc:memory_heap_free [User tracepoint event]
libc:memory_heap_more [User tracepoint event]
[...]
Then used the same.
Brendan
On Mon, Jul 20, 2015 at 01:48:36PM +0900, Masami Hiramatsu wrote:
> On 2015/07/19 19:16, Namhyung Kim wrote:
> > On Wed, Jul 15, 2015 at 06:15:30PM +0900, Masami Hiramatsu wrote:
> >> Allow user to set group name for adding new event.
> >> Note that this can easily shot yourself in the foot.
> >> E.g. Existing group name can conflict with other events.
> >> Especially, using the group name reserved for kernel
> >> modules can break something when loading/unloading
> >> modules.
> >
> > Yes, I agree that this can be dangerous. How about enforcing
> > [ku]probes to make the directory of dynamic events safely?
>
> What the safety issue would you afraid?
As you said, I worried that an arbitrary group/event names can clash
with another module's group/event names.
>
> > I think
> > it'd be better putting all dynamic events in a single directory -
> > e.g. $tracefs/events/probe/. Any events lack group name are created
> > in the directory. Any events have group name create subdirectories as
> > group name under the directory. The perf tools (and others too)
> > should be changed to lookup the directory after the usual location.
>
> That will be possible, but includes a big change on event namespace,
> e.g. how we'll show the events by perf-list? Even if we can avoid
> namespace conflict on tracefs, perf-list event namespace is still
> fragile.
Yes, it's a big change. And I think we can easily fix perf-list to
handle the new event namespace. But other tools/scripts will break.
>
> > What do you think?
>
> I think there are 2 purposes of probe-event, one is just additional
> debug points, another is an extensible event-set. The former will not
> any namespace problem, we just add it into new namespace. But latter
> requires to be treated as a part of existing (in-kernel) events.
> And (userspace)SDT is clearly the latter one.
>
> However, avoiding the conflict of namespace is also important, how
> about simply using sdt_<PROVIDER>:<NAME> ?
>
> - Give just a name on a userspace binary
> perf probe -x <BIN> --add <NAME>=<PROBEDEF>
> -> probe_<BIN>:<NAME>
> - Give a pair of group and name on a userspace binary
> perf probe -x <BIN> --add <GRP>:<NAME>=<PROBEDEF>
> -> probe_<GRP>:<NAME>
> - Set an sdt event on a userspace binary
> perf probe -x <BIN> --add %<PROV>:<NAME> # or %sdt_<PROV> ?
> -> sdt_<PROV>:<NAME>
> - Set an cached event on a userspace binary
> perf probe -x <BIN> --add %<GRP>:<NAME> # or %probe_<GRP> ?
> -> probe_<GRP>:<NAME>
I think this is good for perf. It seems same problem still exists
when users access tracefs directly though.
Thanks,
Namhyung
On Mon, Jul 20, 2015 at 12:19:14PM +0900, Masami Hiramatsu wrote:
> On 2015/07/19 19:46, Namhyung Kim wrote:
> > On Wed, Jul 15, 2015 at 06:15:37PM +0900, Masami Hiramatsu wrote:
> >> perf buildid-cache --add <binary> scans given binary and add
> >> the SDT events to probe cache. It is possible to use the cached
> >> SDT events as other cached events (perf probe <provider>:<event>=<event>).
> >
> > That means lookup the cached SDT events only using event name, right?
>
> Right,
>
> > What if same event names are used by more than one providers?
>
> That's a good discussion point :)
>
> What I'm thinking is that the real SDT is always prior to other
> cached events. (currently not implemented yet)
> - if someone gives a same event name, it overwrites previous one.
> - if someone gives an event name same as existing SDT, it is not
> cached (or rejected)
> - if SDT scanned after cached same name events, SDT always overwrites
> the entry.
I'm thinking about allowing same name for different events. IMHO it's
possible to have same SDT names for some reason - i.e. having multiple
versions of same program, similar (but different) binaries have same
event names, or even in a single bianry it might have same event names
but different provider names.
In that case, I think perf probe (or record) simply can do the job for
every matching events.
>
> So, the all SDT events will be treated as fixed events.
>
> Note that this will be happen if we agree SDT and probe share the
> same namespace :)
Right.
Thanks,
Namhyung
Hi Brendan,
On Sun, Jul 19, 2015 at 10:47:31PM -0700, Brendan Gregg wrote:
> G'Day Masami-san, Namhyung,
>
> I'm really looking forward to this feature -- very useful, thanks!...
>
> On Sat, Jul 18, 2015 at 9:24 PM, Namhyung Kim <[email protected]> wrote:
> > Hi Masami,
> >
> > On Fri, Jul 17, 2015 at 12:21:42PM +0900, Masami Hiramatsu wrote:
> >> Now I'm thinking that we should avoid using %event syntax for perf-list
> >> and perf-record to avoid confusion. For example, suppose that we have
> >> "libfoo:bar" SDT event, when we just scanned the libfoo binary and
> >> use it via perf-record, we'll run perf record -e "%libfoo:bar".
> >> However, after we set the probe via perf-probe, we have to run
> >> perf record -e "libfoo:bar". That difference looks no good.
> >> So, I think in both case it should accept -e "libfoo:bar" syntax.
> >
> > I don't remember how the SDT events should be shown to users. Sorry
> > if I'm missing something here.
> >
> > AFAIK an SDT event consists of a provider and an event name. So it
> > can be simply 'provider:event' like tracepoints or
> > 'binary:provider_event' like uprobes.
> >
> > I like the former because it's simpler but it needs to guarantee that
> > it doesn't clash with existing tracepoints/[ku]probes. So IIUC we
> > chose the '%' sign to distinguish them. But after setting a probe at
> > it, the group name should be the binary name. So the whole event name
> > might be changed, and this is not good.
>
> I don't think we should worry about the clash, as the provider name
> should differentiate.
But there's no guarantee. Maybe an userspace tool which deals with a
kernel module has SDT names as same as the kernel module's tracepoint
names. It might or might not be a problem if we can handle those
duplicate names somehow.
> So I think "libfoo:bar" with perf record is
> better. After adding them to the cache (via % if needed), I'd think
> they would be best looking like tracepoints. Eg, listing them together
> they can be differentiated, something like:
>
> # perf list
> [...]
> block:block_rq_abort [Tracepoint event]
> block:block_rq_requeue [Tracepoint event]
> block:block_rq_complete [Tracepoint event]
> [...]
> libc:memory_heap_new [User tracepoint event]
> libc:memory_heap_free [User tracepoint event]
> libc:memory_heap_more [User tracepoint event]
> [...]
>
> Then used the same.
Yes, as I said I also prefer this simpler form. Maybe we can choose
to use another names for low-level plumbing inside the perf tools, but
I still think that users should be able to use simple names like above.
Thanks,
Namhyung
Em Wed, Jul 15, 2015 at 06:13:53PM +0900, Masami Hiramatsu escreveu:
> Hi,
>
> Here is the 2nd version of the patchset for probe-cache and
> initial SDT support which are going to be perf-cache finally.
Applied the first three patches, after fixing up a trivial clash with
work I did in perf/core.
- Arnaldo
Em Mon, Jul 20, 2015 at 03:36:40PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Jul 15, 2015 at 06:13:53PM +0900, Masami Hiramatsu escreveu:
> > Hi,
> >
> > Here is the 2nd version of the patchset for probe-cache and
> > initial SDT support which are going to be perf-cache finally.
>
> Applied the first three patches, after fixing up a trivial clash with
The first two patches were applied, sorry.
> work I did in perf/core.
>
> - Arnaldo
Em Wed, Jul 15, 2015 at 06:14:28PM +0900, Masami Hiramatsu escreveu:
> Introduce SBUILD_ID_SIZE macro and use it instead of using
> BUILD_ID_SIZE * 2 + 1.
Applied.
- Arnaldo
Commit-ID: a3c9de6280b8d196ab89ca7fad143bfa2a949790
Gitweb: http://git.kernel.org/tip/a3c9de6280b8d196ab89ca7fad143bfa2a949790
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Wed, 15 Jul 2015 18:14:00 +0900
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 20 Jul 2015 17:49:49 -0300
perf probe: Simplify __add_probe_trace_events code
Simplify the __add_probe_trace_events() code by taking out the
probe_trace_event__set_name() and updating show_perf_probe_event()
Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Hemant Kumar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/probe-event.c | 70 ++++++++++++++++++++++++++-----------------
1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 7abaac4..54a91d7 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2478,16 +2478,54 @@ out:
free(buf);
}
+/* Set new name from original perf_probe_event and namelist */
+static int probe_trace_event__set_name(struct probe_trace_event *tev,
+ struct perf_probe_event *pev,
+ struct strlist *namelist,
+ bool allow_suffix)
+{
+ const char *event, *group;
+ char buf[64];
+ int ret;
+
+ if (pev->event)
+ event = pev->event;
+ else
+ if (pev->point.function && !strisglob(pev->point.function))
+ event = pev->point.function;
+ else
+ event = tev->point.realname;
+ if (pev->group)
+ group = pev->group;
+ else
+ group = PERFPROBE_GROUP;
+
+ /* Get an unused new event name */
+ ret = get_new_event_name(buf, 64, event,
+ namelist, allow_suffix);
+ if (ret < 0)
+ return ret;
+
+ event = buf;
+
+ tev->event = strdup(event);
+ tev->group = strdup(group);
+ if (tev->event == NULL || tev->group == NULL)
+ return -ENOMEM;
+
+ /* Add added event name to namelist */
+ strlist__add(namelist, event);
+ return 0;
+}
+
static int __add_probe_trace_events(struct perf_probe_event *pev,
struct probe_trace_event *tevs,
int ntevs, bool allow_suffix)
{
int i, fd, ret;
struct probe_trace_event *tev = NULL;
- char buf[64];
const char *event = NULL, *group = NULL;
struct strlist *namelist;
- bool safename;
if (pev->uprobes)
fd = open_uprobe_events(true);
@@ -2507,7 +2545,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
goto close_out;
}
- safename = (pev->point.function && !strisglob(pev->point.function));
ret = 0;
pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
for (i = 0; i < ntevs; i++) {
@@ -2516,36 +2553,15 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
if (!tev->point.symbol)
continue;
- if (pev->event)
- event = pev->event;
- else
- if (safename)
- event = pev->point.function;
- else
- event = tev->point.realname;
- if (pev->group)
- group = pev->group;
- else
- group = PERFPROBE_GROUP;
-
- /* Get an unused new event name */
- ret = get_new_event_name(buf, 64, event,
- namelist, allow_suffix);
+ /* Set new name for tev (and update namelist) */
+ ret = probe_trace_event__set_name(tev, pev, namelist,
+ allow_suffix);
if (ret < 0)
break;
- event = buf;
- tev->event = strdup(event);
- tev->group = strdup(group);
- if (tev->event == NULL || tev->group == NULL) {
- ret = -ENOMEM;
- break;
- }
ret = write_probe_trace_event(fd, tev);
if (ret < 0)
break;
- /* Add added event name to namelist */
- strlist__add(namelist, event);
/* We use tev's name for showing new events */
show_perf_probe_event(tev->group, tev->event, pev,
Commit-ID: 92f6c72e7ac40cbf8d12682d1aeeb82c905f2a64
Gitweb: http://git.kernel.org/tip/92f6c72e7ac40cbf8d12682d1aeeb82c905f2a64
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Wed, 15 Jul 2015 18:14:07 +0900
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 20 Jul 2015 17:49:49 -0300
perf probe: Move ftrace probe-event operations to probe-file.c
Move ftrace probe-event operations to probe-file.c from probe-event.c.
Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Hemant Kumar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
[ Fixed up strlist__new() calls wrt 4a77e2183fc0 ("perf strlist: Make dupstr be the...") ]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/Build | 1 +
tools/perf/util/probe-event.c | 318 ++++--------------------------------------
tools/perf/util/probe-event.h | 7 +
tools/perf/util/probe-file.c | 301 +++++++++++++++++++++++++++++++++++++++
tools/perf/util/probe-file.h | 18 +++
5 files changed, 353 insertions(+), 292 deletions(-)
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 601d114..8d1bdf8 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -79,6 +79,7 @@ libperf-$(CONFIG_AUXTRACE) += auxtrace.o
libperf-y += parse-branch-options.o
libperf-$(CONFIG_LIBELF) += symbol-elf.o
+libperf-$(CONFIG_LIBELF) += probe-file.o
libperf-$(CONFIG_LIBELF) += probe-event.o
ifndef CONFIG_LIBELF
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 54a91d7..fe4941a 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -45,6 +45,7 @@
#include "trace-event.h" /* For __maybe_unused */
#include "probe-event.h"
#include "probe-finder.h"
+#include "probe-file.h"
#include "session.h"
#define MAX_CMDLEN 256
@@ -55,11 +56,7 @@ struct probe_conf probe_conf;
#define semantic_error(msg ...) pr_err("Semantic error :" msg)
-/* If there is no space to write, returns -E2BIG. */
-static int e_snprintf(char *str, size_t size, const char *format, ...)
- __attribute__((format(printf, 3, 4)));
-
-static int e_snprintf(char *str, size_t size, const char *format, ...)
+int e_snprintf(char *str, size_t size, const char *format, ...)
{
int ret;
va_list ap;
@@ -72,7 +69,6 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
}
static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
-static void clear_probe_trace_event(struct probe_trace_event *tev);
static struct machine *host_machine;
/* Initialize symbol maps and path of vmlinux/modules */
@@ -1467,8 +1463,7 @@ bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
}
/* Parse probe_events event into struct probe_point */
-static int parse_probe_trace_command(const char *cmd,
- struct probe_trace_event *tev)
+int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
{
struct probe_trace_point *tp = &tev->point;
char pr;
@@ -1951,7 +1946,7 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
memset(pev, 0, sizeof(*pev));
}
-static void clear_probe_trace_event(struct probe_trace_event *tev)
+void clear_probe_trace_event(struct probe_trace_event *tev)
{
struct probe_trace_arg_ref *ref, *next;
int i;
@@ -1976,119 +1971,6 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
memset(tev, 0, sizeof(*tev));
}
-static void print_open_warning(int err, bool is_kprobe)
-{
- char sbuf[STRERR_BUFSIZE];
-
- if (err == -ENOENT) {
- const char *config;
-
- if (!is_kprobe)
- config = "CONFIG_UPROBE_EVENTS";
- else
- config = "CONFIG_KPROBE_EVENTS";
-
- pr_warning("%cprobe_events file does not exist"
- " - please rebuild kernel with %s.\n",
- is_kprobe ? 'k' : 'u', config);
- } else if (err == -ENOTSUP)
- pr_warning("Tracefs or debugfs is not mounted.\n");
- else
- pr_warning("Failed to open %cprobe_events: %s\n",
- is_kprobe ? 'k' : 'u',
- strerror_r(-err, sbuf, sizeof(sbuf)));
-}
-
-static void print_both_open_warning(int kerr, int uerr)
-{
- /* Both kprobes and uprobes are disabled, warn it. */
- if (kerr == -ENOTSUP && uerr == -ENOTSUP)
- pr_warning("Tracefs or debugfs is not mounted.\n");
- else if (kerr == -ENOENT && uerr == -ENOENT)
- pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
- "or/and CONFIG_UPROBE_EVENTS.\n");
- else {
- char sbuf[STRERR_BUFSIZE];
- pr_warning("Failed to open kprobe events: %s.\n",
- strerror_r(-kerr, sbuf, sizeof(sbuf)));
- pr_warning("Failed to open uprobe events: %s.\n",
- strerror_r(-uerr, sbuf, sizeof(sbuf)));
- }
-}
-
-static int open_probe_events(const char *trace_file, bool readwrite)
-{
- char buf[PATH_MAX];
- const char *__debugfs;
- const char *tracing_dir = "";
- int ret;
-
- __debugfs = tracefs_find_mountpoint();
- if (__debugfs == NULL) {
- tracing_dir = "tracing/";
-
- __debugfs = debugfs_find_mountpoint();
- if (__debugfs == NULL)
- return -ENOTSUP;
- }
-
- ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
- __debugfs, tracing_dir, trace_file);
- if (ret >= 0) {
- pr_debug("Opening %s write=%d\n", buf, readwrite);
- if (readwrite && !probe_event_dry_run)
- ret = open(buf, O_RDWR | O_APPEND, 0);
- else
- ret = open(buf, O_RDONLY, 0);
-
- if (ret < 0)
- ret = -errno;
- }
- return ret;
-}
-
-static int open_kprobe_events(bool readwrite)
-{
- return open_probe_events("kprobe_events", readwrite);
-}
-
-static int open_uprobe_events(bool readwrite)
-{
- return open_probe_events("uprobe_events", readwrite);
-}
-
-/* Get raw string list of current kprobe_events or uprobe_events */
-static struct strlist *get_probe_trace_command_rawlist(int fd)
-{
- int ret, idx;
- FILE *fp;
- char buf[MAX_CMDLEN];
- char *p;
- struct strlist *sl;
-
- sl = strlist__new(NULL, NULL);
-
- fp = fdopen(dup(fd), "r");
- while (!feof(fp)) {
- p = fgets(buf, MAX_CMDLEN, fp);
- if (!p)
- break;
-
- idx = strlen(p) - 1;
- if (p[idx] == '\n')
- p[idx] = '\0';
- ret = strlist__add(sl, buf);
- if (ret < 0) {
- pr_debug("strlist__add failed (%d)\n", ret);
- strlist__delete(sl);
- return NULL;
- }
- }
- fclose(fp);
-
- return sl;
-}
-
struct kprobe_blacklist_node {
struct list_head list;
unsigned long start;
@@ -2284,7 +2166,7 @@ static int __show_perf_probe_events(int fd, bool is_kprobe,
memset(&tev, 0, sizeof(tev));
memset(&pev, 0, sizeof(pev));
- rawlist = get_probe_trace_command_rawlist(fd);
+ rawlist = probe_file__get_rawlist(fd);
if (!rawlist)
return -ENOMEM;
@@ -2325,89 +2207,20 @@ int show_perf_probe_events(struct strfilter *filter)
if (ret < 0)
return ret;
- kp_fd = open_kprobe_events(false);
- if (kp_fd >= 0) {
- ret = __show_perf_probe_events(kp_fd, true, filter);
- close(kp_fd);
- if (ret < 0)
- goto out;
- }
-
- up_fd = open_uprobe_events(false);
- if (kp_fd < 0 && up_fd < 0) {
- print_both_open_warning(kp_fd, up_fd);
- ret = kp_fd;
- goto out;
- }
+ ret = probe_file__open_both(&kp_fd, &up_fd, 0);
+ if (ret < 0)
+ return ret;
- if (up_fd >= 0) {
+ if (kp_fd >= 0)
+ ret = __show_perf_probe_events(kp_fd, true, filter);
+ if (up_fd >= 0 && ret >= 0)
ret = __show_perf_probe_events(up_fd, false, filter);
+ if (kp_fd > 0)
+ close(kp_fd);
+ if (up_fd > 0)
close(up_fd);
- }
-out:
exit_symbol_maps();
- return ret;
-}
-/* Get current perf-probe event names */
-static struct strlist *get_probe_trace_event_names(int fd, bool include_group)
-{
- char buf[128];
- struct strlist *sl, *rawlist;
- struct str_node *ent;
- struct probe_trace_event tev;
- int ret = 0;
-
- memset(&tev, 0, sizeof(tev));
- rawlist = get_probe_trace_command_rawlist(fd);
- if (!rawlist)
- return NULL;
- sl = strlist__new(NULL, NULL);
- strlist__for_each(ent, rawlist) {
- ret = parse_probe_trace_command(ent->s, &tev);
- if (ret < 0)
- break;
- if (include_group) {
- ret = e_snprintf(buf, 128, "%s:%s", tev.group,
- tev.event);
- if (ret >= 0)
- ret = strlist__add(sl, buf);
- } else
- ret = strlist__add(sl, tev.event);
- clear_probe_trace_event(&tev);
- if (ret < 0)
- break;
- }
- strlist__delete(rawlist);
-
- if (ret < 0) {
- strlist__delete(sl);
- return NULL;
- }
- return sl;
-}
-
-static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
-{
- int ret = 0;
- char *buf = synthesize_probe_trace_command(tev);
- char sbuf[STRERR_BUFSIZE];
-
- if (!buf) {
- pr_debug("Failed to synthesize probe trace event.\n");
- return -EINVAL;
- }
-
- pr_debug("Writing event: %s\n", buf);
- if (!probe_event_dry_run) {
- ret = write(fd, buf, strlen(buf));
- if (ret <= 0) {
- ret = -errno;
- pr_warning("Failed to write event: %s\n",
- strerror_r(errno, sbuf, sizeof(sbuf)));
- }
- }
- free(buf);
return ret;
}
@@ -2527,18 +2340,12 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
const char *event = NULL, *group = NULL;
struct strlist *namelist;
- if (pev->uprobes)
- fd = open_uprobe_events(true);
- else
- fd = open_kprobe_events(true);
-
- if (fd < 0) {
- print_open_warning(fd, !pev->uprobes);
+ fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));
+ if (fd < 0)
return fd;
- }
/* Get current event names */
- namelist = get_probe_trace_event_names(fd, false);
+ namelist = probe_file__get_namelist(fd);
if (!namelist) {
pr_debug("Failed to get current event list.\n");
ret = -ENOMEM;
@@ -2559,7 +2366,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
if (ret < 0)
break;
- ret = write_probe_trace_event(fd, tev);
+ ret = probe_file__add_event(fd, tev);
if (ret < 0)
break;
@@ -2854,68 +2661,9 @@ end:
return ret;
}
-static int __del_trace_probe_event(int fd, struct str_node *ent)
-{
- char *p;
- char buf[128];
- int ret;
-
- /* Convert from perf-probe event to trace-probe event */
- ret = e_snprintf(buf, 128, "-:%s", ent->s);
- if (ret < 0)
- goto error;
-
- p = strchr(buf + 2, ':');
- if (!p) {
- pr_debug("Internal error: %s should have ':' but not.\n",
- ent->s);
- ret = -ENOTSUP;
- goto error;
- }
- *p = '/';
-
- pr_debug("Writing event: %s\n", buf);
- ret = write(fd, buf, strlen(buf));
- if (ret < 0) {
- ret = -errno;
- goto error;
- }
-
- pr_info("Removed event: %s\n", ent->s);
- return 0;
-error:
- pr_warning("Failed to delete event: %s\n",
- strerror_r(-ret, buf, sizeof(buf)));
- return ret;
-}
-
-static int del_trace_probe_events(int fd, struct strfilter *filter,
- struct strlist *namelist)
-{
- struct str_node *ent;
- const char *p;
- int ret = -ENOENT;
-
- if (!namelist)
- return -ENOENT;
-
- strlist__for_each(ent, namelist) {
- p = strchr(ent->s, ':');
- if ((p && strfilter__compare(filter, p + 1)) ||
- strfilter__compare(filter, ent->s)) {
- ret = __del_trace_probe_event(fd, ent);
- if (ret < 0)
- break;
- }
- }
-
- return ret;
-}
-
int del_perf_probe_events(struct strfilter *filter)
{
int ret, ret2, ufd = -1, kfd = -1;
- struct strlist *namelist = NULL, *unamelist = NULL;
char *str = strfilter__string(filter);
if (!str)
@@ -2924,25 +2672,15 @@ int del_perf_probe_events(struct strfilter *filter)
pr_debug("Delete filter: \'%s\'\n", str);
/* Get current event names */
- kfd = open_kprobe_events(true);
- if (kfd >= 0)
- namelist = get_probe_trace_event_names(kfd, true);
-
- ufd = open_uprobe_events(true);
- if (ufd >= 0)
- unamelist = get_probe_trace_event_names(ufd, true);
-
- if (kfd < 0 && ufd < 0) {
- print_both_open_warning(kfd, ufd);
- ret = kfd;
- goto error;
- }
+ ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);
+ if (ret < 0)
+ goto out;
- ret = del_trace_probe_events(kfd, filter, namelist);
+ ret = probe_file__del_events(kfd, filter);
if (ret < 0 && ret != -ENOENT)
goto error;
- ret2 = del_trace_probe_events(ufd, filter, unamelist);
+ ret2 = probe_file__del_events(ufd, filter);
if (ret2 < 0 && ret2 != -ENOENT) {
ret = ret2;
goto error;
@@ -2953,15 +2691,11 @@ int del_perf_probe_events(struct strfilter *filter)
ret = 0;
error:
- if (kfd >= 0) {
- strlist__delete(namelist);
+ if (kfd >= 0)
close(kfd);
- }
-
- if (ufd >= 0) {
- strlist__delete(unamelist);
+ if (ufd >= 0)
close(ufd);
- }
+out:
free(str);
return ret;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 31db6ee..20f555d 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -109,6 +109,8 @@ struct variable_list {
/* Command string to events */
extern int parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev);
+extern int parse_probe_trace_command(const char *cmd,
+ struct probe_trace_event *tev);
/* Events to command string */
extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
@@ -121,6 +123,7 @@ extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
/* Release event contents */
extern void clear_perf_probe_event(struct perf_probe_event *pev);
+extern void clear_probe_trace_event(struct probe_trace_event *tev);
/* Command string to line-range */
extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
@@ -144,6 +147,10 @@ bool arch__prefers_symtab(void);
void arch__fix_tev_from_maps(struct perf_probe_event *pev,
struct probe_trace_event *tev, struct map *map);
+/* If there is no space to write, returns -E2BIG. */
+int e_snprintf(char *str, size_t size, const char *format, ...)
+ __attribute__((format(printf, 3, 4)));
+
/* Maximum index number of event-name postfix */
#define MAX_EVENT_INDEX 1024
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
new file mode 100644
index 0000000..bbb2437
--- /dev/null
+++ b/tools/perf/util/probe-file.c
@@ -0,0 +1,301 @@
+/*
+ * probe-file.c : operate ftrace k/uprobe events files
+ *
+ * Written by Masami Hiramatsu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include "util.h"
+#include "event.h"
+#include "strlist.h"
+#include "debug.h"
+#include "cache.h"
+#include "color.h"
+#include "symbol.h"
+#include "thread.h"
+#include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
+#include "probe-event.h"
+#include "probe-file.h"
+#include "session.h"
+
+#define MAX_CMDLEN 256
+
+static void print_open_warning(int err, bool uprobe)
+{
+ char sbuf[STRERR_BUFSIZE];
+
+ if (err == -ENOENT) {
+ const char *config;
+
+ if (uprobe)
+ config = "CONFIG_UPROBE_EVENTS";
+ else
+ config = "CONFIG_KPROBE_EVENTS";
+
+ pr_warning("%cprobe_events file does not exist"
+ " - please rebuild kernel with %s.\n",
+ uprobe ? 'u' : 'k', config);
+ } else if (err == -ENOTSUP)
+ pr_warning("Tracefs or debugfs is not mounted.\n");
+ else
+ pr_warning("Failed to open %cprobe_events: %s\n",
+ uprobe ? 'u' : 'k',
+ strerror_r(-err, sbuf, sizeof(sbuf)));
+}
+
+static void print_both_open_warning(int kerr, int uerr)
+{
+ /* Both kprobes and uprobes are disabled, warn it. */
+ if (kerr == -ENOTSUP && uerr == -ENOTSUP)
+ pr_warning("Tracefs or debugfs is not mounted.\n");
+ else if (kerr == -ENOENT && uerr == -ENOENT)
+ pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
+ "or/and CONFIG_UPROBE_EVENTS.\n");
+ else {
+ char sbuf[STRERR_BUFSIZE];
+ pr_warning("Failed to open kprobe events: %s.\n",
+ strerror_r(-kerr, sbuf, sizeof(sbuf)));
+ pr_warning("Failed to open uprobe events: %s.\n",
+ strerror_r(-uerr, sbuf, sizeof(sbuf)));
+ }
+}
+
+static int open_probe_events(const char *trace_file, bool readwrite)
+{
+ char buf[PATH_MAX];
+ const char *__debugfs;
+ const char *tracing_dir = "";
+ int ret;
+
+ __debugfs = tracefs_find_mountpoint();
+ if (__debugfs == NULL) {
+ tracing_dir = "tracing/";
+
+ __debugfs = debugfs_find_mountpoint();
+ if (__debugfs == NULL)
+ return -ENOTSUP;
+ }
+
+ ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
+ __debugfs, tracing_dir, trace_file);
+ if (ret >= 0) {
+ pr_debug("Opening %s write=%d\n", buf, readwrite);
+ if (readwrite && !probe_event_dry_run)
+ ret = open(buf, O_RDWR | O_APPEND, 0);
+ else
+ ret = open(buf, O_RDONLY, 0);
+
+ if (ret < 0)
+ ret = -errno;
+ }
+ return ret;
+}
+
+static int open_kprobe_events(bool readwrite)
+{
+ return open_probe_events("kprobe_events", readwrite);
+}
+
+static int open_uprobe_events(bool readwrite)
+{
+ return open_probe_events("uprobe_events", readwrite);
+}
+
+int probe_file__open(int flag)
+{
+ int fd;
+
+ if (flag & PF_FL_UPROBE)
+ fd = open_uprobe_events(flag & PF_FL_RW);
+ else
+ fd = open_kprobe_events(flag & PF_FL_RW);
+ if (fd < 0)
+ print_open_warning(fd, flag & PF_FL_UPROBE);
+
+ return fd;
+}
+
+int probe_file__open_both(int *kfd, int *ufd, int flag)
+{
+ if (!kfd || !ufd)
+ return -EINVAL;
+
+ *kfd = open_kprobe_events(flag & PF_FL_RW);
+ *ufd = open_uprobe_events(flag & PF_FL_RW);
+ if (*kfd < 0 && *ufd < 0) {
+ print_both_open_warning(*kfd, *ufd);
+ return *kfd;
+ }
+
+ return 0;
+}
+
+/* Get raw string list of current kprobe_events or uprobe_events */
+struct strlist *probe_file__get_rawlist(int fd)
+{
+ int ret, idx;
+ FILE *fp;
+ char buf[MAX_CMDLEN];
+ char *p;
+ struct strlist *sl;
+
+ sl = strlist__new(NULL, NULL);
+
+ fp = fdopen(dup(fd), "r");
+ while (!feof(fp)) {
+ p = fgets(buf, MAX_CMDLEN, fp);
+ if (!p)
+ break;
+
+ idx = strlen(p) - 1;
+ if (p[idx] == '\n')
+ p[idx] = '\0';
+ ret = strlist__add(sl, buf);
+ if (ret < 0) {
+ pr_debug("strlist__add failed (%d)\n", ret);
+ strlist__delete(sl);
+ return NULL;
+ }
+ }
+ fclose(fp);
+
+ return sl;
+}
+
+static struct strlist *__probe_file__get_namelist(int fd, bool include_group)
+{
+ char buf[128];
+ struct strlist *sl, *rawlist;
+ struct str_node *ent;
+ struct probe_trace_event tev;
+ int ret = 0;
+
+ memset(&tev, 0, sizeof(tev));
+ rawlist = probe_file__get_rawlist(fd);
+ if (!rawlist)
+ return NULL;
+ sl = strlist__new(NULL, NULL);
+ strlist__for_each(ent, rawlist) {
+ ret = parse_probe_trace_command(ent->s, &tev);
+ if (ret < 0)
+ break;
+ if (include_group) {
+ ret = e_snprintf(buf, 128, "%s:%s", tev.group,
+ tev.event);
+ if (ret >= 0)
+ ret = strlist__add(sl, buf);
+ } else
+ ret = strlist__add(sl, tev.event);
+ clear_probe_trace_event(&tev);
+ if (ret < 0)
+ break;
+ }
+ strlist__delete(rawlist);
+
+ if (ret < 0) {
+ strlist__delete(sl);
+ return NULL;
+ }
+ return sl;
+}
+
+/* Get current perf-probe event names */
+struct strlist *probe_file__get_namelist(int fd)
+{
+ return __probe_file__get_namelist(fd, false);
+}
+
+int probe_file__add_event(int fd, struct probe_trace_event *tev)
+{
+ int ret = 0;
+ char *buf = synthesize_probe_trace_command(tev);
+ char sbuf[STRERR_BUFSIZE];
+
+ if (!buf) {
+ pr_debug("Failed to synthesize probe trace event.\n");
+ return -EINVAL;
+ }
+
+ pr_debug("Writing event: %s\n", buf);
+ if (!probe_event_dry_run) {
+ ret = write(fd, buf, strlen(buf));
+ if (ret <= 0) {
+ ret = -errno;
+ pr_warning("Failed to write event: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
+ }
+ }
+ free(buf);
+
+ return ret;
+}
+
+static int __del_trace_probe_event(int fd, struct str_node *ent)
+{
+ char *p;
+ char buf[128];
+ int ret;
+
+ /* Convert from perf-probe event to trace-probe event */
+ ret = e_snprintf(buf, 128, "-:%s", ent->s);
+ if (ret < 0)
+ goto error;
+
+ p = strchr(buf + 2, ':');
+ if (!p) {
+ pr_debug("Internal error: %s should have ':' but not.\n",
+ ent->s);
+ ret = -ENOTSUP;
+ goto error;
+ }
+ *p = '/';
+
+ pr_debug("Writing event: %s\n", buf);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ ret = -errno;
+ goto error;
+ }
+
+ pr_info("Removed event: %s\n", ent->s);
+ return 0;
+error:
+ pr_warning("Failed to delete event: %s\n",
+ strerror_r(-ret, buf, sizeof(buf)));
+ return ret;
+}
+
+int probe_file__del_events(int fd, struct strfilter *filter)
+{
+ struct strlist *namelist;
+ struct str_node *ent;
+ const char *p;
+ int ret = -ENOENT;
+
+ namelist = __probe_file__get_namelist(fd, true);
+ if (!namelist)
+ return -ENOENT;
+
+ strlist__for_each(ent, namelist) {
+ p = strchr(ent->s, ':');
+ if ((p && strfilter__compare(filter, p + 1)) ||
+ strfilter__compare(filter, ent->s)) {
+ ret = __del_trace_probe_event(fd, ent);
+ if (ret < 0)
+ break;
+ }
+ }
+ strlist__delete(namelist);
+
+ return ret;
+}
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
new file mode 100644
index 0000000..ada94a2
--- /dev/null
+++ b/tools/perf/util/probe-file.h
@@ -0,0 +1,18 @@
+#ifndef __PROBE_FILE_H
+#define __PROBE_FILE_H
+
+#include "strlist.h"
+#include "strfilter.h"
+#include "probe-event.h"
+
+#define PF_FL_UPROBE 1
+#define PF_FL_RW 2
+
+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);
+struct strlist *probe_file__get_rawlist(int fd);
+int probe_file__add_event(int fd, struct probe_trace_event *tev);
+int probe_file__del_events(int fd, struct strfilter *filter);
+
+#endif
Commit-ID: d77fac7f9e687d137b17296d86d9143c2cccab6a
Gitweb: http://git.kernel.org/tip/d77fac7f9e687d137b17296d86d9143c2cccab6a
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Wed, 15 Jul 2015 18:14:28 +0900
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 20 Jul 2015 17:49:50 -0300
perf buildid: Use SBUILD_ID_SIZE macro
Introduce SBUILD_ID_SIZE macro and use it instead of using BUILD_ID_SIZE
* 2 + 1.
Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Hemant Kumar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-buildid-cache.c | 8 ++++----
tools/perf/builtin-buildid-list.c | 4 ++--
tools/perf/util/build-id.c | 4 ++--
tools/perf/util/build-id.h | 3 ++-
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index ddca990..65b4835 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -127,7 +127,7 @@ static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
static int build_id_cache__add_kcore(const char *filename, bool force)
{
- char dir[32], sbuildid[BUILD_ID_SIZE * 2 + 1];
+ char dir[32], sbuildid[SBUILD_ID_SIZE];
char from_dir[PATH_MAX], to_dir[PATH_MAX];
char *p;
@@ -184,7 +184,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
static int build_id_cache__add_file(const char *filename)
{
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
u8 build_id[BUILD_ID_SIZE];
int err;
@@ -204,7 +204,7 @@ static int build_id_cache__add_file(const char *filename)
static int build_id_cache__remove_file(const char *filename)
{
u8 build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
int err;
@@ -276,7 +276,7 @@ static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *f
static int build_id_cache__update_file(const char *filename)
{
u8 build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
int err = 0;
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 9fe93c8..b5ca988 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -20,7 +20,7 @@
static int sysfs__fprintf_build_id(FILE *fp)
{
u8 kallsyms_build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
sizeof(kallsyms_build_id)) != 0)
@@ -35,7 +35,7 @@ static int sysfs__fprintf_build_id(FILE *fp)
static int filename__fprintf_build_id(const char *name, FILE *fp)
{
u8 build_id[BUILD_ID_SIZE];
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
if (filename__read_build_id(name, build_id,
sizeof(build_id)) != sizeof(build_id))
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index f98c2ff..4a2c2f0 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -124,7 +124,7 @@ static char *build_id__filename(const char *sbuild_id, char *bf, size_t size)
char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size)
{
- char build_id_hex[BUILD_ID_SIZE * 2 + 1];
+ char build_id_hex[SBUILD_ID_SIZE];
if (!dso->has_build_id)
return NULL;
@@ -384,7 +384,7 @@ static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
const char *name, bool is_kallsyms,
bool is_vdso)
{
- char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+ char sbuild_id[SBUILD_ID_SIZE];
build_id__sprintf(build_id, build_id_size, sbuild_id);
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 8501122..ce2f493 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -1,7 +1,8 @@
#ifndef PERF_BUILD_ID_H_
#define PERF_BUILD_ID_H_ 1
-#define BUILD_ID_SIZE 20
+#define BUILD_ID_SIZE 20
+#define SBUILD_ID_SIZE (BUILD_ID_SIZE * 2 + 1)
#include "tool.h"
#include "strlist.h"
On 2015/07/21 1:20, Namhyung Kim wrote:
> Hi Brendan,
>
> On Sun, Jul 19, 2015 at 10:47:31PM -0700, Brendan Gregg wrote:
>> G'Day Masami-san, Namhyung,
>>
>> I'm really looking forward to this feature -- very useful, thanks!...
>>
>> On Sat, Jul 18, 2015 at 9:24 PM, Namhyung Kim <[email protected]> wrote:
>>> Hi Masami,
>>>
>>> On Fri, Jul 17, 2015 at 12:21:42PM +0900, Masami Hiramatsu wrote:
>>>> Now I'm thinking that we should avoid using %event syntax for perf-list
>>>> and perf-record to avoid confusion. For example, suppose that we have
>>>> "libfoo:bar" SDT event, when we just scanned the libfoo binary and
>>>> use it via perf-record, we'll run perf record -e "%libfoo:bar".
>>>> However, after we set the probe via perf-probe, we have to run
>>>> perf record -e "libfoo:bar". That difference looks no good.
>>>> So, I think in both case it should accept -e "libfoo:bar" syntax.
>>>
>>> I don't remember how the SDT events should be shown to users. Sorry
>>> if I'm missing something here.
>>>
>>> AFAIK an SDT event consists of a provider and an event name. So it
>>> can be simply 'provider:event' like tracepoints or
>>> 'binary:provider_event' like uprobes.
>>>
>>> I like the former because it's simpler but it needs to guarantee that
>>> it doesn't clash with existing tracepoints/[ku]probes. So IIUC we
>>> chose the '%' sign to distinguish them. But after setting a probe at
>>> it, the group name should be the binary name. So the whole event name
>>> might be changed, and this is not good.
>>
>> I don't think we should worry about the clash, as the provider name
>> should differentiate.
>
> But there's no guarantee. Maybe an userspace tool which deals with a
> kernel module has SDT names as same as the kernel module's tracepoint
> names. It might or might not be a problem if we can handle those
> duplicate names somehow.
I'd like to suggest to choose the behavior on scanning SDT. Since the
perf-probe just relays on what the event names are stored on the cache file,
we can choose "sdt_" prefix or not when scanning the SDT.
If the name is already used by the kernel tracepoint, we can add sdt_ prefix
or some sort of suffix.
Thank you,
>> So I think "libfoo:bar" with perf record is
>> better. After adding them to the cache (via % if needed), I'd think
>> they would be best looking like tracepoints. Eg, listing them together
>> they can be differentiated, something like:
>>
>> # perf list
>> [...]
>> block:block_rq_abort [Tracepoint event]
>> block:block_rq_requeue [Tracepoint event]
>> block:block_rq_complete [Tracepoint event]
>> [...]
>> libc:memory_heap_new [User tracepoint event]
>> libc:memory_heap_free [User tracepoint event]
>> libc:memory_heap_more [User tracepoint event]
>> [...]
>>
>> Then used the same.
>
> Yes, as I said I also prefer this simpler form. Maybe we can choose
> to use another names for low-level plumbing inside the perf tools, but
> I still think that users should be able to use simple names like above.
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
On 2015/07/21 0:52, Namhyung Kim wrote:
> On Mon, Jul 20, 2015 at 12:19:14PM +0900, Masami Hiramatsu wrote:
>> On 2015/07/19 19:46, Namhyung Kim wrote:
>>> On Wed, Jul 15, 2015 at 06:15:37PM +0900, Masami Hiramatsu wrote:
>>>> perf buildid-cache --add <binary> scans given binary and add
>>>> the SDT events to probe cache. It is possible to use the cached
>>>> SDT events as other cached events (perf probe <provider>:<event>=<event>).
>>>
>>> That means lookup the cached SDT events only using event name, right?
>>
>> Right,
>>
>>> What if same event names are used by more than one providers?
>>
>> That's a good discussion point :)
>>
>> What I'm thinking is that the real SDT is always prior to other
>> cached events. (currently not implemented yet)
>> - if someone gives a same event name, it overwrites previous one.
>> - if someone gives an event name same as existing SDT, it is not
>> cached (or rejected)
>> - if SDT scanned after cached same name events, SDT always overwrites
>> the entry.
>
> I'm thinking about allowing same name for different events. IMHO it's
> possible to have same SDT names for some reason - i.e. having multiple
> versions of same program, similar (but different) binaries have same
> event names, or even in a single bianry it might have same event names
> but different provider names.
>
> In that case, I think perf probe (or record) simply can do the job for
> every matching events.
Hmm, right. If we support the 3-level event name as you said, that
can make things much simpler. We can use "probe_<12chars-buildid>"
for the toplevel dirname, and "provider/name" for lower 2 levels.
Or, if we can use <provider>.<buildid>/ for the group name (this requres
kernel change) it is more easier to support SDTs.
Thank you,
>
>>
>> So, the all SDT events will be treated as fixed events.
>>
>> Note that this will be happen if we agree SDT and probe share the
>> same namespace :)
>
> Right.
>
> Thanks,
> Namhyung
>
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Hi Masami,
Apologies for the delayed response.
On 07/17/2015 08:51 AM, Masami Hiramatsu wrote:
> Hi Hemant,
>
> On 2015/07/16 12:13, Hemant Kumar wrote:
>> Hi Masami,
>>
>> On 07/15/2015 02:43 PM, Masami Hiramatsu wrote:
>>> Hi,
>>>
>>> Here is the 2nd version of the patchset for probe-cache and
>>> initial SDT support which are going to be perf-cache finally.
>> Thanks for adding the SDT support.
>>
>>> The perf-probe is useful for debugging, but it strongly depends
>>> on the debuginfo. Without debuginfo, it is just a frontend of
>>> ftrace's dynamic events. This can usually happen in server
>>> farms or on cloud system, since no one wants to distribute
>>> big debuginfo packages.
>>>
>>> To solve this issue, I had tried to make a pre-analyzed probes
>>> ( https://lkml.org/lkml/2014/10/31/207 ) but it has a problm
>>> that we can't ensure the probed binary is same as what we analyzed.
>>> Arnaldo gave me an idea to reuse build-id cache for that perpose
>>> and this series is the first prototype of that.
>>>
>>> At the same time, Hemant has started to support SDT probes which
>>> also use the cache file of SDT info. So I decided to merge this
>>> into the same build-id cache.
>>> In this version, SDT support is still very limited, it works
>>> as a part of probe-cache.
>>>
>>> In this version, perf probe supports --cache option which means
>>> that perf probe manipulate probe caches, for example,
>>>
>>> # perf probe --cache --add "probe-desc"
>>>
>>> does not only add probe events but also add "probe-desc" and
>>> it's result on the cache. (Note that the cached entry is always
>>> referred even without --cache)
>>> The --list and --del commands also support --cache. Note that
>>> both are only manipulate caches, not real events.
>>>
>>> To use SDT, we have to scan the target binary at first by using
>>> perf-buildid-cache, e.g.
>>>
>>> # perf buildid-cache --add /lib/libc-2.17.so
>>>
>>> And perf probe --cache --list shows what SDTs are scanned.
>>>
>>> # perf probe --cache --list
>>> /usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
>>> libc:setjmp=setjmp
>>> libc:longjmp=longjmp
>>> libc:longjmp_target=longjmp_target
>>> libc:memory_heap_new=memory_heap_new
>>> libc:memory_sbrk_less=memory_sbrk_less
>>> libc:memory_arena_reuse_free_list=memory_arena_reuse_free_list
>>> libc:memory_arena_reuse=memory_arena_reuse
>>> ...
>>>
>>> To use the SDT events, perf probe -x BIN %SDTEVENT allows you to
>>> add a probe on SDTEVENT@BIN.
>>>
>>> # perf probe -x /lib/libc-2.17.so %memory_heap_new
>>>
>>> If you define a cached probe with event name, you can also reuse
>>> it as same as SDT events.
>>>
>>> # perf probe -x ./perf --cache -n 'myevent=dso__load $params'
>>>
>>> (Note that "-n" option only updates caches)
>>> To use the above "myevent", you just have to add "%myevent".
>>>
>>> # perf probe -x ./perf %myevent
>>>
>>>
>>> TODOs:
>>> - Show available cached/SDT events by perf-list
>>> - Allow perf-record to use cached/SDT events directly
>> As I was already working on SDT events' recording
>> https://lkml.org/lkml/2014/11/2/73,
>> I can re-spin the patches on top of your patchset and make the
>> required changes to implement the above TODOs.
> Sounds great! :)
> Note that you'll need to re-implement almost from scratch, since
> now the SDT is implemented on buildid-cache. Maybe I have to work
> on the buildid-cache one more to filter out binaries which are gone
> or different version from current running one (e.g. old vmlinux).
> It could help you to get available SDTs when showing it via perf-list.
Sure. That would be great.
>> What would you suggest?
> Now I'm thinking that we should avoid using %event syntax for perf-list
> and perf-record to avoid confusion. For example, suppose that we have
> "libfoo:bar" SDT event, when we just scanned the libfoo binary and
> use it via perf-record, we'll run perf record -e "%libfoo:bar".
> However, after we set the probe via perf-probe, we have to run
> perf record -e "libfoo:bar". That difference looks no good.
> So, I think in both case it should accept -e "libfoo:bar" syntax.
Although I agree to have "perf record" as a higher level tool and not bother
this tool to distinguish between its events, but that way we end up looking
into kprobe_events, uprobe_events, kernel tracepoints and then the entire
cache for any event (which may or may not be an SDT event or even a valid
event) lookup. Right?
The idea behind '%' was to identify the SDT events and take a different path
to lookup through the cache, put a probe, record and then delete the probe.
Or, do you want "perf record" to record any event this way (not just an sdt
event).
Please correct me if I missed something.
> In this series I've introduced %event syntax only to recall cached event
> setting explicitly, because perf-probe is a lower layer tool to set up
> new event. IMO, perf-list and perf-record should be higher tools which
> handle abstract events.
>
> Thanks!
>
>
--
Thanks,
Hemant Kumar
On 2015/07/22 23:12, Hemant Kumar wrote:
> Hi Masami,
>
> Apologies for the delayed response.
>
> On 07/17/2015 08:51 AM, Masami Hiramatsu wrote:
>> Hi Hemant,
>>
>> On 2015/07/16 12:13, Hemant Kumar wrote:
>>> Hi Masami,
>>>
>>> On 07/15/2015 02:43 PM, Masami Hiramatsu wrote:
>>>> Hi,
>>>>
>>>> Here is the 2nd version of the patchset for probe-cache and
>>>> initial SDT support which are going to be perf-cache finally.
>>> Thanks for adding the SDT support.
>>>
>>>> The perf-probe is useful for debugging, but it strongly depends
>>>> on the debuginfo. Without debuginfo, it is just a frontend of
>>>> ftrace's dynamic events. This can usually happen in server
>>>> farms or on cloud system, since no one wants to distribute
>>>> big debuginfo packages.
>>>>
>>>> To solve this issue, I had tried to make a pre-analyzed probes
>>>> ( https://lkml.org/lkml/2014/10/31/207 ) but it has a problm
>>>> that we can't ensure the probed binary is same as what we analyzed.
>>>> Arnaldo gave me an idea to reuse build-id cache for that perpose
>>>> and this series is the first prototype of that.
>>>>
>>>> At the same time, Hemant has started to support SDT probes which
>>>> also use the cache file of SDT info. So I decided to merge this
>>>> into the same build-id cache.
>>>> In this version, SDT support is still very limited, it works
>>>> as a part of probe-cache.
>>>>
>>>> In this version, perf probe supports --cache option which means
>>>> that perf probe manipulate probe caches, for example,
>>>>
>>>> # perf probe --cache --add "probe-desc"
>>>>
>>>> does not only add probe events but also add "probe-desc" and
>>>> it's result on the cache. (Note that the cached entry is always
>>>> referred even without --cache)
>>>> The --list and --del commands also support --cache. Note that
>>>> both are only manipulate caches, not real events.
>>>>
>>>> To use SDT, we have to scan the target binary at first by using
>>>> perf-buildid-cache, e.g.
>>>>
>>>> # perf buildid-cache --add /lib/libc-2.17.so
>>>>
>>>> And perf probe --cache --list shows what SDTs are scanned.
>>>>
>>>> # perf probe --cache --list
>>>> /usr/lib/libc-2.17.so (a6fb821bdf53660eb2c29f778757aef294d3d392):
>>>> libc:setjmp=setjmp
>>>> libc:longjmp=longjmp
>>>> libc:longjmp_target=longjmp_target
>>>> libc:memory_heap_new=memory_heap_new
>>>> libc:memory_sbrk_less=memory_sbrk_less
>>>> libc:memory_arena_reuse_free_list=memory_arena_reuse_free_list
>>>> libc:memory_arena_reuse=memory_arena_reuse
>>>> ...
>>>>
>>>> To use the SDT events, perf probe -x BIN %SDTEVENT allows you to
>>>> add a probe on SDTEVENT@BIN.
>>>>
>>>> # perf probe -x /lib/libc-2.17.so %memory_heap_new
>>>>
>>>> If you define a cached probe with event name, you can also reuse
>>>> it as same as SDT events.
>>>>
>>>> # perf probe -x ./perf --cache -n 'myevent=dso__load $params'
>>>>
>>>> (Note that "-n" option only updates caches)
>>>> To use the above "myevent", you just have to add "%myevent".
>>>>
>>>> # perf probe -x ./perf %myevent
>>>>
>>>>
>>>> TODOs:
>>>> - Show available cached/SDT events by perf-list
>>>> - Allow perf-record to use cached/SDT events directly
>>> As I was already working on SDT events' recording
>>> https://lkml.org/lkml/2014/11/2/73,
>>> I can re-spin the patches on top of your patchset and make the
>>> required changes to implement the above TODOs.
>> Sounds great! :)
>> Note that you'll need to re-implement almost from scratch, since
>> now the SDT is implemented on buildid-cache. Maybe I have to work
>> on the buildid-cache one more to filter out binaries which are gone
>> or different version from current running one (e.g. old vmlinux).
>> It could help you to get available SDTs when showing it via perf-list.
>
> Sure. That would be great.
>
>>> What would you suggest?
>> Now I'm thinking that we should avoid using %event syntax for perf-list
>> and perf-record to avoid confusion. For example, suppose that we have
>> "libfoo:bar" SDT event, when we just scanned the libfoo binary and
>> use it via perf-record, we'll run perf record -e "%libfoo:bar".
>> However, after we set the probe via perf-probe, we have to run
>> perf record -e "libfoo:bar". That difference looks no good.
>> So, I think in both case it should accept -e "libfoo:bar" syntax.
>
> Although I agree to have "perf record" as a higher level tool and not bother
> this tool to distinguish between its events, but that way we end up looking
> into kprobe_events, uprobe_events, kernel tracepoints and then the entire
> cache for any event (which may or may not be an SDT event or even a valid
> event) lookup. Right?
Yeah, right.
>
> The idea behind '%' was to identify the SDT events and take a different path
> to lookup through the cache, put a probe, record and then delete the probe.
> Or, do you want "perf record" to record any event this way (not just an sdt
> event).
I see, but I think that is not good by following reasons,
- when we record event with "-e %provider:event", it will be shown as
"provider:event"
- if perf-list shows the SDT(cached) events as "%provider:event", that
will not match the recorded result.
- it is somewhat fragile that we temporary add the SDT event and remove it
after record, because the event will not hide from ftrace users (this
means that we'll fail removing the event by -EBUSY if someone use it
via ftrace)
- if we set SDT events perf-probe, it will be shown as "provider:event" name
because "%" will be rejected by ftrace. In that case, what the perf-list show
those events, both of %provider:event and provider:event ?
thus I pushed the "%" as a "special remembering mark" only for looking
up the event from cache by perf-probe.
So I'd like to suggest that the following behavior
1) perf-list shows the cached-with-name and SDT events as Tracepoint events
even if it is not yet probed.
# perf list
List of pre-defined events (to be used in -e):
...
libc:memory_heap_new [Tracepoint event]
...
probes:myevent [Tracepoint event]
...
2) perf-record -e with no-probed event should try to set up the given probe
by using perf-probe. It is possible to remove that the probe after recording,
but also ignore if it fails by -EBUSY. (anyway, there is no difference for
users)
This rule will solve the contradiction between the event name on recorded
data and listed events. However, as we discussed there are other clashes.
A) clash among binaries: Since the binary builders can freely use the
provider name, it is possible to clash to other binaries' SDTs.
B) clash among different versions: Of course the different versions of binaries
can be co-exist on the system. Those usually have the same SDTs and same
basename, just different build-ids.
These issues are not solved by using "%" because it happens among SDTs.
So we need to find another way to distinguish the SDTs.
Thank you,
>
> Please correct me if I missed something.
>
>> In this series I've introduced %event syntax only to recall cached event
>> setting explicitly, because perf-probe is a lower layer tool to set up
>> new event. IMO, perf-list and perf-record should be higher tools which
>> handle abstract events.
>>
>> Thanks!
>>
>>
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Em Thu, Jul 23, 2015 at 10:13:22PM +0900, Masami Hiramatsu escreveu:
> On 2015/07/22 23:12, Hemant Kumar wrote:
> > On 07/17/2015 08:51 AM, Masami Hiramatsu wrote:
> >> On 2015/07/16 12:13, Hemant Kumar wrote:
> > The idea behind '%' was to identify the SDT events and take a different path
> > to lookup through the cache, put a probe, record and then delete the probe.
> > Or, do you want "perf record" to record any event this way (not just an sdt
> > event).
> I see, but I think that is not good by following reasons,
> - when we record event with "-e %provider:event", it will be shown as
> "provider:event"
> - if perf-list shows the SDT(cached) events as "%provider:event", that
> will not match the recorded result.
> - it is somewhat fragile that we temporary add the SDT event and remove it
> after record, because the event will not hide from ftrace users (this
> means that we'll fail removing the event by -EBUSY if someone use it
> via ftrace)
We should avoid that, if we say record event "foo:bar", then we should
consistently show "foo:bar" everywhere this is referenced.
> - if we set SDT events perf-probe, it will be shown as "provider:event" name
> because "%" will be rejected by ftrace. In that case, what the perf-list show
> those events, both of %provider:event and provider:event ?
> thus I pushed the "%" as a "special remembering mark" only for looking
> up the event from cache by perf-probe.
> So I'd like to suggest that the following behavior
> 1) perf-list shows the cached-with-name and SDT events as Tracepoint events
> even if it is not yet probed.
I can agree with 'perf list' showing what can be used as events, and
SDTs, AFAIK, match that definition, i.e. we have somewhere (in the DSOs,
right?) information about where to ask for an event to be enabled.
If there are details on how that needs to be obtained, then passed to
the kernel somehow to then become really, really accessible, then these
details are completely internal.
> # perf list
>
> List of pre-defined events (to be used in -e):
> ...
> libc:memory_heap_new [Tracepoint event]
Is it like this or is it like [ku]probes where we already have a
namespace qualifier, i.e.:
[root@zoo ~]# perf probe icmp_rcv
Added new event:
probe:icmp_rcv (on icmp_rcv)
You can now use it in all perf tools, such as:
perf record -e probe:icmp_rcv -aR sleep 1
[root@zoo ~]#
[root@zoo ~]# perf probe /lib64/libc-2.20.so malloc
Added new events:
probe_libc:malloc (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_1 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_2 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_3 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_4 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_5 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_6 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_7 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_8 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_9 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_10 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_11 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_12 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_13 (on malloc in /lib64/libc-2.20.so)
probe_libc:malloc_14 (on malloc in /lib64/libc-2.20.so)
You can now use it in all perf tools, such as:
perf record -e probe_libc:malloc_14 -aR sleep 1
[root@zoo ~]#
"probe" for kernel events, "probe_%s" % DSO basename for userspace
events.
Why not continue with that and have SDTs use the probe_%s: namespace?
Sorry if this was already discussed here...
If there is some ambiguity, that can be resolved by explicitely setting
a new name, 'perf probe' has provision for that, right? I.e.:
[root@zoo ~]# perf probe /lib64/libc-2.20.so another_name=malloc
Added new events:
<SNIP>
probe_libc:another_name_14 (on malloc in /lib64/libc-2.20.so)
You can now use it in all perf tools, such as:
perf record -e probe_libc:another_name_14 -aR sleep 1
[root@zoo ~]#
> ...
> probes:myevent [Tracepoint event]
> ...
> 2) perf-record -e with no-probed event should try to set up the given probe
> by using perf-probe. It is possible to remove that the probe after recording,
> but also ignore if it fails by -EBUSY. (anyway, there is no difference for
> users)
Right, being able to add new probes _without_ calling 'perf probe', but
instead functions used by 'perf probe' is something the eBPF does (I'm
almost getting there... :) ) and that I want to do in other tools, like
'trace' as well...
There are permission problems about how to add new probes and how to
_enable_ them, i.e. I think it is ok to allow users to ask for
probe:foo, if they are monitoring just their workloads...
[root@zoo ~]# perf probe 'vfs_getname=getname_flags:72 pathname=filename:string'
Added new event:
probe:vfs_getname (on getname_flags:72 with pathname=filename:string)
You can now use it in all perf tools, such as:
perf record -e probe:vfs_getname -aR sleep 1
[root@zoo ~]#
Then, as !root:
[acme@zoo linux]$ trace cat /etc/passwd
Error: No permissions to read /sys/kernel/debug/tracing/events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug'
By default, !root users can't see debugfs, so, no dice in trying to use
the raw_syscalls tracepoints, bummer, then:
[acme@zoo linux]$ sudo mount -o remount,mode=755 /sys/kernel/debug
[sudo] password for acme:
[acme@zoo linux]$ trace cat /etc/passwd
Error: No permissions to read /sys/kernel/debug/tracing/events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing'
Ouch, now this tracefs thing inside debugfs, at least sudo doesn't asks me for the
password this time!
But then, since 'perf trace' knows there is a probe:vfs_getname syscall in place, it
will try to use it, to monitor a workload it is about to start, but:
[acme@zoo linux]$ sudo mount -o remount,mode=755 /sys/kernel/debug/tracing
[acme@zoo linux]$ trace cat /etc/passwd
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: Try: 'sudo sh -c "echo -1 > /proc/sys/kernel/perf_event_paranoid"'
Hint: The current value is 1.
[acme@zoo linux]$
This needs refining, i.e. I should just warn that albeit "probe:vfs_getname" is available,
it can't be used, unless we open the doors wide.
Sorry for the digression, but these permission issues will hit us with SDT as well, no?
> This rule will solve the contradiction between the event name on recorded
> data and listed events. However, as we discussed there are other clashes.
> A) clash among binaries: Since the binary builders can freely use the
> provider name, it is possible to clash to other binaries' SDTs.
Yes, one way to disambiguate is to use the buildid, i.e. content based, when/if
the need arises. We should _always_ store the build-id, together with any probe
used, so that we can bail out when trying to run those with a non matching DSO
(kernel, module, library, whatever).
When specifying some SDT that is ambiguous, we should bail out and ask for further
namespacing, like:
[acme@zoo linux]$ git show --oneline 25b6
error: short SHA1 25b6 is ambiguous.
error: short SHA1 25b6 is ambiguous.
fatal: ambiguous argument '25b6': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
[acme@zoo linux]$ git show --oneline 25b67
error: short SHA1 25b67 is ambiguous.
error: short SHA1 25b67 is ambiguous.
fatal: ambiguous argument '25b67': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
It can be via build-id or by asking for the full pathname to the DSO, etc.
> B) clash among different versions: Of course the different versions of binaries
> can be co-exist on the system. Those usually have the same SDTs and same
> basename, just different build-ids.
Right, in that case the build-id or the full pathname needs to be specified somehow
> These issues are not solved by using "%" because it happens among SDTs.
> So we need to find another way to distinguish the SDTs.
>From what I've read so far (not much): agreed.
- Arnaldo
On 2015/07/23 23:01, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jul 23, 2015 at 10:13:22PM +0900, Masami Hiramatsu escreveu:
>> On 2015/07/22 23:12, Hemant Kumar wrote:
>>> On 07/17/2015 08:51 AM, Masami Hiramatsu wrote:
>>>> On 2015/07/16 12:13, Hemant Kumar wrote:
>>> The idea behind '%' was to identify the SDT events and take a different path
>>> to lookup through the cache, put a probe, record and then delete the probe.
>>> Or, do you want "perf record" to record any event this way (not just an sdt
>>> event).
>
>> I see, but I think that is not good by following reasons,
>
>> - when we record event with "-e %provider:event", it will be shown as
>> "provider:event"
>> - if perf-list shows the SDT(cached) events as "%provider:event", that
>> will not match the recorded result.
>> - it is somewhat fragile that we temporary add the SDT event and remove it
>> after record, because the event will not hide from ftrace users (this
>> means that we'll fail removing the event by -EBUSY if someone use it
>> via ftrace)
>
> We should avoid that, if we say record event "foo:bar", then we should
> consistently show "foo:bar" everywhere this is referenced.
>
>> - if we set SDT events perf-probe, it will be shown as "provider:event" name
>> because "%" will be rejected by ftrace. In that case, what the perf-list show
>> those events, both of %provider:event and provider:event ?
>
>> thus I pushed the "%" as a "special remembering mark" only for looking
>> up the event from cache by perf-probe.
>
>> So I'd like to suggest that the following behavior
>
>> 1) perf-list shows the cached-with-name and SDT events as Tracepoint events
>> even if it is not yet probed.
>
> I can agree with 'perf list' showing what can be used as events, and
> SDTs, AFAIK, match that definition, i.e. we have somewhere (in the DSOs,
> right?) information about where to ask for an event to be enabled.
SDTs are described in .note section, and is extracted by perf-buildid-cache
and stored into perf-probe's cache file (under buildid-cache). Perf-list
shows only the extracted one.
> If there are details on how that needs to be obtained, then passed to
> the kernel somehow to then become really, really accessible, then these
> details are completely internal.
agreed.
>
>> # perf list
>>
>> List of pre-defined events (to be used in -e):
>> ...
>> libc:memory_heap_new [Tracepoint event]
>
> Is it like this or is it like [ku]probes where we already have a
> namespace qualifier, i.e.:
>
> [root@zoo ~]# perf probe icmp_rcv
> Added new event:
> probe:icmp_rcv (on icmp_rcv)
>
> You can now use it in all perf tools, such as:
>
> perf record -e probe:icmp_rcv -aR sleep 1
>
> [root@zoo ~]#
>
> [root@zoo ~]# perf probe /lib64/libc-2.20.so malloc
> Added new events:
> probe_libc:malloc (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_1 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_2 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_3 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_4 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_5 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_6 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_7 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_8 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_9 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_10 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_11 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_12 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_13 (on malloc in /lib64/libc-2.20.so)
> probe_libc:malloc_14 (on malloc in /lib64/libc-2.20.so)
>
> You can now use it in all perf tools, such as:
>
> perf record -e probe_libc:malloc_14 -aR sleep 1
>
> [root@zoo ~]#
>
> "probe" for kernel events, "probe_%s" % DSO basename for userspace
> events.
>
> Why not continue with that and have SDTs use the probe_%s: namespace?
> Sorry if this was already discussed here...
:) We are discussing about that in another thread, anyway, probe_%s can
solve a little part of the clash of names.
>
> If there is some ambiguity, that can be resolved by explicitely setting
> a new name, 'perf probe' has provision for that, right? I.e.:
Yes, but that means we'll have to give new names before using that.
Actually, SDT has "provider-name", "event-name" and "probe location" (also
have arguments, but not supported). And provider name is not always same
as the binary name. (actually, the application developers can use any
name for it...)
So adding something special prefix or detect clash before using will
be the option.
The following patterns we've discussed.
- <provider>:<name>
simple, but could easily clash with others.
- probe_<provider>:<name>
- sdt_<provider>:<name>
also simple and similar to current solution. but fragile against
clash among SDTs.
- probe_<binary>:<provider>_<name>
also simple, but if provider or/and name has '_', it is hard to
split the provider and name. and fragile against clash among SDTs too.
- <provider>_<buildid>/<name>
possible, but ugly since buildid is a random long xdigits(maybe cut up
to 8 or 12 bytes).
> [root@zoo ~]# perf probe /lib64/libc-2.20.so another_name=malloc
> Added new events:
> <SNIP>
> probe_libc:another_name_14 (on malloc in /lib64/libc-2.20.so)
>
> You can now use it in all perf tools, such as:
>
> perf record -e probe_libc:another_name_14 -aR sleep 1
>
> [root@zoo ~]#
>
>> ...
>> probes:myevent [Tracepoint event]
>> ...
>
>> 2) perf-record -e with no-probed event should try to set up the given probe
>> by using perf-probe. It is possible to remove that the probe after recording,
>> but also ignore if it fails by -EBUSY. (anyway, there is no difference for
>> users)
>
> Right, being able to add new probes _without_ calling 'perf probe', but
> instead functions used by 'perf probe' is something the eBPF does (I'm
> almost getting there... :) ) and that I want to do in other tools, like
> 'trace' as well...
Yes, it should be done internally. (of course, users also can use perf-probe
for activating SDT.)
> There are permission problems about how to add new probes and how to
> _enable_ them, i.e. I think it is ok to allow users to ask for
> probe:foo, if they are monitoring just their workloads...
I see... But that's another issue I think, since the issue is already there
for using uprobes. We'd better fork thread for that issue.
[...]
> This needs refining, i.e. I should just warn that albeit "probe:vfs_getname" is available,
> it can't be used, unless we open the doors wide.
>
> Sorry for the digression, but these permission issues will hit us with SDT as well, no?
Yes, and we have another way to avoid this issue, by using setuid as systemtap does.
>> This rule will solve the contradiction between the event name on recorded
>> data and listed events. However, as we discussed there are other clashes.
>
>> A) clash among binaries: Since the binary builders can freely use the
>> provider name, it is possible to clash to other binaries' SDTs.
>
> Yes, one way to disambiguate is to use the buildid, i.e. content based, when/if
> the need arises. We should _always_ store the build-id, together with any probe
> used, so that we can bail out when trying to run those with a non matching DSO
> (kernel, module, library, whatever).
Store the build-id with what? SDTs and cached probes are already stored under
build-id directory(same location of buildid-cache). Would you mean perf.data?
And managing all probe events strictly by perftools is hard since someone can
set new probes via tracefs(debugfs) directly.
>
> When specifying some SDT that is ambiguous, we should bail out and ask for further
> namespacing, like:
>
> [acme@zoo linux]$ git show --oneline 25b6
> error: short SHA1 25b6 is ambiguous.
> error: short SHA1 25b6 is ambiguous.
> fatal: ambiguous argument '25b6': unknown revision or path not in the working tree.
> Use '--' to separate paths from revisions, like this:
> 'git <command> [<revision>...] -- [<file>...]'
> [acme@zoo linux]$ git show --oneline 25b67
> error: short SHA1 25b67 is ambiguous.
> error: short SHA1 25b67 is ambiguous.
> fatal: ambiguous argument '25b67': unknown revision or path not in the working tree.
> Use '--' to separate paths from revisions, like this:
> 'git <command> [<revision>...] -- [<file>...]'
>
> It can be via build-id or by asking for the full pathname to the DSO, etc.
>
>> B) clash among different versions: Of course the different versions of binaries
>> can be co-exist on the system. Those usually have the same SDTs and same
>> basename, just different build-ids.
>
> Right, in that case the build-id or the full pathname needs to be specified somehow
>
>> These issues are not solved by using "%" because it happens among SDTs.
>> So we need to find another way to distinguish the SDTs.
>
>>From what I've read so far (not much): agreed.
Thank you,
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Em Fri, Jul 24, 2015 at 01:24:53AM +0900, Masami Hiramatsu escreveu:
> On 2015/07/23 23:01, Arnaldo Carvalho de Melo wrote:
> > This needs refining, i.e. I should just warn that albeit "probe:vfs_getname" is available,
> > it can't be used, unless we open the doors wide.
> >
> > Sorry for the digression, but these permission issues will hit us with SDT as well, no?
>
> Yes, and we have another way to avoid this issue, by using setuid as systemtap does.
Will react to the other parts later, but 'setuid'?, can we do better?
That look like some big hammer :-/
- Arnaldo
Hi Masami and Arnaldo,
On Fri, Jul 24, 2015 at 01:24:53AM +0900, Masami Hiramatsu wrote:
> On 2015/07/23 23:01, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Jul 23, 2015 at 10:13:22PM +0900, Masami Hiramatsu escreveu:
> >> # perf list
> >>
> >> List of pre-defined events (to be used in -e):
> >> ...
> >> libc:memory_heap_new [Tracepoint event]
> >
> > Is it like this or is it like [ku]probes where we already have a
> > namespace qualifier, i.e.:
> >
> > [root@zoo ~]# perf probe icmp_rcv
> > Added new event:
> > probe:icmp_rcv (on icmp_rcv)
> >
> > You can now use it in all perf tools, such as:
> >
> > perf record -e probe:icmp_rcv -aR sleep 1
> >
> > [root@zoo ~]#
> >
> > [root@zoo ~]# perf probe /lib64/libc-2.20.so malloc
> > Added new events:
> > probe_libc:malloc (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_1 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_2 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_3 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_4 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_5 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_6 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_7 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_8 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_9 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_10 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_11 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_12 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_13 (on malloc in /lib64/libc-2.20.so)
> > probe_libc:malloc_14 (on malloc in /lib64/libc-2.20.so)
> >
> > You can now use it in all perf tools, such as:
> >
> > perf record -e probe_libc:malloc_14 -aR sleep 1
> >
> > [root@zoo ~]#
> >
> > "probe" for kernel events, "probe_%s" % DSO basename for userspace
> > events.
> >
> > Why not continue with that and have SDTs use the probe_%s: namespace?
> > Sorry if this was already discussed here...
>
> :) We are discussing about that in another thread, anyway, probe_%s can
> solve a little part of the clash of names.
>
> >
> > If there is some ambiguity, that can be resolved by explicitely setting
> > a new name, 'perf probe' has provision for that, right? I.e.:
>
> Yes, but that means we'll have to give new names before using that.
>
> Actually, SDT has "provider-name", "event-name" and "probe location" (also
> have arguments, but not supported). And provider name is not always same
> as the binary name. (actually, the application developers can use any
> name for it...)
> So adding something special prefix or detect clash before using will
> be the option.
>
> The following patterns we've discussed.
>
> - <provider>:<name>
> simple, but could easily clash with others.
> - probe_<provider>:<name>
> - sdt_<provider>:<name>
> also simple and similar to current solution. but fragile against
> clash among SDTs.
> - probe_<binary>:<provider>_<name>
> also simple, but if provider or/and name has '_', it is hard to
> split the provider and name. and fragile against clash among SDTs too.
> - <provider>_<buildid>/<name>
> possible, but ugly since buildid is a random long xdigits(maybe cut up
> to 8 or 12 bytes).
As I said, we might allow name clashes as they're rare. I don't want
to make it complex just for an uncommon case. I think such a
duplicate name is fine as long as 'perf list' indicates it and 'perf
record' enable them all.
If we agreed to extend the event format, I'd like to keep it simple
and to make it optional to add more info (separated by colon?).
Maybe something like below. Suppose we have 3 SDT events with a same
name:
/some/where/dir1/libfoo1.so (build-id: 0x1234...) --> foo:bar
/some/where/dir2/libfoo1.so (build-id: 0x5678...) --> foo:bar
/some/where/dir2/libfoo2.so (build-id: 0xabcd...) --> foo:bar
So perf list shows the single name, but also says it has 3 events.
$ perf list sdt_foo:bar
sdt_foo:bar (total 3 events) [User SDT event]
$ perf list -v sdt_foo:bar
sdt_foo:bar:libfoo1.so:0x1234... [User SDT event]
sdt_foo:bar:libfoo1.so:0x5678... [User SDT event]
sdt_foo:bar:libfoo2.so:0xabcd... [User SDT event]
Now perf record can accept any of these forms..
# record all 3 events
$ perf record -e 'sdt_foo:bar'
# record 2 events from libfoo1.so
$ perf record -e 'sdt_foo:bar:libfoo1.so'
# record only 1 event
$ perf record -e 'sdt_foo:bar:libfoo1.so:0x1234...'
What do you think?
Thanks,
Namhyung
Em Fri, Jul 24, 2015 at 04:55:19PM +0900, Namhyung Kim escreveu:
> On Fri, Jul 24, 2015 at 01:24:53AM +0900, Masami Hiramatsu wrote:
> > On 2015/07/23 23:01, Arnaldo Carvalho de Melo wrote:
> > > Em Thu, Jul 23, 2015 at 10:13:22PM +0900, Masami Hiramatsu escreveu:
> > The following patterns we've discussed.
> >
> > - <provider>:<name>
> > simple, but could easily clash with others.
> > - probe_<provider>:<name>
> > - sdt_<provider>:<name>
> > also simple and similar to current solution. but fragile against
> > clash among SDTs.
> > - probe_<binary>:<provider>_<name>
> > also simple, but if provider or/and name has '_', it is hard to
> > split the provider and name. and fragile against clash among SDTs too.
> > - <provider>_<buildid>/<name>
> > possible, but ugly since buildid is a random long xdigits(maybe cut up
> > to 8 or 12 bytes).
> As I said, we might allow name clashes as they're rare. I don't want
> to make it complex just for an uncommon case. I think such a
> duplicate name is fine as long as 'perf list' indicates it and 'perf
> record' enable them all.
I made some comments about enabling it all by default, look below.
> If we agreed to extend the event format, I'd like to keep it simple
> and to make it optional to add more info (separated by colon?).
Reading this again after writing what is below: my suggestion is to use
@, see rationale below.
> Maybe something like below. Suppose we have 3 SDT events with a same
> name:
>
> /some/where/dir1/libfoo1.so (build-id: 0x1234...) --> foo:bar
> /some/where/dir2/libfoo1.so (build-id: 0x5678...) --> foo:bar
> /some/where/dir2/libfoo2.so (build-id: 0xabcd...) --> foo:bar
>
> So perf list shows the single name, but also says it has 3 events.
>
> $ perf list sdt_foo:bar
>
> sdt_foo:bar (total 3 events) [User SDT event]
I would show what desambiguates them in non verbose mode, i.e., the
above would be:
$ perf list sdt_foo:bar
sdt_foo:bar:dir1/libfoo1.so [User SDT event]
sdt_foo:bar:dir2/libfoo1.so [User SDT event]
sdt_foo:bar:libfoo2.so [User SDT event]
The -v one would should both the full path and the buildid, but this
is just polishing up the default output a bit to make it more
informative.
Now what should be the default when one does:
perf record -e sdt_foo:bar
Will it enable all events or bail out and state that multiple
events with that name matches, requiring a '--all-matches' to really
apply it to all events with the same name?
Humm, this probably will not be that common, so perhaps just
use all matches by default while telling the user that all those places
were used and if the user wants just one of them, be more precise,
adding somehow a disambiguator.
That would be something like this:
perf record -e sdt_foo:bar:0x1234
Or perhaps:
perf record -e sdt_foo:bar@0x1234
Because in this case the 'at' meaning of '@' makes sense, i.e.
use the std_foo:bar event at the DSO with a 0x1234 buildid?
Additionally, for people that don't want to mess with buildids
because its environment is deemed well controlled and this works and is
unambiguous, looking at the LD_LIBRARY_PATH or equivalent:
perf record -e sdt_foo:bar@libfoo2
Full paths could be used as well.
>
> $ perf list -v sdt_foo:bar
>
> sdt_foo:bar:libfoo1.so:0x1234... [User SDT event]
> sdt_foo:bar:libfoo1.so:0x5678... [User SDT event]
> sdt_foo:bar:libfoo2.so:0xabcd... [User SDT event]
>
> Now perf record can accept any of these forms..
>
> # record all 3 events
> $ perf record -e 'sdt_foo:bar'
>
> # record 2 events from libfoo1.so
> $ perf record -e 'sdt_foo:bar:libfoo1.so'
>
> # record only 1 event
> $ perf record -e 'sdt_foo:bar:libfoo1.so:0x1234...'
>
>
> What do you think?
If nothing prevents using @ with the meaning of "event at LOCATION"
where LOCATION is a buildid (noticed because it starts with 0x) or
a library name or pathname, then that looks more natural.
- Arnaldo
On 2015/07/25 0:52, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jul 24, 2015 at 04:55:19PM +0900, Namhyung Kim escreveu:
>> On Fri, Jul 24, 2015 at 01:24:53AM +0900, Masami Hiramatsu wrote:
>>> On 2015/07/23 23:01, Arnaldo Carvalho de Melo wrote:
>>>> Em Thu, Jul 23, 2015 at 10:13:22PM +0900, Masami Hiramatsu escreveu:
>
>>> The following patterns we've discussed.
>>>
>>> - <provider>:<name>
>>> simple, but could easily clash with others.
>>> - probe_<provider>:<name>
>>> - sdt_<provider>:<name>
>>> also simple and similar to current solution. but fragile against
>>> clash among SDTs.
>>> - probe_<binary>:<provider>_<name>
>>> also simple, but if provider or/and name has '_', it is hard to
>>> split the provider and name. and fragile against clash among SDTs too.
>>> - <provider>_<buildid>/<name>
>>> possible, but ugly since buildid is a random long xdigits(maybe cut up
>>> to 8 or 12 bytes).
>
>> As I said, we might allow name clashes as they're rare. I don't want
>> to make it complex just for an uncommon case. I think such a
>> duplicate name is fine as long as 'perf list' indicates it and 'perf
>> record' enable them all.
>
> I made some comments about enabling it all by default, look below.
>
>> If we agreed to extend the event format, I'd like to keep it simple
>> and to make it optional to add more info (separated by colon?).
>
> Reading this again after writing what is below: my suggestion is to use
> @, see rationale below.
>
>> Maybe something like below. Suppose we have 3 SDT events with a same
>> name:
>>
>> /some/where/dir1/libfoo1.so (build-id: 0x1234...) --> foo:bar
>> /some/where/dir2/libfoo1.so (build-id: 0x5678...) --> foo:bar
>> /some/where/dir2/libfoo2.so (build-id: 0xabcd...) --> foo:bar
>>
>> So perf list shows the single name, but also says it has 3 events.
>>
>> $ perf list sdt_foo:bar
>>
>> sdt_foo:bar (total 3 events) [User SDT event]
>
> I would show what desambiguates them in non verbose mode, i.e., the
> above would be:
>
> $ perf list sdt_foo:bar
>
> sdt_foo:bar:dir1/libfoo1.so [User SDT event]
> sdt_foo:bar:dir2/libfoo1.so [User SDT event]
> sdt_foo:bar:libfoo2.so [User SDT event]
>
> The -v one would should both the full path and the buildid, but this
> is just polishing up the default output a bit to make it more
> informative.
I agree that the short path is useful, but we know only full path
how to make it short? (only show the differences?)
>
> Now what should be the default when one does:
>
> perf record -e sdt_foo:bar
>
> Will it enable all events or bail out and state that multiple
> events with that name matches, requiring a '--all-matches' to really
> apply it to all events with the same name?
OK, but the problem is that the k/uprobe_event doesn't support multiple
probe on one event yet. This means that if we set those 3 events, it will
be translated to "sdt_foo:bar", "sdt_foo:bar_1", and "sdt_foo:bar_2".
So we need to enhance k/uprobe_event too. Note that, if the event-name
clash happens among events with different type of arguments, we can not
bail it out... It is better to warn user if that happened.
> Humm, this probably will not be that common, so perhaps just
> use all matches by default while telling the user that all those places
> were used and if the user wants just one of them, be more precise,
> adding somehow a disambiguator.
>
> That would be something like this:
>
> perf record -e sdt_foo:bar:0x1234
>
> Or perhaps:
>
> perf record -e sdt_foo:bar@0x1234
>
> Because in this case the 'at' meaning of '@' makes sense, i.e.
> use the std_foo:bar event at the DSO with a 0x1234 buildid?
Ah, that's nice :) I like '@'.
> Additionally, for people that don't want to mess with buildids
> because its environment is deemed well controlled and this works and is
> unambiguous, looking at the LD_LIBRARY_PATH or equivalent:
>
> perf record -e sdt_foo:bar@libfoo2
>
> Full paths could be used as well.
>>
>> $ perf list -v sdt_foo:bar
>>
>> sdt_foo:bar:libfoo1.so:0x1234... [User SDT event]
>> sdt_foo:bar:libfoo1.so:0x5678... [User SDT event]
>> sdt_foo:bar:libfoo2.so:0xabcd... [User SDT event]
>
>>
>> Now perf record can accept any of these forms..
>>
>> # record all 3 events
>> $ perf record -e 'sdt_foo:bar'
>>
>> # record 2 events from libfoo1.so
>> $ perf record -e 'sdt_foo:bar:libfoo1.so'
>>
>> # record only 1 event
>> $ perf record -e 'sdt_foo:bar:libfoo1.so:0x1234...'
>>
>>
>> What do you think?
>
> If nothing prevents using @ with the meaning of "event at LOCATION"
> where LOCATION is a buildid (noticed because it starts with 0x) or
> a library name or pathname, then that looks more natural.
BTW, will we show it as "[User SDT event]" instead of "[Tracepoint]"?
In that case, after setting the event, same name event will appear
under tracefs/events/. I guess it conflicts with above SDT event.
e.g.
$ perf list sdt_foo:bar
sdt_foo:bar@dir1/libfoo1.so [User SDT event]
sdt_foo:bar@dir2/libfoo1.so [User SDT event]
sdt_foo:[email protected] [User SDT event]
And enables on libfoo2.so
$ perf record -e sdt_foo:[email protected]
What the perf list shows
$ perf list sdt_foo:bar
sdt_foo:[email protected] [Tracepoint]
sdt_foo:bar@dir1/libfoo1.so [User SDT event]
sdt_foo:bar@dir2/libfoo1.so [User SDT event]
Is this OK? Or, we'll need to distinguish sdt_* from other events.
Thank you,
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Hi Arnaldo,
On Fri, Jul 24, 2015 at 12:52:37PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jul 24, 2015 at 04:55:19PM +0900, Namhyung Kim escreveu:
> > On Fri, Jul 24, 2015 at 01:24:53AM +0900, Masami Hiramatsu wrote:
> > > On 2015/07/23 23:01, Arnaldo Carvalho de Melo wrote:
> > > > Em Thu, Jul 23, 2015 at 10:13:22PM +0900, Masami Hiramatsu escreveu:
>
> > > The following patterns we've discussed.
> > >
> > > - <provider>:<name>
> > > simple, but could easily clash with others.
> > > - probe_<provider>:<name>
> > > - sdt_<provider>:<name>
> > > also simple and similar to current solution. but fragile against
> > > clash among SDTs.
> > > - probe_<binary>:<provider>_<name>
> > > also simple, but if provider or/and name has '_', it is hard to
> > > split the provider and name. and fragile against clash among SDTs too.
> > > - <provider>_<buildid>/<name>
> > > possible, but ugly since buildid is a random long xdigits(maybe cut up
> > > to 8 or 12 bytes).
>
> > As I said, we might allow name clashes as they're rare. I don't want
> > to make it complex just for an uncommon case. I think such a
> > duplicate name is fine as long as 'perf list' indicates it and 'perf
> > record' enable them all.
>
> I made some comments about enabling it all by default, look below.
OK.
>
> > If we agreed to extend the event format, I'd like to keep it simple
> > and to make it optional to add more info (separated by colon?).
>
> Reading this again after writing what is below: my suggestion is to use
> @, see rationale below.
I'm fine with using @.
>
> > Maybe something like below. Suppose we have 3 SDT events with a same
> > name:
> >
> > /some/where/dir1/libfoo1.so (build-id: 0x1234...) --> foo:bar
> > /some/where/dir2/libfoo1.so (build-id: 0x5678...) --> foo:bar
> > /some/where/dir2/libfoo2.so (build-id: 0xabcd...) --> foo:bar
> >
> > So perf list shows the single name, but also says it has 3 events.
> >
> > $ perf list sdt_foo:bar
> >
> > sdt_foo:bar (total 3 events) [User SDT event]
>
> I would show what desambiguates them in non verbose mode, i.e., the
> above would be:
>
> $ perf list sdt_foo:bar
>
> sdt_foo:bar:dir1/libfoo1.so [User SDT event]
> sdt_foo:bar:dir2/libfoo1.so [User SDT event]
> sdt_foo:bar:libfoo2.so [User SDT event]
Then it should use @ here too.
>
> The -v one would should both the full path and the buildid, but this
> is just polishing up the default output a bit to make it more
> informative.
Fair enough.
>
> Now what should be the default when one does:
>
> perf record -e sdt_foo:bar
>
> Will it enable all events or bail out and state that multiple
> events with that name matches, requiring a '--all-matches' to really
> apply it to all events with the same name?
>
> Humm, this probably will not be that common, so perhaps just
> use all matches by default while telling the user that all those places
> were used and if the user wants just one of them, be more precise,
> adding somehow a disambiguator.
Either is fine to me. Mayb we can add a config option to select the
default bahavior.. :)
>
> That would be something like this:
>
> perf record -e sdt_foo:bar:0x1234
>
> Or perhaps:
>
> perf record -e sdt_foo:bar@0x1234
>
> Because in this case the 'at' meaning of '@' makes sense, i.e.
> use the std_foo:bar event at the DSO with a 0x1234 buildid?
IMHO @ looks perfect for pathnames but I don't know about build-id as
it can be thought as some address. Anyway I still think @ is a good
choice though. ;-)
>
> Additionally, for people that don't want to mess with buildids
> because its environment is deemed well controlled and this works and is
> unambiguous, looking at the LD_LIBRARY_PATH or equivalent:
Ah, good idea.
>
> perf record -e sdt_foo:bar@libfoo2
>
> Full paths could be used as well.
> >
> > $ perf list -v sdt_foo:bar
> >
> > sdt_foo:bar:libfoo1.so:0x1234... [User SDT event]
> > sdt_foo:bar:libfoo1.so:0x5678... [User SDT event]
> > sdt_foo:bar:libfoo2.so:0xabcd... [User SDT event]
>
> >
> > Now perf record can accept any of these forms..
> >
> > # record all 3 events
> > $ perf record -e 'sdt_foo:bar'
> >
> > # record 2 events from libfoo1.so
> > $ perf record -e 'sdt_foo:bar:libfoo1.so'
> >
> > # record only 1 event
> > $ perf record -e 'sdt_foo:bar:libfoo1.so:0x1234...'
> >
> >
> > What do you think?
>
> If nothing prevents using @ with the meaning of "event at LOCATION"
> where LOCATION is a buildid (noticed because it starts with 0x) or
> a library name or pathname, then that looks more natural.
Agreed.
Thanks,
Namhyung
Em Mon, Jul 27, 2015 at 11:03:20PM +0900, Namhyung Kim escreveu:
> On Fri, Jul 24, 2015 at 12:52:37PM -0300, Arnaldo Carvalho de Melo wrote:
> > > If we agreed to extend the event format, I'd like to keep it simple
> > > and to make it optional to add more info (separated by colon?).
> >
> > Reading this again after writing what is below: my suggestion is to use
> > @, see rationale below.
>
> I'm fine with using @.
> > I would show what desambiguates them in non verbose mode, i.e., the
> > above would be:
> >
> > $ perf list sdt_foo:bar
> >
> > sdt_foo:bar:dir1/libfoo1.so [User SDT event]
> > sdt_foo:bar:dir2/libfoo1.so [User SDT event]
> > sdt_foo:bar:libfoo2.so [User SDT event]
>
> Then it should use @ here too.
Right.
<SNIP>
> > That would be something like this:
> > perf record -e sdt_foo:bar@0x1234
> > Because in this case the 'at' meaning of '@' makes sense, i.e.
> > use the std_foo:bar event at the DSO with a 0x1234 buildid?
>
> IMHO @ looks perfect for pathnames but I don't know about build-id as
> it can be thought as some address. Anyway I still think @ is a good
> choice though. ;-)
Yeah, perhaps we need further clarification? I.e. something like:
sdt_foo:bar:libfoo1.so@buildid(0x1234)
Or something else, perhaps shorter, that clarifies that it is a buildid?
- Arnaldo
On 2015/07/28 0:16, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jul 27, 2015 at 11:03:20PM +0900, Namhyung Kim escreveu:
>> On Fri, Jul 24, 2015 at 12:52:37PM -0300, Arnaldo Carvalho de Melo wrote:
>>>> If we agreed to extend the event format, I'd like to keep it simple
>>>> and to make it optional to add more info (separated by colon?).
>>>
>>> Reading this again after writing what is below: my suggestion is to use
>>> @, see rationale below.
>>
>> I'm fine with using @.
>
>>> I would show what desambiguates them in non verbose mode, i.e., the
>>> above would be:
>>>
>>> $ perf list sdt_foo:bar
>>>
>>> sdt_foo:bar:dir1/libfoo1.so [User SDT event]
>>> sdt_foo:bar:dir2/libfoo1.so [User SDT event]
>>> sdt_foo:bar:libfoo2.so [User SDT event]
>>
>> Then it should use @ here too.
>
> Right.
>
> <SNIP>
>
>>> That would be something like this:
>
>>> perf record -e sdt_foo:bar@0x1234
>
>>> Because in this case the 'at' meaning of '@' makes sense, i.e.
>>> use the std_foo:bar event at the DSO with a 0x1234 buildid?
>>
>> IMHO @ looks perfect for pathnames but I don't know about build-id as
>> it can be thought as some address. Anyway I still think @ is a good
>> choice though. ;-)
>
> Yeah, perhaps we need further clarification? I.e. something like:
>
> sdt_foo:bar:libfoo1.so@buildid(0x1234)
>
> Or something else, perhaps shorter, that clarifies that it is a buildid?
Hmm, Do we really need such additional buildid? Even though, I think
the build id should have different delimiter, like '%', as below.
sdt_foo:[email protected]%buildid
Thank you,
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: [email protected]
Em Tue, Jul 28, 2015 at 09:42:59AM +0900, Masami Hiramatsu escreveu:
> On 2015/07/28 0:16, Arnaldo Carvalho de Melo wrote:
> > Em Mon, Jul 27, 2015 at 11:03:20PM +0900, Namhyung Kim escreveu:
> >> IMHO @ looks perfect for pathnames but I don't know about build-id as
> >> it can be thought as some address. Anyway I still think @ is a good
> >> choice though. ;-)
> > Yeah, perhaps we need further clarification? I.e. something like:
> > sdt_foo:bar:libfoo1.so@buildid(0x1234)
> > Or something else, perhaps shorter, that clarifies that it is a buildid?
>
> Hmm, Do we really need such additional buildid? Even though, I think
"or something else, perhaps shorter" :-)
> the build id should have different delimiter, like '%', as below.
>
> sdt_foo:[email protected]%buildid
How about:
sdt_foo:[email protected](0x1234)
Which is clear, to humans: "hey, I want the SDT event 'bar' at the
'libfoo1' library, but make sure it is the one which contents have build
id '0x1234'".
But even the name of the library is not strictly needed, would be just a
nicety for humans, as the way buildids are looked up are by means of:
[acme@zoo tuna]$ ls -la /usr/lib/debug/.build-id/ | tail -5
drwxr-xr-x. 2 root root 4096 Jul 23 09:26 fb/
drwxr-xr-x. 2 root root 4096 Jun 22 19:35 fc/
drwxr-xr-x. 2 root root 4096 Jun 22 19:35 fd/
drwxr-xr-x. 2 root root 4096 Jun 22 19:35 fe/
drwxr-xr-x. 2 root root 4096 Jun 26 16:57 ff/
[acme@zoo tuna]$
So, having:
sdt_foo:bar@0x1234
Should be unambiguous and shorter.
- ARnaldo