aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-trace.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-09-27 16:34:10 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-10-16 10:05:01 -0400
commit97119f37bbebbab852899bd37ed52b80396728f9 (patch)
treeeb008335452fae9cd58ea4f5257878c7b0476ca3 /tools/perf/builtin-trace.c
parent6650b181cc0b0c4218ebff9b0c368a2e56287907 (diff)
perf trace: Split fd -> pathname array handling
So that the part that grows the array as needed is untied from the code that reads the /proc/pid/fd symlink and can be used for the vfs_getname hook that will set the fd -> path translation too, when available. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-ydo5rumyv9hdc1vsfmqamugs@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-trace.c')
-rw-r--r--tools/perf/builtin-trace.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index d0f91fe755a3..763bef45afad 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -975,30 +975,9 @@ struct trace {
975 double runtime_ms; 975 double runtime_ms;
976}; 976};
977 977
978static int thread__read_fd_path(struct thread *thread, int fd) 978static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pathname)
979{ 979{
980 struct thread_trace *ttrace = thread->priv; 980 struct thread_trace *ttrace = thread->priv;
981 char linkname[PATH_MAX], pathname[PATH_MAX];
982 struct stat st;
983 int ret;
984
985 if (thread->pid_ == thread->tid) {
986 scnprintf(linkname, sizeof(linkname),
987 "/proc/%d/fd/%d", thread->pid_, fd);
988 } else {
989 scnprintf(linkname, sizeof(linkname),
990 "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd);
991 }
992
993 if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname))
994 return -1;
995
996 ret = readlink(linkname, pathname, sizeof(pathname));
997
998 if (ret < 0 || ret > st.st_size)
999 return -1;
1000
1001 pathname[ret] = '\0';
1002 981
1003 if (fd > ttrace->paths.max) { 982 if (fd > ttrace->paths.max) {
1004 char **npath = realloc(ttrace->paths.table, (fd + 1) * sizeof(char *)); 983 char **npath = realloc(ttrace->paths.table, (fd + 1) * sizeof(char *));
@@ -1022,6 +1001,32 @@ static int thread__read_fd_path(struct thread *thread, int fd)
1022 return ttrace->paths.table[fd] != NULL ? 0 : -1; 1001 return ttrace->paths.table[fd] != NULL ? 0 : -1;
1023} 1002}
1024 1003
1004static int thread__read_fd_path(struct thread *thread, int fd)
1005{
1006 char linkname[PATH_MAX], pathname[PATH_MAX];
1007 struct stat st;
1008 int ret;
1009
1010 if (thread->pid_ == thread->tid) {
1011 scnprintf(linkname, sizeof(linkname),
1012 "/proc/%d/fd/%d", thread->pid_, fd);
1013 } else {
1014 scnprintf(linkname, sizeof(linkname),
1015 "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd);
1016 }
1017
1018 if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname))
1019 return -1;
1020
1021 ret = readlink(linkname, pathname, sizeof(pathname));
1022
1023 if (ret < 0 || ret > st.st_size)
1024 return -1;
1025
1026 pathname[ret] = '\0';
1027 return trace__set_fd_pathname(thread, fd, pathname);
1028}
1029
1025static const char *thread__fd_path(struct thread *thread, int fd, bool live) 1030static const char *thread__fd_path(struct thread *thread, int fd, bool live)
1026{ 1031{
1027 struct thread_trace *ttrace = thread->priv; 1032 struct thread_trace *ttrace = thread->priv;