Skip to contentSkip to conversation

perf tools: Add rootfs option for off-box analysis using specified tree

PATCH New David Ahern 1 participant 1 message Nov 21, 2010 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: Add rootfs option for off-box analysis using specified tree

The rootfs argument allows analysis of perf.data file using a locally accessible filesystem tree with debug symbols - e.g., loop mounted KVM disk images, NFS, USB keys, initrds, etc. Anything with an OS tree can be analyzed from anywhere without the need to populate a local data store with build-ids.

---
 tools/perf/builtin-annotate.c  |   16 +++++--
 tools/perf/builtin-diff.c      |    2 +
 tools/perf/builtin-report.c    |    2 +
 tools/perf/builtin-timechart.c |    2 +
 tools/perf/util/hist.c         |   14 +++++-
 tools/perf/util/symbol.c       |   82 +++++++++++++++++++++++++---------------
 tools/perf/util/symbol.h       |    1 +
 7 files changed, 80 insertions(+), 39 deletions(-)
tools/perf/builtin-annotate.c +11 -5
index 6d5604d8d..0ad6876 100644
@@ -280,7 +280,8 @@ static int hist_entry__tty_annotate(struct hist_entry *he)
 	struct map *map = he->ms.map;
 	struct dso *dso = map->dso;
 	struct symbol *sym = he->ms.sym;
-	const char *filename = dso->long_name, *d_filename;
+	const char *filename = dso->long_name;
+	char d_filename[PATH_MAX];
 	u64 len;
 	LIST_HEAD(head);
 	struct objdump_line *pos, *n;
@@ -288,10 +289,13 @@ static int hist_entry__tty_annotate(struct hist_entry *he)
 	if (hist_entry__annotate(he, &head, 0) < 0)
 		return -1;
 
-	if (full_paths)
-		d_filename = filename;
-	else
-		d_filename = basename(filename);
+	if (full_paths) {
+		snprintf(d_filename, sizeof(d_filename), "%s%s",
+			 symbol_conf.rootfs, filename);
+	} else {
+		snprintf(d_filename, sizeof(d_filename), "%s/%s",
+			 symbol_conf.rootfs, basename(filename));
+	}
 
 	len = sym->end - sym->start;
 
@@ -437,6 +441,8 @@ static const struct option options[] = {
 		    "print matching source lines (may be slow)"),
 	OPT_BOOLEAN('P', "full-paths", &full_paths,
 		    "Don't shorten the displayed pathnames"),
+	OPT_STRING(0, "rootfs", &symbol_conf.rootfs, "directory",
+		    "Look for symbol files relative to this root directory."),
 	OPT_END()
 };
 
tools/perf/builtin-diff.c +2 -0
index fca1d44..92754fa 100644
@@ -191,6 +191,8 @@ static const struct option options[] = {
 	OPT_STRING('t', "field-separator", &symbol_conf.field_sep, "separator",
 		   "separator for columns, no spaces will be added between "
 		   "columns '.' is reserved."),
+	OPT_STRING(0, "rootfs", &symbol_conf.rootfs, "directory",
+		    "Look for symbol files relative to this root directory."),
 	OPT_END()
 };
 
tools/perf/builtin-report.c +2 -0
index 5de405d..dd07dda 100644
@@ -478,6 +478,8 @@ static const struct option options[] = {
 		   "columns '.' is reserved."),
 	OPT_BOOLEAN('U', "hide-unresolved", &hide_unresolved,
 		    "Only display entries resolved to a symbol"),
+	OPT_STRING(0, "rootfs", &symbol_conf.rootfs, "directory",
+		    "Look for symbol files relative to this root directory."),
 	OPT_END()
 };
 
tools/perf/builtin-timechart.c +2 -0
index 9bcc38f..9745cd0 100644
@@ -1018,6 +1018,8 @@ static const struct option options[] = {
 	OPT_CALLBACK('p', "process", NULL, "process",
 		      "process selector. Pass a pid or process name.",
 		       parse_process),
+	OPT_STRING(0, "rootfs", &symbol_conf.rootfs, "directory",
+		    "Look for symbol files relative to this root directory."),
 	OPT_END()
 };
 
tools/perf/util/hist.c +11 -3
index 2022e87..f4de675 100644
@@ -1092,6 +1092,12 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head,
 	FILE *file;
 	int err = 0;
 	u64 len;
+	char rootfs_filename[PATH_MAX];
+
+	if (filename) {
+		snprintf(rootfs_filename, sizeof(rootfs_filename), "%s%s",
+		 symbol_conf.rootfs, filename);
+	}
 
 	if (filename == NULL) {
 		if (dso->has_build_id) {
@@ -1100,9 +1106,9 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head,
 			return -ENOMEM;
 		}
 		goto fallback;
-	} else if (readlink(filename, command, sizeof(command)) < 0 ||
+	} else if (readlink(rootfs_filename, command, sizeof(command)) < 0 ||
 		   strstr(command, "[kernel.kallsyms]") ||
-		   access(filename, R_OK)) {
+		   access(rootfs_filename, R_OK)) {
 		free(filename);
 fallback:
 		/*
@@ -1111,6 +1117,8 @@ fallback:
 		 * DSO is the same as when 'perf record' ran.
 		 */
 		filename = dso->long_name;
+		snprintf(rootfs_filename, sizeof(rootfs_filename), "%s%s",
+		 symbol_conf.rootfs, filename);
 		free_filename = false;
 	}
 
@@ -1137,7 +1145,7 @@ fallback:
 		 "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS -C %s|grep -v %s|expand",
 		 map__rip_2objdump(map, sym->start),
 		 map__rip_2objdump(map, sym->end),
-		 filename, filename);
+		 rootfs_filename, filename);
 
 	pr_debug("Executing: %s\n", command);
 
tools/perf/util/symbol.c +51 -31

147 lines not on this page · raw message

tools/perf/util/symbol.h +1 -0
index 038f220..a97b6d3 100644
@@ -85,6 +85,7 @@ struct symbol_conf {
        struct strlist	*dso_list,
 			*comm_list,
 			*sym_list;
+	const char	*rootfs;
 };
 
 extern struct symbol_conf symbol_conf;
Signature · 1 line
1.7.2.3