public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@elte.hu>
Cc: Mel Gorman <mel@csn.ul.ie>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Arnaldo Carvalho de Melo <acme@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Roland McGrath <roland@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Christoph Hellwig <hch@infradead.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Oleg Nesterov <oleg@redhat.com>, Mark Wielaard <mjw@redhat.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Jim Keniston <jkenisto@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCHv7 2.6.35-rc3-tip 10/11]  perf: Re-Add make_absolute_path
Date: Wed, 30 Jun 2010 00:06:54 +0530	[thread overview]
Message-ID: <20100629183654.32537.61590.sendpatchset@localhost6.localdomain6> (raw)
In-Reply-To: <20100629183454.32537.63582.sendpatchset@localhost6.localdomain6>


perf: Re-Add make_absolute_path

perf probe for uprobes would use make_absolute_path.
make_absolute_path can be used to convert a file name to a dso name.

so if user specifies the function to be traced as malloc@/lib/libc.so.6
it needs to be converted to malloc@libc-2.5.so

This patch reverts a part of a41794cdd7ee94a5199e14f642c26d649d383fa5
---

 tools/perf/util/abspath.c |   81 +++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/cache.h   |    1 +
 2 files changed, 82 insertions(+), 0 deletions(-)


diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c
index 0e76aff..a791dd4 100644
--- a/tools/perf/util/abspath.c
+++ b/tools/perf/util/abspath.c
@@ -1,5 +1,86 @@
 #include "cache.h"
 
+/*
+ * Do not use this for inspecting *tracked* content.  When path is a
+ * symlink to a directory, we do not want to say it is a directory when
+ * dealing with tracked content in the working tree.
+ */
+static int is_directory(const char *path)
+{
+	struct stat st;
+	return (!stat(path, &st) && S_ISDIR(st.st_mode));
+}
+
+/* We allow "recursive" symbolic links. Only within reason, though. */
+#define MAXDEPTH 5
+
+const char *make_absolute_path(const char *path)
+{
+	static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1];
+	char cwd[1024] = "";
+	int buf_index = 1, len;
+
+	int depth = MAXDEPTH;
+	char *last_elem = NULL;
+	struct stat st;
+
+	if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
+		die ("Too long path: %.*s", 60, path);
+
+	while (depth--) {
+		if (!is_directory(buf)) {
+			char *last_slash = strrchr(buf, '/');
+			if (last_slash) {
+				*last_slash = '\0';
+				last_elem = xstrdup(last_slash + 1);
+			} else {
+				last_elem = xstrdup(buf);
+				*buf = '\0';
+			}
+		}
+
+		if (*buf) {
+			if (!*cwd && !getcwd(cwd, sizeof(cwd)))
+				die ("Could not get current working directory");
+
+			if (chdir(buf))
+				die ("Could not switch to '%s'", buf);
+		}
+		if (!getcwd(buf, PATH_MAX))
+			die ("Could not get current working directory");
+
+		if (last_elem) {
+			len = strlen(buf);
+
+			if (len + strlen(last_elem) + 2 > PATH_MAX)
+				die ("Too long path name: '%s/%s'",
+						buf, last_elem);
+			buf[len] = '/';
+			strcpy(buf + len + 1, last_elem);
+			free(last_elem);
+			last_elem = NULL;
+		}
+
+		if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) {
+			len = readlink(buf, next_buf, PATH_MAX);
+			if (len < 0)
+				die ("Invalid symlink: %s", buf);
+			if (PATH_MAX <= len)
+				die("symbolic link too long: %s", buf);
+			next_buf[len] = '\0';
+			buf = next_buf;
+			buf_index = 1 - buf_index;
+			next_buf = bufs[buf_index];
+		} else
+			break;
+	}
+
+	if (*cwd && chdir(cwd))
+		die ("Could not change back to '%s'", cwd);
+
+	return buf;
+}
+
 static const char *get_pwd_cwd(void)
 {
 	static char cwd[PATH_MAX + 1];
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 27e9ebe..0dfed40 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -73,6 +73,7 @@ static inline int is_absolute_path(const char *path)
 	return path[0] == '/';
 }
 
+const char *make_absolute_path(const char *path);
 const char *make_nonrelative_path(const char *path);
 char *strip_path_suffix(const char *path, const char *suffix);
 

  parent reply	other threads:[~2010-06-29 18:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-29 18:34 [PATCHv7 2.6.35-rc3-tip 0/11] Uprobes Patches: Srikar Dronamraju
2010-06-29 18:35 ` [PATCHv7 2.6.35-rc3-tip 1/11] mm: Move replace_page() / write_protect_page() to mm/memory.c Srikar Dronamraju
2010-06-29 18:35 ` [PATCHv7 2.6.35-rc3-tip 2/11] uprobes: Breakpoint insertion/removal in user space applications Srikar Dronamraju
2010-06-29 18:35 ` [PATCHv7 2.6.35-rc3-tip 3/11] uprobes: Slot allocation for Execution out of line(XOL) Srikar Dronamraju
2010-06-29 18:35 ` [PATCHv7 2.6.35-rc3-tip 4/11] uprobes: x86 specific functions for user space breakpointing Srikar Dronamraju
2010-06-29 18:35 ` [PATCHv7 2.6.35-rc3-tip 5/11] uprobes: Uprobes (un)registration and exception handling Srikar Dronamraju
2010-06-29 18:36 ` [PATCHv7 2.6.35-rc3-tip 6/11] uprobes: X86 support for Uprobes Srikar Dronamraju
2010-06-29 18:36 ` [PATCHv7 2.6.35-rc3-tip 7/11] uprobes: Uprobes Documentation Srikar Dronamraju
2010-06-29 18:36 ` [PATCHv7 2.6.35-rc3-tip 8/11] trace: Extract out common code for kprobes/uprobes traceevents Srikar Dronamraju
2010-06-29 18:36 ` [PATCHv7 2.6.35-rc3-tip 9/11] trace: uprobes trace_event interface Srikar Dronamraju
2010-06-29 18:36 ` Srikar Dronamraju [this message]
2010-06-29 18:37 ` [PATCHv7 2.6.35-rc3-tip 11/11] perf: perf interface for uprobes Srikar Dronamraju
2010-07-01  5:59   ` Masami Hiramatsu
2010-07-02 11:25     ` Masami Hiramatsu
2010-07-02 11:28       ` Srikar Dronamraju
2010-07-06  0:27         ` Masami Hiramatsu
2010-07-01  5:02 ` [PATCHv7 2.6.35-rc3-tip 0/11] Uprobes Patches: Srikar Dronamraju
2010-07-01  8:19   ` Ingo Molnar
2010-07-01  9:17     ` Masami Hiramatsu
2010-07-01  9:58       ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100629183654.32537.61590.sendpatchset@localhost6.localdomain6 \
    --to=srikar@linux.vnet.ibm.com \
    --cc=acme@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=ananth@in.ibm.com \
    --cc=fche@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jkenisto@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mel@csn.ul.ie \
    --cc=mingo@elte.hu \
    --cc=mjw@redhat.com \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@xenotime.net \
    --cc=rjw@sisk.pl \
    --cc=roland@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox