diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2016-07-12 06:04:54 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-07-13 22:09:05 -0400 |
commit | c3492a3a4e58117f18d96125e67b0bed7c4231e1 (patch) | |
tree | 838c56bd326744293836dd5c4fe3896b4b977f50 | |
parent | 36a009fe07bdecd201335f982babb8af34b603e2 (diff) |
perf probe: Make --list show only available cached events
Make "perf probe --cache --list" show only available cached events by
checking build-id validity.
E.g. without this patch:
----
$ ./perf probe --cache --add oldevent=cmd_probe
$ make #(to update ./perf)
$ ./perf probe --cache --add newevent=cmd_probe
$ ./perf probe --cache --list
/home/mhiramat/ksrc/linux/tools/perf/perf (061e90539bac69
probe_perf:newevent=cmd_probe
/home/mhiramat/ksrc/linux/tools/perf/perf (c2e44d614e33e1
probe_perf:oldevent=cmd_probe
----
It shows both of old and new events but user can not use old one.
With this;
----
$ ./perf probe --cache -l
/home/mhiramat/ksrc/linux/tools/perf/perf (061e90539bac69
probe_perf:newevent=cmd_probe
----
This shows only new events which are on the existing binary.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.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/146831789417.17065.17896487479879669610.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-probe.c | 2 | ||||
-rw-r--r-- | tools/perf/util/build-id.c | 33 | ||||
-rw-r--r-- | tools/perf/util/build-id.h | 2 | ||||
-rw-r--r-- | tools/perf/util/probe-file.c | 2 |
4 files changed, 35 insertions, 4 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index c6d890ad2c1a..ee5b42173ba3 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -370,7 +370,7 @@ static int del_perf_probe_caches(struct strfilter *filter) | |||
370 | struct str_node *nd; | 370 | struct str_node *nd; |
371 | int ret; | 371 | int ret; |
372 | 372 | ||
373 | bidlist = build_id_cache__list_all(); | 373 | bidlist = build_id_cache__list_all(false); |
374 | if (!bidlist) { | 374 | if (!bidlist) { |
375 | ret = -errno; | 375 | ret = -errno; |
376 | pr_debug("Failed to get buildids: %d\n", ret); | 376 | pr_debug("Failed to get buildids: %d\n", ret); |
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 1e504e40dac8..36b4279a9002 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -206,6 +206,31 @@ out: | |||
206 | return ret; | 206 | return ret; |
207 | } | 207 | } |
208 | 208 | ||
209 | /* Check if the given build_id cache is valid on current running system */ | ||
210 | static bool build_id_cache__valid_id(char *sbuild_id) | ||
211 | { | ||
212 | char real_sbuild_id[SBUILD_ID_SIZE] = ""; | ||
213 | char *pathname; | ||
214 | int ret = 0; | ||
215 | bool result = false; | ||
216 | |||
217 | pathname = build_id_cache__origname(sbuild_id); | ||
218 | if (!pathname) | ||
219 | return false; | ||
220 | |||
221 | if (!strcmp(pathname, DSO__NAME_KALLSYMS)) | ||
222 | ret = sysfs__sprintf_build_id("/", real_sbuild_id); | ||
223 | else if (pathname[0] == '/') | ||
224 | ret = filename__sprintf_build_id(pathname, real_sbuild_id); | ||
225 | else | ||
226 | ret = -EINVAL; /* Should we support other special DSO cache? */ | ||
227 | if (ret >= 0) | ||
228 | result = (strcmp(sbuild_id, real_sbuild_id) == 0); | ||
229 | free(pathname); | ||
230 | |||
231 | return result; | ||
232 | } | ||
233 | |||
209 | static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso) | 234 | static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso) |
210 | { | 235 | { |
211 | return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : "elf"); | 236 | return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : "elf"); |
@@ -433,13 +458,17 @@ static bool lsdir_bid_tail_filter(const char *name __maybe_unused, | |||
433 | return (i == SBUILD_ID_SIZE - 3) && (d->d_name[i] == '\0'); | 458 | return (i == SBUILD_ID_SIZE - 3) && (d->d_name[i] == '\0'); |
434 | } | 459 | } |
435 | 460 | ||
436 | struct strlist *build_id_cache__list_all(void) | 461 | struct strlist *build_id_cache__list_all(bool validonly) |
437 | { | 462 | { |
438 | struct strlist *toplist, *linklist = NULL, *bidlist; | 463 | struct strlist *toplist, *linklist = NULL, *bidlist; |
439 | struct str_node *nd, *nd2; | 464 | struct str_node *nd, *nd2; |
440 | char *topdir, *linkdir = NULL; | 465 | char *topdir, *linkdir = NULL; |
441 | char sbuild_id[SBUILD_ID_SIZE]; | 466 | char sbuild_id[SBUILD_ID_SIZE]; |
442 | 467 | ||
468 | /* for filename__ functions */ | ||
469 | if (validonly) | ||
470 | symbol__init(NULL); | ||
471 | |||
443 | /* Open the top-level directory */ | 472 | /* Open the top-level directory */ |
444 | if (asprintf(&topdir, "%s/.build-id/", buildid_dir) < 0) | 473 | if (asprintf(&topdir, "%s/.build-id/", buildid_dir) < 0) |
445 | return NULL; | 474 | return NULL; |
@@ -470,6 +499,8 @@ struct strlist *build_id_cache__list_all(void) | |||
470 | if (snprintf(sbuild_id, SBUILD_ID_SIZE, "%s%s", | 499 | if (snprintf(sbuild_id, SBUILD_ID_SIZE, "%s%s", |
471 | nd->s, nd2->s) != SBUILD_ID_SIZE - 1) | 500 | nd->s, nd2->s) != SBUILD_ID_SIZE - 1) |
472 | goto err_out; | 501 | goto err_out; |
502 | if (validonly && !build_id_cache__valid_id(sbuild_id)) | ||
503 | continue; | ||
473 | if (strlist__add(bidlist, sbuild_id) < 0) | 504 | if (strlist__add(bidlist, sbuild_id) < 0) |
474 | goto err_out; | 505 | goto err_out; |
475 | } | 506 | } |
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index b742e271ea2c..64e740f4bc28 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h | |||
@@ -34,7 +34,7 @@ char *build_id_cache__origname(const char *sbuild_id); | |||
34 | char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size); | 34 | char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size); |
35 | char *build_id_cache__cachedir(const char *sbuild_id, const char *name, | 35 | char *build_id_cache__cachedir(const char *sbuild_id, const char *name, |
36 | bool is_kallsyms, bool is_vdso); | 36 | bool is_kallsyms, bool is_vdso); |
37 | struct strlist *build_id_cache__list_all(void); | 37 | struct strlist *build_id_cache__list_all(bool validonly); |
38 | int build_id_cache__list_build_ids(const char *pathname, | 38 | int build_id_cache__list_build_ids(const char *pathname, |
39 | struct strlist **result); | 39 | struct strlist **result); |
40 | bool build_id_cache__cached(const char *sbuild_id); | 40 | bool build_id_cache__cached(const char *sbuild_id); |
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index fc16b172579f..a5059dc3921a 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c | |||
@@ -808,7 +808,7 @@ int probe_cache__show_all_caches(struct strfilter *filter) | |||
808 | pr_debug("list cache with filter: %s\n", buf); | 808 | pr_debug("list cache with filter: %s\n", buf); |
809 | free(buf); | 809 | free(buf); |
810 | 810 | ||
811 | bidlist = build_id_cache__list_all(); | 811 | bidlist = build_id_cache__list_all(true); |
812 | if (!bidlist) { | 812 | if (!bidlist) { |
813 | pr_debug("Failed to get buildids: %d\n", errno); | 813 | pr_debug("Failed to get buildids: %d\n", errno); |
814 | return -EINVAL; | 814 | return -EINVAL; |