Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1399126

[PATCH perf/core v7 07/21] perf symbol: Cleanup the code flow of dso__find_kallsyms

From Masami Hiramatsu <mhiramat@kernel.org>
Newsgroups linux.kernel
Subject [PATCH perf/core v7 07/21] perf symbol: Cleanup the code flow of dso__find_kallsyms
Date 2016-05-11 16:00 +0200
Message-ID <rxCQc-UH-67@gated-at.bofh.it> (permalink)
References <rxCQa-UH-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Cleanup the code flow of dso__find_kallsyms() to remove
redundant checking code and add some comment for readability.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/symbol.c |   60 +++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 33 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index e112bbd..b2b06b7 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1629,6 +1629,15 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
 	return ret;
 }
 
+static bool filename__readable(const char *file)
+{
+	int fd = open(file, O_RDONLY);
+	if (fd < 0)
+		return false;
+	close(fd);
+	return true;
+}
+
 static char *dso__find_kallsyms(struct dso *dso, struct map *map)
 {
 	u8 host_build_id[BUILD_ID_SIZE];
@@ -1648,45 +1657,33 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
 				 sizeof(host_build_id)) == 0)
 		is_host = dso__build_id_equal(dso, host_build_id);
 
-	build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
-
-	scnprintf(path, sizeof(path), "%s/%s/%s", buildid_dir,
-		  DSO__NAME_KCORE, sbuild_id);
-
-	/* Use /proc/kallsyms if possible */
+	/* Try a fast path for /proc/kallsyms if possible */
 	if (is_host) {
-		DIR *d;
-		int fd;
-
-		/* If no cached kcore go with /proc/kallsyms */
-		d = opendir(path);
-		if (!d)
-			goto proc_kallsyms;
-		closedir(d);
-
 		/*
-		 * Do not check the build-id cache, until we know we cannot use
-		 * /proc/kcore.
+		 * Do not check the build-id cache, unless we know we cannot use
+		 * /proc/kcore or module maps don't match to /proc/kallsyms.
 		 */
-		fd = open("/proc/kcore", O_RDONLY);
-		if (fd != -1) {
-			close(fd);
-			/* If module maps match go with /proc/kallsyms */
-			if (!validate_kcore_addresses("/proc/kallsyms", map))
-				goto proc_kallsyms;
-		}
-
-		/* Find kallsyms in build-id cache with kcore */
-		if (!find_matching_kcore(map, path, sizeof(path)))
-			return strdup(path);
-
-		goto proc_kallsyms;
+		if (filename__readable("/proc/kcore") &&
+		    !validate_kcore_addresses("/proc/kallsyms", map))
+			goto proc_kallsyms;
 	}
 
+	build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
+
 	/* Find kallsyms in build-id cache with kcore */
+	scnprintf(path, sizeof(path), "%s/%s/%s",
+		  buildid_dir, DSO__NAME_KCORE, sbuild_id);
+
 	if (!find_matching_kcore(map, path, sizeof(path)))
 		return strdup(path);
 
+	/* Use current /proc/kallsyms if possible */
+	if (is_host) {
+proc_kallsyms:
+		return strdup("/proc/kallsyms");
+	}
+
+	/* Finally, find a cache of kallsyms */
 	scnprintf(path, sizeof(path), "%s/%s/%s",
 		  buildid_dir, DSO__NAME_KALLSYMS, sbuild_id);
 
@@ -1697,9 +1694,6 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
 	}
 
 	return strdup(path);
-
-proc_kallsyms:
-	return strdup("/proc/kallsyms");
 }
 
 static int dso__load_kernel_sym(struct dso *dso, struct map *map,

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH perf/core v7 00/21] perf-probe --cache and SDT support Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 18/21] perf-list: Skip SDTs placed in invalid binaries Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 07/21] perf symbol: Cleanup the code flow of dso__find_kallsyms Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
    Re: [PATCH perf/core v7 07/21] perf symbol: Cleanup the code flow of  dso__find_kallsyms Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-11 18:00 +0200
      Re: [PATCH perf/core v7 07/21] perf symbol: Cleanup the code flow  of dso__find_kallsyms Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-12 03:50 +0200
  [PATCH perf/core v7 17/21] perf-list: Show SDT and pre-cached events Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 16/21] perf probe: Accept %sdt and %cached event name Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 10/21] perf probe: Use cache entry if possible Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 15/21] perf buildid-cache: Scan and import user SDT events to probe cache Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 01/21] tools/perf: Fix lsdir to set errno correctly Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
    [tip:perf/core] perf tools: Fix lsdir to set errno correctly tip-bot for Masami Hiramatsu <tipbot@zytor.com> - 2016-05-12 12:30 +0200
  [PATCH perf/core v7 20/21] perf probe: Support @BUILDID or @FILE suffix for SDT events Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 19/21] perf probe: Allow wildcard for cached events Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 02/21] perf buildid: Fix to set correct dso name for kallsyms Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
    Re: [PATCH perf/core v7 02/21] perf buildid: Fix to set correct dso  name for kallsyms Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-11 17:50 +0200
      Re: [PATCH perf/core v7 02/21] perf buildid: Fix to set correct dso  name for kallsyms Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-12 04:10 +0200
        Re: [PATCH perf/core v7 02/21] perf buildid: Fix to set correct dso  name for kallsyms Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-12 11:00 +0200
  [PATCH perf/core v7 09/21] perf probe: Add --cache option to cache the probe definitions Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:00 +0200
  [PATCH perf/core v7 03/21] perf buildid: Introduce DSO__NAME_KALLSYMS and DSO__NAME_KCORE Masami Hiramatsu <mhiramat@kernel.org> - 2016-05-11 16:10 +0200
    Re: [PATCH perf/core v7 03/21] perf buildid: Introduce  DSO__NAME_KALLSYMS and DSO__NAME_KCORE Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-11 17:50 +0200

csiph-web