Skip to content

Commit 4e4b6c0

Browse files
mhiramatacmel
authored andcommitted
perf symbols: Cleanup the code flow of dso__find_kallsyms
Cleanup the code flow of dso__find_kallsyms() to remove redundant checking code and add some comment for readability. Signed-off-by: Masami Hiramatsu <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Brendan Gregg <[email protected]> Cc: Hemant Kumar <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/20160528151522.16098.43446.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 11870d7 commit 4e4b6c0

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

tools/perf/util/symbol.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,21 +1674,8 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
16741674
sizeof(host_build_id)) == 0)
16751675
is_host = dso__build_id_equal(dso, host_build_id);
16761676

1677-
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
1678-
1679-
scnprintf(path, sizeof(path), "%s/%s/%s", buildid_dir,
1680-
DSO__NAME_KCORE, sbuild_id);
1681-
1682-
/* Use /proc/kallsyms if possible */
1677+
/* Try a fast path for /proc/kallsyms if possible */
16831678
if (is_host) {
1684-
DIR *d;
1685-
1686-
/* If no cached kcore go with /proc/kallsyms */
1687-
d = opendir(path);
1688-
if (!d)
1689-
goto proc_kallsyms;
1690-
closedir(d);
1691-
16921679
/*
16931680
* Do not check the build-id cache, unless we know we cannot use
16941681
* /proc/kcore or module maps don't match to /proc/kallsyms.
@@ -1699,18 +1686,24 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
16991686
if (filename__readable("/proc/kcore") &&
17001687
!validate_kcore_addresses("/proc/kallsyms", map))
17011688
goto proc_kallsyms;
1702-
1703-
/* Find kallsyms in build-id cache with kcore */
1704-
if (!find_matching_kcore(map, path, sizeof(path)))
1705-
return strdup(path);
1706-
1707-
goto proc_kallsyms;
17081689
}
17091690

1691+
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
1692+
17101693
/* Find kallsyms in build-id cache with kcore */
1694+
scnprintf(path, sizeof(path), "%s/%s/%s",
1695+
buildid_dir, DSO__NAME_KCORE, sbuild_id);
1696+
17111697
if (!find_matching_kcore(map, path, sizeof(path)))
17121698
return strdup(path);
17131699

1700+
/* Use current /proc/kallsyms if possible */
1701+
if (is_host) {
1702+
proc_kallsyms:
1703+
return strdup("/proc/kallsyms");
1704+
}
1705+
1706+
/* Finally, find a cache of kallsyms */
17141707
scnprintf(path, sizeof(path), "%s/%s/%s",
17151708
buildid_dir, DSO__NAME_KALLSYMS, sbuild_id);
17161709

@@ -1721,9 +1714,6 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
17211714
}
17221715

17231716
return strdup(path);
1724-
1725-
proc_kallsyms:
1726-
return strdup("/proc/kallsyms");
17271717
}
17281718

17291719
static int dso__load_kernel_sym(struct dso *dso, struct map *map,

0 commit comments

Comments
 (0)