Skip to content

Commit c3492a3

Browse files
mhiramathitachiacmel
authored andcommitted
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 <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Brendan Gregg <[email protected]> Cc: Hemant Kumar <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/146831789417.17065.17896487479879669610.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 36a009f commit c3492a3

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

tools/perf/builtin-probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static int del_perf_probe_caches(struct strfilter *filter)
370370
struct str_node *nd;
371371
int ret;
372372

373-
bidlist = build_id_cache__list_all();
373+
bidlist = build_id_cache__list_all(false);
374374
if (!bidlist) {
375375
ret = -errno;
376376
pr_debug("Failed to get buildids: %d\n", ret);

tools/perf/util/build-id.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,31 @@ char *build_id_cache__origname(const char *sbuild_id)
206206
return ret;
207207
}
208208

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+
209234
static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso)
210235
{
211236
return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : "elf");
@@ -433,13 +458,17 @@ static bool lsdir_bid_tail_filter(const char *name __maybe_unused,
433458
return (i == SBUILD_ID_SIZE - 3) && (d->d_name[i] == '\0');
434459
}
435460

436-
struct strlist *build_id_cache__list_all(void)
461+
struct strlist *build_id_cache__list_all(bool validonly)
437462
{
438463
struct strlist *toplist, *linklist = NULL, *bidlist;
439464
struct str_node *nd, *nd2;
440465
char *topdir, *linkdir = NULL;
441466
char sbuild_id[SBUILD_ID_SIZE];
442467

468+
/* for filename__ functions */
469+
if (validonly)
470+
symbol__init(NULL);
471+
443472
/* Open the top-level directory */
444473
if (asprintf(&topdir, "%s/.build-id/", buildid_dir) < 0)
445474
return NULL;
@@ -470,6 +499,8 @@ struct strlist *build_id_cache__list_all(void)
470499
if (snprintf(sbuild_id, SBUILD_ID_SIZE, "%s%s",
471500
nd->s, nd2->s) != SBUILD_ID_SIZE - 1)
472501
goto err_out;
502+
if (validonly && !build_id_cache__valid_id(sbuild_id))
503+
continue;
473504
if (strlist__add(bidlist, sbuild_id) < 0)
474505
goto err_out;
475506
}

tools/perf/util/build-id.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ char *build_id_cache__origname(const char *sbuild_id);
3434
char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size);
3535
char *build_id_cache__cachedir(const char *sbuild_id, const char *name,
3636
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);
3838
int build_id_cache__list_build_ids(const char *pathname,
3939
struct strlist **result);
4040
bool build_id_cache__cached(const char *sbuild_id);

tools/perf/util/probe-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ int probe_cache__show_all_caches(struct strfilter *filter)
808808
pr_debug("list cache with filter: %s\n", buf);
809809
free(buf);
810810

811-
bidlist = build_id_cache__list_all();
811+
bidlist = build_id_cache__list_all(true);
812812
if (!bidlist) {
813813
pr_debug("Failed to get buildids: %d\n", errno);
814814
return -EINVAL;

0 commit comments

Comments
 (0)