Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1441198 > unrolled thread
| Started by | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| First post | 2016-07-12 12:10 +0200 |
| Last post | 2016-07-14 03:40 +0200 |
| Articles | 6 on this page of 26 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH perf/core 00/10] perf-probe --cache and SDT support Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
[PATCH perf/core 03/10] perf-probe: Make --list shows only available cached events Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
Re: [PATCH perf/core 03/10] perf-probe: Make --list shows only available cached events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-13 21:30 +0200
Re: [PATCH perf/core 03/10] perf-probe: Make --list shows only available cached events Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-14 08:20 +0200
[tip:perf/core] perf probe: Make --list show only available cached events tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:10 +0200
[PATCH perf/core 10/10] perf-test: Add a test case for SDT event Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
[tip:perf/core] perf test: Add a test case for SDT event tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:20 +0200
[PATCH perf/core 09/10] perf build: Add sdt feature detection Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
[tip:perf/core] perf build: Add sdt feature detection tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:20 +0200
[PATCH perf/core 01/10] [BUGFIX] perf-probe: Fix to show correct error message for $vars and $params Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
[tip:perf/core] perf probe: Fix to show correct error message for $vars and $params tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:10 +0200
[PATCH perf/core 07/10] perf probe: Support @BUILDID or @FILE suffix for SDT events Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
Re: [PATCH perf/core 07/10] perf probe: Support @BUILDID or @FILE suffix for SDT events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-13 22:00 +0200
Re: [PATCH perf/core 07/10] perf probe: Support @BUILDID or @FILE suffix for SDT events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-14 02:10 +0200
Re: [PATCH perf/core 07/10] perf probe: Support @BUILDID or @FILE suffix for SDT events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-14 02:20 +0200
Re: [PATCH perf/core 07/10] perf probe: Support @BUILDID or @FILE suffix for SDT events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-14 02:30 +0200
Re: [PATCH perf/core 07/10] perf probe: Support @BUILDID or @FILE suffix for SDT events Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-14 17:40 +0200
[tip:perf/core] perf probe: Support @BUILDID or @FILE suffix for SDT events tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:10 +0200
[PATCH perf/core 08/10] perf probe: Support a special SDT probe format Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
[tip:perf/core] perf probe: Support a special SDT probe format tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:10 +0200
[PATCH perf/core 05/10] perf probe: Allow wildcard for cached events Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
Re: [PATCH perf/core 05/10] perf probe: Allow wildcard for cached events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-13 21:40 +0200
[tip:perf/core] perf probe: Allow wildcard for cached events tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:10 +0200
[PATCH perf/core 02/10] perf probe: Accept %sdt and %cached event name Masami Hiramatsu <mhiramat@kernel.org> - 2016-07-12 12:10 +0200
[tip:perf/core] perf probe: Accept %sdt and %cached event name tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-07-14 09:10 +0200
Re: [PATCH perf/core 00/10] perf-probe --cache and SDT support Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-07-14 03:40 +0200
Page 2 of 2 — ← Prev page 1 [2]
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Date | 2016-07-12 12:10 +0200 |
| Subject | [PATCH perf/core 05/10] perf probe: Allow wildcard for cached events |
| Message-ID | <rU2NB-3tA-59@gated-at.bofh.it> |
| In reply to | #1441198 |
Allo glob wildcard for reusing cached/SDT events. E.g.
# perf probe -x /usr/lib64/libc-2.20.so -a %sdt_libc:\*
This example adds probes for all SDT in libc.
Note that the SDTs must have been scanned by perf buildid-cache.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Changes in v12:
- Rename strlist__for_each to strlist__for_each_entry.
Changes in v10:
- Split off bugfix, adding interface, and target search patches.
- Do not export clear_probe_trace_events().
Changes in v7:
- Continue to search caches if a build-id cache has no probe cache.
- Make probe_cache__open() to accept DSO__NAME_KALLSYMS for kernel.
- Fix to add probes correctly when a wildcard matchs both of
uprobes and kprobes.
Changes in v5.1:
- Fix a SEGV bug when a group name is omitted. (Thanks Hemant!)
---
tools/perf/util/probe-event.c | 107 +++++++++++++++++++++++++++++++++++++++--
tools/perf/util/probe-file.c | 38 ++++++++++++---
tools/perf/util/probe-file.h | 3 +
3 files changed, 138 insertions(+), 10 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 3642cca..1aeac09 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1204,7 +1204,7 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
ptr = strchr(*arg, ':');
if (ptr) {
*ptr = '\0';
- if (!is_c_func_name(*arg))
+ if (!pev->sdt && !is_c_func_name(*arg))
goto ng_name;
pev->group = strdup(*arg);
if (!pev->group)
@@ -1212,7 +1212,7 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
*arg = ptr + 1;
} else
pev->group = NULL;
- if (!is_c_func_name(*arg)) {
+ if (!pev->sdt && !is_c_func_name(*arg)) {
ng_name:
semantic_error("%s is bad for event name -it must "
"follow C symbol-naming rule.\n", *arg);
@@ -1644,6 +1644,7 @@ int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
ret = -ENOMEM;
goto out;
}
+ tev->uprobes = (tp->module[0] == '/');
p++;
} else
p = argv[1];
@@ -2518,7 +2519,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
int ret;
/* If probe_event or trace_event already have the name, reuse it */
- if (pev->event)
+ if (pev->event && !pev->sdt)
event = pev->event;
else if (tev->event)
event = tev->event;
@@ -2531,7 +2532,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
else
event = tev->point.realname;
}
- if (pev->group)
+ if (pev->group && !pev->sdt)
group = pev->group;
else if (tev->group)
group = tev->group;
@@ -2894,6 +2895,100 @@ errout:
bool __weak arch__prefers_symtab(void) { return false; }
+/* Concatinate two arrays */
+static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b)
+{
+ void *ret;
+
+ ret = malloc(sz_a + sz_b);
+ if (ret) {
+ memcpy(ret, a, sz_a);
+ memcpy(ret + sz_a, b, sz_b);
+ }
+ return ret;
+}
+
+static int
+concat_probe_trace_events(struct probe_trace_event **tevs, int *ntevs,
+ struct probe_trace_event **tevs2, int ntevs2)
+{
+ struct probe_trace_event *new_tevs;
+ int ret = 0;
+
+ if (ntevs == 0) {
+ *tevs = *tevs2;
+ *ntevs = ntevs2;
+ *tevs2 = NULL;
+ return 0;
+ }
+
+ if (*ntevs + ntevs2 > probe_conf.max_probes)
+ ret = -E2BIG;
+ else {
+ /* Concatinate the array of probe_trace_event */
+ new_tevs = memcat(*tevs, (*ntevs) * sizeof(**tevs),
+ *tevs2, ntevs2 * sizeof(**tevs2));
+ if (!new_tevs)
+ ret = -ENOMEM;
+ else {
+ free(*tevs);
+ *tevs = new_tevs;
+ *ntevs += ntevs2;
+ }
+ }
+ if (ret < 0)
+ clear_probe_trace_events(*tevs2, ntevs2);
+ zfree(tevs2);
+
+ return ret;
+}
+
+/*
+ * Try to find probe_trace_event from given probe caches. Return the number
+ * of cached events found, if an error occurs return the error.
+ */
+static int find_cached_events(struct perf_probe_event *pev,
+ struct probe_trace_event **tevs,
+ const char *target)
+{
+ struct probe_cache *cache;
+ struct probe_cache_entry *entry;
+ struct probe_trace_event *tmp_tevs = NULL;
+ int ntevs = 0;
+ int ret = 0;
+
+ cache = probe_cache__new(target);
+ /* Return 0 ("not found") if the target has no probe cache. */
+ if (!cache)
+ return 0;
+
+ for_each_probe_cache_entry(entry, cache) {
+ /* Skip the cache entry which has no name */
+ if (!entry->pev.event || !entry->pev.group)
+ continue;
+ if ((!pev->group || strglobmatch(entry->pev.group, pev->group)) &&
+ strglobmatch(entry->pev.event, pev->event)) {
+ ret = probe_cache_entry__get_event(entry, &tmp_tevs);
+ if (ret > 0)
+ ret = concat_probe_trace_events(tevs, &ntevs,
+ &tmp_tevs, ret);
+ if (ret < 0)
+ break;
+ }
+ }
+ probe_cache__delete(cache);
+ if (ret < 0) {
+ clear_probe_trace_events(*tevs, ntevs);
+ zfree(tevs);
+ } else {
+ ret = ntevs;
+ if (ntevs > 0 && target && target[0] == '/')
+ pev->uprobes = true;
+ }
+
+ return ret;
+}
+
static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
struct probe_trace_event **tevs)
{
@@ -2903,6 +2998,10 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
struct str_node *node;
int ret, i;
+ if (pev->sdt)
+ /* For SDT/cached events, we use special search functions */
+ return find_cached_events(pev, tevs, pev->target);
+
cache = probe_cache__new(pev->target);
if (!cache)
return 0;
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 9152ad2..78a84f5 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -362,13 +362,38 @@ probe_cache_entry__new(struct perf_probe_event *pev)
return entry;
}
-/* For the kernel probe caches, pass target = NULL */
+int probe_cache_entry__get_event(struct probe_cache_entry *entry,
+ struct probe_trace_event **tevs)
+{
+ struct probe_trace_event *tev;
+ struct str_node *node;
+ int ret, i;
+
+ ret = strlist__nr_entries(entry->tevlist);
+ if (ret > probe_conf.max_probes)
+ return -E2BIG;
+
+ *tevs = zalloc(ret * sizeof(*tev));
+ if (!*tevs)
+ return -ENOMEM;
+
+ i = 0;
+ strlist__for_each_entry(node, entry->tevlist) {
+ tev = &(*tevs)[i++];
+ ret = parse_probe_trace_command(node->s, tev);
+ if (ret < 0)
+ break;
+ }
+ return i;
+}
+
+/* For the kernel probe caches, pass target = NULL or DSO__NAME_KALLSYMS */
static int probe_cache__open(struct probe_cache *pcache, const char *target)
{
char cpath[PATH_MAX];
char sbuildid[SBUILD_ID_SIZE];
char *dir_name = NULL;
- bool is_kallsyms = !target;
+ bool is_kallsyms = false;
int ret, fd;
if (target && build_id_cache__cached(target)) {
@@ -378,12 +403,13 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target)
goto found;
}
- if (target)
- ret = filename__sprintf_build_id(target, sbuildid);
- else {
+ if (!target || !strcmp(target, DSO__NAME_KALLSYMS)) {
target = DSO__NAME_KALLSYMS;
+ is_kallsyms = true;
ret = sysfs__sprintf_build_id("/", sbuildid);
- }
+ } else
+ ret = filename__sprintf_build_id(target, sbuildid);
+
if (ret < 0) {
pr_debug("Failed to get build-id from %s.\n", target);
return ret;
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index d513b34..cafbe1d 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -34,6 +34,9 @@ int probe_file__get_events(int fd, struct strfilter *filter,
struct strlist *plist);
int probe_file__del_strlist(int fd, struct strlist *namelist);
+int probe_cache_entry__get_event(struct probe_cache_entry *entry,
+ struct probe_trace_event **tevs);
+
struct probe_cache *probe_cache__new(const char *target);
int probe_cache__add_entry(struct probe_cache *pcache,
struct perf_probe_event *pev,
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-07-13 21:40 +0200 |
| Subject | Re: [PATCH perf/core 05/10] perf probe: Allow wildcard for cached events |
| Message-ID | <rUyaJ-7qt-11@gated-at.bofh.it> |
| In reply to | #1441214 |
Em Tue, Jul 12, 2016 at 07:05:18PM +0900, Masami Hiramatsu escreveu:
> Allo glob wildcard for reusing cached/SDT events. E.g.
>
> # perf probe -x /usr/lib64/libc-2.20.so -a %sdt_libc:\*
The example message for this could be improved to also use a wildcard
:-)
> This example adds probes for all SDT in libc.
> Note that the SDTs must have been scanned by perf buildid-cache.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
> Changes in v12:
> - Rename strlist__for_each to strlist__for_each_entry.
> Changes in v10:
> - Split off bugfix, adding interface, and target search patches.
> - Do not export clear_probe_trace_events().
> Changes in v7:
> - Continue to search caches if a build-id cache has no probe cache.
> - Make probe_cache__open() to accept DSO__NAME_KALLSYMS for kernel.
> - Fix to add probes correctly when a wildcard matchs both of
> uprobes and kprobes.
> Changes in v5.1:
> - Fix a SEGV bug when a group name is omitted. (Thanks Hemant!)
> ---
> tools/perf/util/probe-event.c | 107 +++++++++++++++++++++++++++++++++++++++--
> tools/perf/util/probe-file.c | 38 ++++++++++++---
> tools/perf/util/probe-file.h | 3 +
> 3 files changed, 138 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 3642cca..1aeac09 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -1204,7 +1204,7 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
> ptr = strchr(*arg, ':');
> if (ptr) {
> *ptr = '\0';
> - if (!is_c_func_name(*arg))
> + if (!pev->sdt && !is_c_func_name(*arg))
> goto ng_name;
> pev->group = strdup(*arg);
> if (!pev->group)
> @@ -1212,7 +1212,7 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
> *arg = ptr + 1;
> } else
> pev->group = NULL;
> - if (!is_c_func_name(*arg)) {
> + if (!pev->sdt && !is_c_func_name(*arg)) {
> ng_name:
> semantic_error("%s is bad for event name -it must "
> "follow C symbol-naming rule.\n", *arg);
> @@ -1644,6 +1644,7 @@ int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
> ret = -ENOMEM;
> goto out;
> }
> + tev->uprobes = (tp->module[0] == '/');
> p++;
> } else
> p = argv[1];
> @@ -2518,7 +2519,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
> int ret;
>
> /* If probe_event or trace_event already have the name, reuse it */
> - if (pev->event)
> + if (pev->event && !pev->sdt)
> event = pev->event;
> else if (tev->event)
> event = tev->event;
> @@ -2531,7 +2532,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
> else
> event = tev->point.realname;
> }
> - if (pev->group)
> + if (pev->group && !pev->sdt)
> group = pev->group;
> else if (tev->group)
> group = tev->group;
> @@ -2894,6 +2895,100 @@ errout:
>
> bool __weak arch__prefers_symtab(void) { return false; }
>
> +/* Concatinate two arrays */
> +static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b)
> +{
> + void *ret;
> +
> + ret = malloc(sz_a + sz_b);
> + if (ret) {
> + memcpy(ret, a, sz_a);
> + memcpy(ret + sz_a, b, sz_b);
> + }
> + return ret;
> +}
> +
> +static int
> +concat_probe_trace_events(struct probe_trace_event **tevs, int *ntevs,
> + struct probe_trace_event **tevs2, int ntevs2)
> +{
> + struct probe_trace_event *new_tevs;
> + int ret = 0;
> +
> + if (ntevs == 0) {
> + *tevs = *tevs2;
> + *ntevs = ntevs2;
> + *tevs2 = NULL;
> + return 0;
> + }
> +
> + if (*ntevs + ntevs2 > probe_conf.max_probes)
> + ret = -E2BIG;
> + else {
> + /* Concatinate the array of probe_trace_event */
> + new_tevs = memcat(*tevs, (*ntevs) * sizeof(**tevs),
> + *tevs2, ntevs2 * sizeof(**tevs2));
> + if (!new_tevs)
> + ret = -ENOMEM;
> + else {
> + free(*tevs);
> + *tevs = new_tevs;
> + *ntevs += ntevs2;
> + }
> + }
> + if (ret < 0)
> + clear_probe_trace_events(*tevs2, ntevs2);
> + zfree(tevs2);
> +
> + return ret;
> +}
> +
> +/*
> + * Try to find probe_trace_event from given probe caches. Return the number
> + * of cached events found, if an error occurs return the error.
> + */
> +static int find_cached_events(struct perf_probe_event *pev,
> + struct probe_trace_event **tevs,
> + const char *target)
> +{
> + struct probe_cache *cache;
> + struct probe_cache_entry *entry;
> + struct probe_trace_event *tmp_tevs = NULL;
> + int ntevs = 0;
> + int ret = 0;
> +
> + cache = probe_cache__new(target);
> + /* Return 0 ("not found") if the target has no probe cache. */
> + if (!cache)
> + return 0;
> +
> + for_each_probe_cache_entry(entry, cache) {
> + /* Skip the cache entry which has no name */
> + if (!entry->pev.event || !entry->pev.group)
> + continue;
> + if ((!pev->group || strglobmatch(entry->pev.group, pev->group)) &&
> + strglobmatch(entry->pev.event, pev->event)) {
> + ret = probe_cache_entry__get_event(entry, &tmp_tevs);
> + if (ret > 0)
> + ret = concat_probe_trace_events(tevs, &ntevs,
> + &tmp_tevs, ret);
> + if (ret < 0)
> + break;
> + }
> + }
> + probe_cache__delete(cache);
> + if (ret < 0) {
> + clear_probe_trace_events(*tevs, ntevs);
> + zfree(tevs);
> + } else {
> + ret = ntevs;
> + if (ntevs > 0 && target && target[0] == '/')
> + pev->uprobes = true;
> + }
> +
> + return ret;
> +}
> +
> static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
> struct probe_trace_event **tevs)
> {
> @@ -2903,6 +2998,10 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
> struct str_node *node;
> int ret, i;
>
> + if (pev->sdt)
> + /* For SDT/cached events, we use special search functions */
> + return find_cached_events(pev, tevs, pev->target);
> +
> cache = probe_cache__new(pev->target);
> if (!cache)
> return 0;
> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> index 9152ad2..78a84f5 100644
> --- a/tools/perf/util/probe-file.c
> +++ b/tools/perf/util/probe-file.c
> @@ -362,13 +362,38 @@ probe_cache_entry__new(struct perf_probe_event *pev)
> return entry;
> }
>
> -/* For the kernel probe caches, pass target = NULL */
> +int probe_cache_entry__get_event(struct probe_cache_entry *entry,
> + struct probe_trace_event **tevs)
> +{
> + struct probe_trace_event *tev;
> + struct str_node *node;
> + int ret, i;
> +
> + ret = strlist__nr_entries(entry->tevlist);
> + if (ret > probe_conf.max_probes)
> + return -E2BIG;
> +
> + *tevs = zalloc(ret * sizeof(*tev));
> + if (!*tevs)
> + return -ENOMEM;
> +
> + i = 0;
> + strlist__for_each_entry(node, entry->tevlist) {
> + tev = &(*tevs)[i++];
> + ret = parse_probe_trace_command(node->s, tev);
> + if (ret < 0)
> + break;
> + }
> + return i;
> +}
> +
> +/* For the kernel probe caches, pass target = NULL or DSO__NAME_KALLSYMS */
> static int probe_cache__open(struct probe_cache *pcache, const char *target)
> {
> char cpath[PATH_MAX];
> char sbuildid[SBUILD_ID_SIZE];
> char *dir_name = NULL;
> - bool is_kallsyms = !target;
> + bool is_kallsyms = false;
> int ret, fd;
>
> if (target && build_id_cache__cached(target)) {
> @@ -378,12 +403,13 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target)
> goto found;
> }
>
> - if (target)
> - ret = filename__sprintf_build_id(target, sbuildid);
> - else {
> + if (!target || !strcmp(target, DSO__NAME_KALLSYMS)) {
> target = DSO__NAME_KALLSYMS;
> + is_kallsyms = true;
> ret = sysfs__sprintf_build_id("/", sbuildid);
> - }
> + } else
> + ret = filename__sprintf_build_id(target, sbuildid);
> +
> if (ret < 0) {
> pr_debug("Failed to get build-id from %s.\n", target);
> return ret;
> diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
> index d513b34..cafbe1d 100644
> --- a/tools/perf/util/probe-file.h
> +++ b/tools/perf/util/probe-file.h
> @@ -34,6 +34,9 @@ int probe_file__get_events(int fd, struct strfilter *filter,
> struct strlist *plist);
> int probe_file__del_strlist(int fd, struct strlist *namelist);
>
> +int probe_cache_entry__get_event(struct probe_cache_entry *entry,
> + struct probe_trace_event **tevs);
> +
> struct probe_cache *probe_cache__new(const char *target);
> int probe_cache__add_entry(struct probe_cache *pcache,
> struct perf_probe_event *pev,
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Masami Hiramatsu <tipbot@zytor.com> |
|---|---|
| Date | 2016-07-14 09:10 +0200 |
| Subject | [tip:perf/core] perf probe: Allow wildcard for cached events |
| Message-ID | <rUIWt-6o9-1@gated-at.bofh.it> |
| In reply to | #1441214 |
Commit-ID: 42bba263eb58800b6239a0cb35ac17fd29379277
Gitweb: http://git.kernel.org/tip/42bba263eb58800b6239a0cb35ac17fd29379277
Author: Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Tue, 12 Jul 2016 19:05:18 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Jul 2016 23:09:07 -0300
perf probe: Allow wildcard for cached events
Allo glob wildcard for reusing cached/SDT events. E.g.
# perf probe -x /usr/lib64/libc-2.20.so -a %sdt_libc:\*
This example adds probes for all SDT in libc.
Note that the SDTs must have been scanned by perf buildid-cache.
Committer note:
Using it to check what of those SDT probes would take place when doing
a cargo run (rust):
# trace --no-sys --event sdt_libc:* cargo run
0.000 sdt_libc:setjmp:(7f326b69c4d1))
28.423 sdt_libc:setjmp:(7f4b0a5364d1))
29.000 sdt_libc:setjmp:(7f4b0a5364d1))
88.597 sdt_libc:setjmp:(7fc01fd414d1))
89.220 sdt_libc:setjmp:(7fc01fd414d1))
95.501 sdt_libc:setjmp:(7f326b69c4d1))
Running `target/debug/hello_world`
97.110 sdt_libc:setjmp:(7f95e09234d1))
Hello, world!
#
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/146831791813.17065.17846564230840594888.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 107 ++++++++++++++++++++++++++++++++++++++++--
tools/perf/util/probe-file.c | 38 ++++++++++++---
tools/perf/util/probe-file.h | 3 ++
3 files changed, 138 insertions(+), 10 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 85f25d4..7b96e68 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1204,7 +1204,7 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
ptr = strchr(*arg, ':');
if (ptr) {
*ptr = '\0';
- if (!is_c_func_name(*arg))
+ if (!pev->sdt && !is_c_func_name(*arg))
goto ng_name;
pev->group = strdup(*arg);
if (!pev->group)
@@ -1212,7 +1212,7 @@ static int parse_perf_probe_event_name(char **arg, struct perf_probe_event *pev)
*arg = ptr + 1;
} else
pev->group = NULL;
- if (!is_c_func_name(*arg)) {
+ if (!pev->sdt && !is_c_func_name(*arg)) {
ng_name:
semantic_error("%s is bad for event name -it must "
"follow C symbol-naming rule.\n", *arg);
@@ -1644,6 +1644,7 @@ int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev)
ret = -ENOMEM;
goto out;
}
+ tev->uprobes = (tp->module[0] == '/');
p++;
} else
p = argv[1];
@@ -2518,7 +2519,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
int ret;
/* If probe_event or trace_event already have the name, reuse it */
- if (pev->event)
+ if (pev->event && !pev->sdt)
event = pev->event;
else if (tev->event)
event = tev->event;
@@ -2531,7 +2532,7 @@ static int probe_trace_event__set_name(struct probe_trace_event *tev,
else
event = tev->point.realname;
}
- if (pev->group)
+ if (pev->group && !pev->sdt)
group = pev->group;
else if (tev->group)
group = tev->group;
@@ -2894,6 +2895,100 @@ errout:
bool __weak arch__prefers_symtab(void) { return false; }
+/* Concatinate two arrays */
+static void *memcat(void *a, size_t sz_a, void *b, size_t sz_b)
+{
+ void *ret;
+
+ ret = malloc(sz_a + sz_b);
+ if (ret) {
+ memcpy(ret, a, sz_a);
+ memcpy(ret + sz_a, b, sz_b);
+ }
+ return ret;
+}
+
+static int
+concat_probe_trace_events(struct probe_trace_event **tevs, int *ntevs,
+ struct probe_trace_event **tevs2, int ntevs2)
+{
+ struct probe_trace_event *new_tevs;
+ int ret = 0;
+
+ if (ntevs == 0) {
+ *tevs = *tevs2;
+ *ntevs = ntevs2;
+ *tevs2 = NULL;
+ return 0;
+ }
+
+ if (*ntevs + ntevs2 > probe_conf.max_probes)
+ ret = -E2BIG;
+ else {
+ /* Concatinate the array of probe_trace_event */
+ new_tevs = memcat(*tevs, (*ntevs) * sizeof(**tevs),
+ *tevs2, ntevs2 * sizeof(**tevs2));
+ if (!new_tevs)
+ ret = -ENOMEM;
+ else {
+ free(*tevs);
+ *tevs = new_tevs;
+ *ntevs += ntevs2;
+ }
+ }
+ if (ret < 0)
+ clear_probe_trace_events(*tevs2, ntevs2);
+ zfree(tevs2);
+
+ return ret;
+}
+
+/*
+ * Try to find probe_trace_event from given probe caches. Return the number
+ * of cached events found, if an error occurs return the error.
+ */
+static int find_cached_events(struct perf_probe_event *pev,
+ struct probe_trace_event **tevs,
+ const char *target)
+{
+ struct probe_cache *cache;
+ struct probe_cache_entry *entry;
+ struct probe_trace_event *tmp_tevs = NULL;
+ int ntevs = 0;
+ int ret = 0;
+
+ cache = probe_cache__new(target);
+ /* Return 0 ("not found") if the target has no probe cache. */
+ if (!cache)
+ return 0;
+
+ for_each_probe_cache_entry(entry, cache) {
+ /* Skip the cache entry which has no name */
+ if (!entry->pev.event || !entry->pev.group)
+ continue;
+ if ((!pev->group || strglobmatch(entry->pev.group, pev->group)) &&
+ strglobmatch(entry->pev.event, pev->event)) {
+ ret = probe_cache_entry__get_event(entry, &tmp_tevs);
+ if (ret > 0)
+ ret = concat_probe_trace_events(tevs, &ntevs,
+ &tmp_tevs, ret);
+ if (ret < 0)
+ break;
+ }
+ }
+ probe_cache__delete(cache);
+ if (ret < 0) {
+ clear_probe_trace_events(*tevs, ntevs);
+ zfree(tevs);
+ } else {
+ ret = ntevs;
+ if (ntevs > 0 && target && target[0] == '/')
+ pev->uprobes = true;
+ }
+
+ return ret;
+}
+
static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
struct probe_trace_event **tevs)
{
@@ -2903,6 +2998,10 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
struct str_node *node;
int ret, i;
+ if (pev->sdt)
+ /* For SDT/cached events, we use special search functions */
+ return find_cached_events(pev, tevs, pev->target);
+
cache = probe_cache__new(pev->target);
if (!cache)
return 0;
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index abfb05c..9aed9c3 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -362,13 +362,38 @@ probe_cache_entry__new(struct perf_probe_event *pev)
return entry;
}
-/* For the kernel probe caches, pass target = NULL */
+int probe_cache_entry__get_event(struct probe_cache_entry *entry,
+ struct probe_trace_event **tevs)
+{
+ struct probe_trace_event *tev;
+ struct str_node *node;
+ int ret, i;
+
+ ret = strlist__nr_entries(entry->tevlist);
+ if (ret > probe_conf.max_probes)
+ return -E2BIG;
+
+ *tevs = zalloc(ret * sizeof(*tev));
+ if (!*tevs)
+ return -ENOMEM;
+
+ i = 0;
+ strlist__for_each_entry(node, entry->tevlist) {
+ tev = &(*tevs)[i++];
+ ret = parse_probe_trace_command(node->s, tev);
+ if (ret < 0)
+ break;
+ }
+ return i;
+}
+
+/* For the kernel probe caches, pass target = NULL or DSO__NAME_KALLSYMS */
static int probe_cache__open(struct probe_cache *pcache, const char *target)
{
char cpath[PATH_MAX];
char sbuildid[SBUILD_ID_SIZE];
char *dir_name = NULL;
- bool is_kallsyms = !target;
+ bool is_kallsyms = false;
int ret, fd;
if (target && build_id_cache__cached(target)) {
@@ -378,12 +403,13 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target)
goto found;
}
- if (target)
- ret = filename__sprintf_build_id(target, sbuildid);
- else {
+ if (!target || !strcmp(target, DSO__NAME_KALLSYMS)) {
target = DSO__NAME_KALLSYMS;
+ is_kallsyms = true;
ret = sysfs__sprintf_build_id("/", sbuildid);
- }
+ } else
+ ret = filename__sprintf_build_id(target, sbuildid);
+
if (ret < 0) {
pr_debug("Failed to get build-id from %s.\n", target);
return ret;
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index d513b34..cafbe1d 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -34,6 +34,9 @@ int probe_file__get_events(int fd, struct strfilter *filter,
struct strlist *plist);
int probe_file__del_strlist(int fd, struct strlist *namelist);
+int probe_cache_entry__get_event(struct probe_cache_entry *entry,
+ struct probe_trace_event **tevs);
+
struct probe_cache *probe_cache__new(const char *target);
int probe_cache__add_entry(struct probe_cache *pcache,
struct perf_probe_event *pev,
[toc] | [prev] | [next] | [standalone]
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Date | 2016-07-12 12:10 +0200 |
| Subject | [PATCH perf/core 02/10] perf probe: Accept %sdt and %cached event name |
| Message-ID | <rU2NC-3tA-77@gated-at.bofh.it> |
| In reply to | #1441198 |
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
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:
sdt_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 sdt_libc:lll_lock_wait_private -aR sleep 1
# perf probe -l | more
sdt_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 <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Changes in v10:
- Update Documentation/perf-probe.txt to add a link about SDT.
Changes in v7:
- Fix a bug to return an error if no SDT/cached events found in cache.
---
tools/perf/Documentation/perf-probe.txt | 9 +++
tools/perf/util/probe-event.c | 82 ++++++++++++++++++++++---------
tools/perf/util/probe-event.h | 1
tools/perf/util/probe-file.c | 9 +++
4 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 7a258e9..39e3870 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -151,6 +151,8 @@ Probe points are defined by following syntax.
3) Define event based on source file with lazy pattern
[[GROUP:]EVENT=]SRC;PTN [ARG ...]
+ 4) Pre-defined SDT events or cached event with name
+ %[PROVIDER:]SDTEVENT
'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. You can also specify a group name by 'GROUP', if omitted, set 'probe' is used for kprobe and 'probe_<bin>' is used for uprobe.
Note that using existing group name can conflict with other events. Especially, using the group name reserved for kernel modules can hide embedded events in the
@@ -158,6 +160,11 @@ modules.
'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.
+Note that before using the SDT event, the target binary (on which SDT events are defined) must be scanned by linkperf:perf-buildid-cache[1] to make SDT events as cached events.
+
+For details of the SDT, see below.
+https://sourceware.org/gdb/onlinedocs/gdb/Static-Probe-Points.html
PROBE ARGUMENT
--------------
@@ -237,4 +244,4 @@ Add probes at malloc() function on libc
SEE ALSO
--------
-linkperf:perf-trace[1], linkperf:perf-record[1]
+linkperf:perf-trace[1], linkperf:perf-record[1], linkperf:perf-buildid-cache[1]
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index dff9a54..3642cca 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1197,6 +1197,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)
{
@@ -1204,38 +1232,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;
}
@@ -2876,7 +2909,8 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
entry = probe_cache__find(cache, pev);
if (!entry) {
- ret = 0;
+ /* SDT must be in the cache */
+ ret = pev->sdt ? -ENOENT : 0;
goto out;
}
@@ -2915,7 +2949,7 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
{
int ret;
- if (!pev->group) {
+ if (!pev->group && !pev->sdt) {
/* Set group name if not given */
if (!pev->uprobes) {
pev->group = strdup(PERFPROBE_GROUP);
@@ -2934,8 +2968,8 @@ 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 (ret > 0 || pev->sdt) /* SDT can be found only in the cache */
+ return ret == 0 ? -ENOENT : ret; /* Found in probe cache */
if (arch__prefers_symtab() && !perf_probe_event_need_dwarf(pev)) {
ret = find_probe_trace_events_from_map(pev, tevs);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 432b690..e18ea9f 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -85,6 +85,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 5b563b2..b642d06 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -547,6 +547,15 @@ probe_cache__find(struct probe_cache *pcache, struct perf_probe_event *pev)
return NULL;
list_for_each_entry(entry, &pcache->entries, node) {
+ 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) &&
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Masami Hiramatsu <tipbot@zytor.com> |
|---|---|
| Date | 2016-07-14 09:10 +0200 |
| Subject | [tip:perf/core] perf probe: Accept %sdt and %cached event name |
| Message-ID | <rUIWt-6o9-3@gated-at.bofh.it> |
| In reply to | #1441219 |
Commit-ID: 36a009fe07bdecd201335f982babb8af34b603e2
Gitweb: http://git.kernel.org/tip/36a009fe07bdecd201335f982babb8af34b603e2
Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
AuthorDate: Tue, 12 Jul 2016 19:04:43 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Jul 2016 23:09:05 -0300
perf probe: Accept %sdt and %cached event name
To improve 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:
sdt_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 sdt_libc:lll_lock_wait_private -aR sleep 1
# perf probe -l | more
sdt_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 <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/146831788372.17065.3645054540325909346.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-probe.txt | 9 +++-
tools/perf/util/probe-event.c | 82 +++++++++++++++++++++++----------
tools/perf/util/probe-event.h | 1 +
tools/perf/util/probe-file.c | 9 ++++
4 files changed, 76 insertions(+), 25 deletions(-)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 7a258e9..39e3870 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -151,6 +151,8 @@ Probe points are defined by following syntax.
3) Define event based on source file with lazy pattern
[[GROUP:]EVENT=]SRC;PTN [ARG ...]
+ 4) Pre-defined SDT events or cached event with name
+ %[PROVIDER:]SDTEVENT
'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. You can also specify a group name by 'GROUP', if omitted, set 'probe' is used for kprobe and 'probe_<bin>' is used for uprobe.
Note that using existing group name can conflict with other events. Especially, using the group name reserved for kernel modules can hide embedded events in the
@@ -158,6 +160,11 @@ modules.
'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.
+Note that before using the SDT event, the target binary (on which SDT events are defined) must be scanned by linkperf:perf-buildid-cache[1] to make SDT events as cached events.
+
+For details of the SDT, see below.
+https://sourceware.org/gdb/onlinedocs/gdb/Static-Probe-Points.html
PROBE ARGUMENT
--------------
@@ -237,4 +244,4 @@ Add probes at malloc() function on libc
SEE ALSO
--------
-linkperf:perf-trace[1], linkperf:perf-record[1]
+linkperf:perf-trace[1], linkperf:perf-record[1], linkperf:perf-buildid-cache[1]
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index fef9768..85f25d4 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1197,6 +1197,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)
{
@@ -1204,38 +1232,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;
}
@@ -2876,7 +2909,8 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
entry = probe_cache__find(cache, pev);
if (!entry) {
- ret = 0;
+ /* SDT must be in the cache */
+ ret = pev->sdt ? -ENOENT : 0;
goto out;
}
@@ -2915,7 +2949,7 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
{
int ret;
- if (!pev->group) {
+ if (!pev->group && !pev->sdt) {
/* Set group name if not given */
if (!pev->uprobes) {
pev->group = strdup(PERFPROBE_GROUP);
@@ -2934,8 +2968,8 @@ 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 (ret > 0 || pev->sdt) /* SDT can be found only in the cache */
+ return ret == 0 ? -ENOENT : ret; /* Found in probe cache */
if (arch__prefers_symtab() && !perf_probe_event_need_dwarf(pev)) {
ret = find_probe_trace_events_from_map(pev, tevs);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 432b690..e18ea9f 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -85,6 +85,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 e705a74..fc16b17 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -547,6 +547,15 @@ probe_cache__find(struct probe_cache *pcache, struct perf_probe_event *pev)
return NULL;
list_for_each_entry(entry, &pcache->entries, node) {
+ 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) &&
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-07-14 03:40 +0200 |
| Message-ID | <rUDN7-2JJ-1@gated-at.bofh.it> |
| In reply to | #1441198 |
Em Tue, Jul 12, 2016 at 07:04:23PM +0900, Masami Hiramatsu escreveu: > Hi, > > Here is the 14th version of the patchset for probe-cache and > initial SDT support. > > Here is the previous v13: https://lkml.org/lkml/2016/7/1/133 Ok, applied it and also one that you missed in this set, the one adding 'perf list sdt', that I rebased and tested, Thanks, - Arnaldo > This version includes patches which not merged yet. This also > adds a bugfix; > - [1/10] Resend the bugfix patch which was sent 4th July. > (https://lkml.org/lkml/2016/7/3/217) > > Thank you, > > --- > > Masami Hiramatsu (10): > [BUGFIX] perf-probe: Fix to show correct error message for $vars and $params > perf probe: Accept %sdt and %cached event name > perf-probe: Make --list shows only available cached events > perf: probe-cache: Add for_each_probe_cache_entry() wrapper > perf probe: Allow wildcard for cached events > perf probe: Search SDT/cached event from all probe caches > perf probe: Support @BUILDID or @FILE suffix for SDT events > perf probe: Support a special SDT probe format > perf build: Add sdt feature detection > perf-test: Add a test case for SDT event > > > tools/perf/Documentation/perf-probe.txt | 11 + > tools/perf/Makefile.perf | 3 > tools/perf/builtin-probe.c | 2 > tools/perf/config/Makefile | 10 + > tools/perf/tests/Build | 1 > tools/perf/tests/builtin-test.c | 4 > tools/perf/tests/make | 3 > tools/perf/tests/sdt.c | 115 ++++++++++++ > tools/perf/tests/tests.h | 1 > tools/perf/util/build-id.c | 76 ++++++++ > tools/perf/util/build-id.h | 3 > tools/perf/util/probe-event.c | 309 +++++++++++++++++++++++++++---- > tools/perf/util/probe-event.h | 1 > tools/perf/util/probe-file.c | 57 +++++- > tools/perf/util/probe-file.h | 5 + > 15 files changed, 542 insertions(+), 59 deletions(-) > create mode 100644 tools/perf/tests/sdt.c > > -- > Masami Hiramatsu
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | linux.kernel
csiph-web