Commit 97119f37bbebbab852899bd37ed52b80396728f9
1 parent
6650b181cc
Exists in
master
and in
16 other branches
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>
Showing 1 changed file with 27 additions and 22 deletions Side-by-side Diff
tools/perf/builtin-trace.c
... | ... | @@ -975,31 +975,10 @@ |
975 | 975 | double runtime_ms; |
976 | 976 | }; |
977 | 977 | |
978 | -static int thread__read_fd_path(struct thread *thread, int fd) | |
978 | +static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pathname) | |
979 | 979 | { |
980 | 980 | struct thread_trace *ttrace = thread->priv; |
981 | - char linkname[PATH_MAX], pathname[PATH_MAX]; | |
982 | - struct stat st; | |
983 | - int ret; | |
984 | 981 | |
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 | - | |
1003 | 982 | if (fd > ttrace->paths.max) { |
1004 | 983 | char **npath = realloc(ttrace->paths.table, (fd + 1) * sizeof(char *)); |
1005 | 984 | |
... | ... | @@ -1020,6 +999,32 @@ |
1020 | 999 | ttrace->paths.table[fd] = strdup(pathname); |
1021 | 1000 | |
1022 | 1001 | return ttrace->paths.table[fd] != NULL ? 0 : -1; |
1002 | +} | |
1003 | + | |
1004 | +static 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); | |
1023 | 1028 | } |
1024 | 1029 | |
1025 | 1030 | static const char *thread__fd_path(struct thread *thread, int fd, bool live) |