Skip to contentSkip to conversation

perf trace beauty: Implement pid_fd beautifier

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Nov 3, 2017 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  0a2f7540abc08e32f89ff273506eeeeb6910794f
Gitweb:     https://git.kernel.org/tip/0a2f7540abc08e32f89ff273506eeeeb6910794f
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 31 Oct 2017 11:30:09 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 31 Oct 2017 16:17:03 -0300

perf trace beauty: Implement pid_fd beautifier

One that given a pid and a fd, will try to get the path for that fd. Will be used in the upcoming kcmp's KCMP_FILE beautifier.

---
 tools/perf/builtin-trace.c       | 17 +++++++++++++++++
 tools/perf/trace/beauty/beauty.h |  3 +++
 2 files changed, 20 insertions(+)
tools/perf/builtin-trace.c +17 -0
index c373f9a..0c14614 100644
@@ -988,6 +988,23 @@ size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg)
 	return printed;
 }
 
+size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size)
+{
+        size_t printed = scnprintf(bf, size, "%d", fd);
+	struct thread *thread = machine__find_thread(trace->host, pid, pid);
+
+	if (thread) {
+		const char *path = thread__fd_path(thread, fd, trace);
+
+		if (path)
+			printed += scnprintf(bf + printed, size - printed, "<%s>", path);
+
+		thread__put(thread);
+	}
+
+        return printed;
+}
+
 static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size,
 					      struct syscall_arg *arg)
 {
tools/perf/trace/beauty/beauty.h +3 -0
index b29f94e..365bb6f 100644
@@ -3,6 +3,7 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <sys/types.h>
 
 struct strarray {
 	int	    offset;
@@ -26,6 +27,8 @@ size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const cha
 struct trace;
 struct thread;
 
+size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
+
 /**
  * @val: value of syscall argument being formatted
  * @args: All the args, use syscall_args__val(arg, nth) to access one