Re: [PATCH perf/core v13 02/15] perf probe: Show all cached probes
On Fri, 1 Jul 2016 10:51:04 -0300 Arnaldo Carvalho de Melowrote: > Em Fri, Jul 01, 2016 at 05:03:26PM +0900, Masami Hiramatsu escreveu: > > From: Masami Hiramatsu > > > > 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 > > This one works: > > # perf probe --cache vfs_read \$params > Added new event: > probe:vfs_read (on vfs_read with $params) > > You can now use it in all perf tools, such as: > > perf record -e probe:vfs_read -aR sleep 1 > > # > > > # perf probe --cache -x /lib64/libc-2.17.so getaddrinfo \$params > > But this one doesn't and provides a funny message: > > [root@jouet perf]# perf probe --cache -x /lib64/libc-2.23.so getaddrinfo > \$params > Failed to write event: Invalid argument > Please upgrade your kernel to at least 3.14 to have access to feature $params > Error: Failed to add events. Ah, OK, $params requires debuginfo. It this error message is not correct. I'll send a fix soon. Thanks!! -- Masami Hiramatsu
Re: [PATCH perf/core v13 02/15] perf probe: Show all cached probes
On Fri, 1 Jul 2016 10:51:04 -0300 Arnaldo Carvalho de Melo wrote: > Em Fri, Jul 01, 2016 at 05:03:26PM +0900, Masami Hiramatsu escreveu: > > From: Masami Hiramatsu > > > > 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 > > This one works: > > # perf probe --cache vfs_read \$params > Added new event: > probe:vfs_read (on vfs_read with $params) > > You can now use it in all perf tools, such as: > > perf record -e probe:vfs_read -aR sleep 1 > > # > > > # perf probe --cache -x /lib64/libc-2.17.so getaddrinfo \$params > > But this one doesn't and provides a funny message: > > [root@jouet perf]# perf probe --cache -x /lib64/libc-2.23.so getaddrinfo > \$params > Failed to write event: Invalid argument > Please upgrade your kernel to at least 3.14 to have access to feature $params > Error: Failed to add events. Ah, OK, $params requires debuginfo. It this error message is not correct. I'll send a fix soon. Thanks!! -- Masami Hiramatsu
Re: [PATCH perf/core v13 02/15] perf probe: Show all cached probes
Em Fri, Jul 01, 2016 at 05:03:26PM +0900, Masami Hiramatsu escreveu: > From: Masami Hiramatsu> > 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 This one works: # perf probe --cache vfs_read \$params Added new event: probe:vfs_read (on vfs_read with $params) You can now use it in all perf tools, such as: perf record -e probe:vfs_read -aR sleep 1 # > # perf probe --cache -x /lib64/libc-2.17.so getaddrinfo \$params But this one doesn't and provides a funny message: [root@jouet perf]# perf probe --cache -x /lib64/libc-2.23.so getaddrinfo \$params Failed to write event: Invalid argument Please upgrade your kernel to at least 3.14 to have access to feature $params Error: Failed to add events. [root@jouet perf]# [root@jouet perf]# uname -a Linux jouet 4.5.7-300.fc24.x86_64 #1 SMP Wed Jun 8 18:12:45 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux [root@jouet perf]# cat /etc/fedora-release Fedora release 24 (Twenty Four) [root@jouet perf]# - Arnaldo > # 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 > Signed-off-by: Masami Hiramatsu > --- > Changes in v12: > - Rename strlist__for_each to strlist__for_each_entry. > Changes in v11: > - Make build_id_cache__list_all() returns strlist directly. (no error code) > - Harden build_id_cache__list_all() to check directory entries. > Changes in v7: > - Remove the top '/' from binary name if it is not a regular file. > --- > tools/perf/Documentation/perf-probe.txt |8 ++ > tools/perf/builtin-probe.c |2 - > tools/perf/util/build-id.c | 108 > ++- > tools/perf/util/build-id.h |3 + > tools/perf/util/probe-event.c |3 + > tools/perf/util/probe-file.c| 66 ++- > tools/perf/util/probe-file.h|1 > 7 files changed, 184 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 3426232..0bb9084 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 62b1473..1c49620 100644 > --- a/tools/perf/util/build-id.c > +++ b/tools/perf/util/build-id.c > @@ -165,8 +165,7 @@ retry: > return NULL; > } > > -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(, size, "%s/.build-id/%.2s/%s", buildid_dir, > @@ -176,6 +175,36 @@ 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; > + size_t offs = 5;/* == strlen("../..") */ > + > + 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 "../../" */ > + p = strrchr(buf, '/'); /* Cut off
Re: [PATCH perf/core v13 02/15] perf probe: Show all cached probes
Em Fri, Jul 01, 2016 at 05:03:26PM +0900, Masami Hiramatsu escreveu: > From: Masami Hiramatsu > > 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 This one works: # perf probe --cache vfs_read \$params Added new event: probe:vfs_read (on vfs_read with $params) You can now use it in all perf tools, such as: perf record -e probe:vfs_read -aR sleep 1 # > # perf probe --cache -x /lib64/libc-2.17.so getaddrinfo \$params But this one doesn't and provides a funny message: [root@jouet perf]# perf probe --cache -x /lib64/libc-2.23.so getaddrinfo \$params Failed to write event: Invalid argument Please upgrade your kernel to at least 3.14 to have access to feature $params Error: Failed to add events. [root@jouet perf]# [root@jouet perf]# uname -a Linux jouet 4.5.7-300.fc24.x86_64 #1 SMP Wed Jun 8 18:12:45 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux [root@jouet perf]# cat /etc/fedora-release Fedora release 24 (Twenty Four) [root@jouet perf]# - Arnaldo > # 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 > Signed-off-by: Masami Hiramatsu > --- > Changes in v12: > - Rename strlist__for_each to strlist__for_each_entry. > Changes in v11: > - Make build_id_cache__list_all() returns strlist directly. (no error code) > - Harden build_id_cache__list_all() to check directory entries. > Changes in v7: > - Remove the top '/' from binary name if it is not a regular file. > --- > tools/perf/Documentation/perf-probe.txt |8 ++ > tools/perf/builtin-probe.c |2 - > tools/perf/util/build-id.c | 108 > ++- > tools/perf/util/build-id.h |3 + > tools/perf/util/probe-event.c |3 + > tools/perf/util/probe-file.c| 66 ++- > tools/perf/util/probe-file.h|1 > 7 files changed, 184 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 3426232..0bb9084 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 62b1473..1c49620 100644 > --- a/tools/perf/util/build-id.c > +++ b/tools/perf/util/build-id.c > @@ -165,8 +165,7 @@ retry: > return NULL; > } > > -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(, size, "%s/.build-id/%.2s/%s", buildid_dir, > @@ -176,6 +175,36 @@ 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; > + size_t offs = 5;/* == strlen("../..") */ > + > + 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 "../../" */ > + p = strrchr(buf, '/'); /* Cut off the "/" */ > + if (p && (p > buf + offs)) { > + *p = '\0'; > +
[PATCH perf/core v13 02/15] perf probe: Show all cached probes
From: Masami Hiramatsuperf 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 Signed-off-by: Masami Hiramatsu --- Changes in v12: - Rename strlist__for_each to strlist__for_each_entry. Changes in v11: - Make build_id_cache__list_all() returns strlist directly. (no error code) - Harden build_id_cache__list_all() to check directory entries. Changes in v7: - Remove the top '/' from binary name if it is not a regular file. --- tools/perf/Documentation/perf-probe.txt |8 ++ tools/perf/builtin-probe.c |2 - tools/perf/util/build-id.c | 108 ++- tools/perf/util/build-id.h |3 + tools/perf/util/probe-event.c |3 + tools/perf/util/probe-file.c| 66 ++- tools/perf/util/probe-file.h|1 7 files changed, 184 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 3426232..0bb9084 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 62b1473..1c49620 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -165,8 +165,7 @@ retry: return NULL; } -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(, size, "%s/.build-id/%.2s/%s", buildid_dir, @@ -176,6 +175,36 @@ 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; + size_t offs = 5;/* == strlen("../..") */ + + 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 "../../" */ + p = strrchr(buf, '/'); /* Cut off the "/" */ + if (p && (p > buf + offs)) { + *p = '\0'; + if (buf[offs + 1] == '[') + offs++; /* +* This is a DSO name, like [kernel.kallsyms]. +* Skip the first '/', since this is not the +* cache of a regular file. +*/ + ret = strdup(buf + offs); /* 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"); @@ -387,6 +416,81 @@ void disable_buildid_cache(void) no_buildid_cache = true; } +static bool lsdir_bid_head_filter(const char *name __maybe_unused, + struct dirent *d __maybe_unused) +{ + return (strlen(d->d_name) == 2) && + isxdigit(d->d_name[0]) &&
[PATCH perf/core v13 02/15] perf probe: Show all cached probes
From: Masami Hiramatsu 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 Signed-off-by: Masami Hiramatsu --- Changes in v12: - Rename strlist__for_each to strlist__for_each_entry. Changes in v11: - Make build_id_cache__list_all() returns strlist directly. (no error code) - Harden build_id_cache__list_all() to check directory entries. Changes in v7: - Remove the top '/' from binary name if it is not a regular file. --- tools/perf/Documentation/perf-probe.txt |8 ++ tools/perf/builtin-probe.c |2 - tools/perf/util/build-id.c | 108 ++- tools/perf/util/build-id.h |3 + tools/perf/util/probe-event.c |3 + tools/perf/util/probe-file.c| 66 ++- tools/perf/util/probe-file.h|1 7 files changed, 184 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 3426232..0bb9084 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 62b1473..1c49620 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -165,8 +165,7 @@ retry: return NULL; } -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(, size, "%s/.build-id/%.2s/%s", buildid_dir, @@ -176,6 +175,36 @@ 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; + size_t offs = 5;/* == strlen("../..") */ + + 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 "../../" */ + p = strrchr(buf, '/'); /* Cut off the "/" */ + if (p && (p > buf + offs)) { + *p = '\0'; + if (buf[offs + 1] == '[') + offs++; /* +* This is a DSO name, like [kernel.kallsyms]. +* Skip the first '/', since this is not the +* cache of a regular file. +*/ + ret = strdup(buf + offs); /* 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"); @@ -387,6 +416,81 @@ void disable_buildid_cache(void) no_buildid_cache = true; } +static bool lsdir_bid_head_filter(const char *name __maybe_unused, + struct dirent *d __maybe_unused) +{ + return (strlen(d->d_name) == 2) && + isxdigit(d->d_name[0]) && isxdigit(d->d_name[1]); +} + +static bool lsdir_bid_tail_filter(const char *name