From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH 02/26] perf trace: Split fd -> pathname array handling
Date: Tue, 22 Oct 2013 11:28:10 -0300 [thread overview]
Message-ID: <1382452114-1243-3-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1382452114-1243-1-git-send-email-acme@infradead.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
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>
---
tools/perf/builtin-trace.c | 49 +++++++++++++++++++++++++---------------------
1 file 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 {
double runtime_ms;
};
-static int thread__read_fd_path(struct thread *thread, int fd)
+static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pathname)
{
struct thread_trace *ttrace = thread->priv;
- char linkname[PATH_MAX], pathname[PATH_MAX];
- struct stat st;
- int ret;
-
- if (thread->pid_ == thread->tid) {
- scnprintf(linkname, sizeof(linkname),
- "/proc/%d/fd/%d", thread->pid_, fd);
- } else {
- scnprintf(linkname, sizeof(linkname),
- "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd);
- }
-
- if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname))
- return -1;
-
- ret = readlink(linkname, pathname, sizeof(pathname));
-
- if (ret < 0 || ret > st.st_size)
- return -1;
-
- pathname[ret] = '\0';
if (fd > ttrace->paths.max) {
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)
return ttrace->paths.table[fd] != NULL ? 0 : -1;
}
+static int thread__read_fd_path(struct thread *thread, int fd)
+{
+ char linkname[PATH_MAX], pathname[PATH_MAX];
+ struct stat st;
+ int ret;
+
+ if (thread->pid_ == thread->tid) {
+ scnprintf(linkname, sizeof(linkname),
+ "/proc/%d/fd/%d", thread->pid_, fd);
+ } else {
+ scnprintf(linkname, sizeof(linkname),
+ "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd);
+ }
+
+ if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname))
+ return -1;
+
+ ret = readlink(linkname, pathname, sizeof(pathname));
+
+ if (ret < 0 || ret > st.st_size)
+ return -1;
+
+ pathname[ret] = '\0';
+ return trace__set_fd_pathname(thread, fd, pathname);
+}
+
static const char *thread__fd_path(struct thread *thread, int fd, bool live)
{
struct thread_trace *ttrace = thread->priv;
--
1.8.1.4
next prev parent reply other threads:[~2013-10-22 14:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 14:28 [GIT PULL 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 01/26] perf scripting perl: Fix build error on Fedora 12 Arnaldo Carvalho de Melo
2013-10-22 14:28 ` Arnaldo Carvalho de Melo [this message]
2013-10-22 14:28 ` [PATCH 03/26] perf trace: Use vfs_getname hook if available Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 04/26] perf trace: Improve event processing exit Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 05/26] perf evlist: Introduce perf_evlist__strerror_tp method Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 06/26] perf tools: Introduce filename__read_int helper Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 07/26] perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 08/26] perf evsel: Add missing 'mmap2' from debug print Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 09/26] perf evsel: Add missing decrement in id sample parsing Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 10/26] perf record: Improve write_output error message Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 11/26] perf session: Add missing sample flush for piped events Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 12/26] perf session: Add missing members to perf_event__attr_swap() Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 13/26] perf evlist: Fix 32-bit build error Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 14/26] perf tools: Fix test_on_exit for 32-bit build Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 15/26] perf tools: Fix bench/numa.c " Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 16/26] perf evlist: Fix perf_evlist__mmap comments Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 17/26] perf evlist: Factor out duplicated mmap code Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 18/26] perf script: Print addr by default for BTS Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 19/26] perf list: Show error if tracepoints not available Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 20/26] perf callchain: Convert children list to rbtree Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 21/26] perf tools: Compare dso's also when comparing symbols Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 22/26] perf tools: Add data object to handle perf data file Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 23/26] perf tools: Add perf_data_file__open interface to data object Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 24/26] perf session: Separating data file properties from session Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 25/26] perf report: Add --max-stack option to limit callchain stack scan Arnaldo Carvalho de Melo
2013-10-22 14:28 ` [PATCH 26/26] perf top: " Arnaldo Carvalho de Melo
2013-10-23 7:48 ` [GIT PULL 00/26] perf/core improvements and fixes 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=1382452114-1243-3-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=dsahern@gmail.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulus@samba.org \
--cc=peterz@infradead.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
all inboxes | Powered by JetHome®