mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf probe: add kernel source path option
@ 2010-06-07  0:22 Chase Douglas
  2010-06-07 11:49 ` Chase Douglas
  0 siblings, 1 reply; 2+ messages in thread
From: Chase Douglas @ 2010-06-07  0:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras, Ingo Molnar
  Cc: Masami Hiramatsu, linux-kernel

The probe plugin requires access to the source code for some operations.
The source code must be in the exact same location as specified by the
DWARF tags, but sometimes the location is an absolute path that cannot
be replicated by a normal user. This change adds the -s|--source option
to allow the user to specify the root of the kernel source tree.

Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
---
 tools/perf/Documentation/perf-probe.txt |    4 ++
 tools/perf/builtin-probe.c              |    2 +
 tools/perf/util/probe-finder.c          |   56 +++++++++++++++++++++++++++++-
 tools/perf/util/symbol.h                |    1 +
 4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 34202b1..d387d8b 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -31,6 +31,10 @@ OPTIONS
 --vmlinux=PATH::
 	Specify vmlinux path which has debuginfo (Dwarf binary).
 
+-s::
+--source=PATH::
+	Specify path to kernel source.
+
 -v::
 --verbose::
         Be more verbose (show parsed arguments, etc).
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 152d6c9..ae7ba65 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -167,6 +167,8 @@ static const struct option options[] = {
 #ifndef NO_DWARF_SUPPORT
 	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
 		   "file", "vmlinux pathname"),
+	OPT_STRING('s', "source", &symbol_conf.source_prefix,
+		   "directory", "path to kernel source"),
 #endif
 	OPT_BOOLEAN('l', "list", &session.list_events,
 		    "list up current probe events"),
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index c171a24..e1a88f1 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -36,6 +36,7 @@
 #include "event.h"
 #include "debug.h"
 #include "util.h"
+#include "symbol.h"
 #include "probe-finder.h"
 
 
@@ -105,6 +106,55 @@ static int strtailcmp(const char *s1, const char *s2)
 	return 0;
 }
 
+/*
+ * Find a src file from a DWARF tag path. Prepend optional source path prefix
+ * and chop off leading directories that do not exist. Result is passed back as
+ * a newly allocated path on success.
+ * Return 0 if file was found and readable, -1 otherwise.
+ */
+static int get_real_src(const char *raw_path, char **new_path)
+{
+	if (!symbol_conf.source_prefix) {
+		if (access(raw_path, R_OK) == 0) {
+			*new_path = strdup(raw_path);
+			return 0;
+		} else
+			return -1;
+	}
+
+	*new_path = malloc(strlen(symbol_conf.source_prefix)
+			   + strlen(raw_path) + 2);
+	if (!*new_path)
+		return -1;
+
+	for (;;) {
+		sprintf(*new_path, "%s/%s", symbol_conf.source_prefix,
+			raw_path);
+
+		if (access(*new_path, R_OK) == 0)
+			return 0;
+
+		switch (errno) {
+		case ENAMETOOLONG:
+		case ENOENT:
+		case EROFS:
+		case EFAULT:
+			raw_path = strchr(++raw_path, '/');
+			if (!raw_path) {
+				free(*new_path);
+				*new_path = NULL;
+				return -1;
+			}
+			continue;
+
+		default:
+			free(*new_path);
+			*new_path = NULL;
+			return -1;
+		}
+	}
+}
+
 /* Line number list operations */
 
 /* Add a line to line number list */
@@ -726,8 +776,10 @@ static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
 			continue;
 
 		/* Copy real path */
-		if (!lf->lr->path)
-			lf->lr->path = strdup(src);
+		if (!lf->lr->path && get_real_src(src, &lf->lr->path) != 0) {
+			perror("Could not find path to source");
+			break;
+		}
 		line_list__add_line(&lf->lr->line_list, (unsigned int)lineno);
 	}
 	/* Update status */
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index f30a374..fdec2eb 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -65,6 +65,7 @@ struct symbol_conf {
 			exclude_other,
 			full_paths;
 	const char	*vmlinux_name,
+			*source_prefix,
 			*field_sep;
 	char            *dso_list_str,
 			*comm_list_str,
-- 
1.7.0.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf probe: add kernel source path option
  2010-06-07  0:22 [PATCH] perf probe: add kernel source path option Chase Douglas
@ 2010-06-07 11:49 ` Chase Douglas
  0 siblings, 0 replies; 2+ messages in thread
From: Chase Douglas @ 2010-06-07 11:49 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Masami Hiramatsu,
	linux-kernel

On Sun, 2010-06-06 at 20:22 -0400, Chase Douglas wrote:
> The probe plugin requires access to the source code for some operations.
> The source code must be in the exact same location as specified by the
> DWARF tags, but sometimes the location is an absolute path that cannot
> be replicated by a normal user. This change adds the -s|--source option
> to allow the user to specify the root of the kernel source tree.
> 
> Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
> ---
>  tools/perf/Documentation/perf-probe.txt |    4 ++
>  tools/perf/builtin-probe.c              |    2 +
>  tools/perf/util/probe-finder.c          |   56 +++++++++++++++++++++++++++++-
>  tools/perf/util/symbol.h                |    1 +
>  4 files changed, 61 insertions(+), 2 deletions(-)

Please disregard this patch. It is based on the 2.6.34 kernel and I
forgot to rebase it on the latest perf code. I have a newer patch I will
be sending out shortly.

Thanks,

-- Chase


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-07 11:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-07  0:22 [PATCH] perf probe: add kernel source path option Chase Douglas
2010-06-07 11:49 ` Chase Douglas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®