Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1373762

[PATCH 08/19] perf trace: Infrastructure to show COMM strings for syscalls returning PIDs

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 08/19] perf trace: Infrastructure to show COMM strings for syscalls returning PIDs
Date 2016-04-07 23:00 +0200
Message-ID <rlpbY-16R-29@gated-at.bofh.it> (permalink)
References <rlpbX-16R-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Arnaldo Carvalho de Melo <acme@redhat.com>

Starting with clone, waitid and wait4:

  # trace -e waitid,wait4
     1.385 ( 1.385 ms): bash/12122 wait4(upid: -1, stat_addr: 0x7ffe0cee1720, options: UNTRACED|CONTINUED) = 1210 (ls)
     1.426 ( 0.002 ms): bash/12122 wait4(upid: -1, stat_addr: 0x7ffe0cee1150, options: NOHANG|UNTRACED|CONTINUED) = 0
     3.293 ( 0.604 ms): bash/1211 wait4(upid: -1, stat_addr: 0x7ffe0cee0560                             ) = 1214 (sed)
     3.342 ( 0.002 ms): bash/1211 wait4(upid: -1, stat_addr: 0x7ffe0cee01d0, options: NOHANG            ) = -1 ECHILD No child processes
     3.576 ( 0.016 ms): bash/12122 wait4(upid: -1, stat_addr: 0x7ffe0cee0550, options: NOHANG|UNTRACED|CONTINUED) = 1211 (bash)
  ^C# trace -e clone
     0.027 ( 0.000 ms): systemd/1  ... [continued]: clone()) = 1227 (systemd)
     0.050 ( 0.000 ms): systemd/1227  ... [continued]: clone()) = 0
  ^C[root@jouet ~]#

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-lyf5d3y5j15wikjb6pe6ukoi@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 9a6c7b1fd5a1..22a4901d057b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1082,6 +1082,7 @@ static struct syscall_fmt {
 	size_t	   (*arg_scnprintf[6])(char *bf, size_t size, struct syscall_arg *arg);
 	void	   *arg_parm[6];
 	bool	   errmsg;
+	bool	   errpid;
 	bool	   timeout;
 	bool	   hexret;
 } syscall_fmts[] = {
@@ -1099,6 +1100,7 @@ static struct syscall_fmt {
 	{ .name	    = "chroot",	    .errmsg = true,
 	  .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, },
 	{ .name     = "clock_gettime",  .errmsg = true, STRARRAY(0, clk_id, clockid), },
+	{ .name	    = "clone",	    .errpid = true, },
 	{ .name	    = "close",	    .errmsg = true,
 	  .arg_scnprintf = { [0] = SCA_CLOSE_FD, /* fd */ }, },
 	{ .name	    = "connect",    .errmsg = true, },
@@ -1365,9 +1367,9 @@ static struct syscall_fmt {
 	  .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, },
 	{ .name	    = "vmsplice",  .errmsg = true,
 	  .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, },
-	{ .name	    = "wait4",	    .errmsg = true,
+	{ .name	    = "wait4",	    .errpid = true,
 	  .arg_scnprintf = { [2] = SCA_WAITID_OPTIONS, /* options */ }, },
-	{ .name	    = "waitid",	    .errmsg = true,
+	{ .name	    = "waitid",	    .errpid = true,
 	  .arg_scnprintf = { [3] = SCA_WAITID_OPTIONS, /* options */ }, },
 	{ .name	    = "write",	    .errmsg = true,
 	  .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, },
@@ -2156,7 +2158,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
 	if (sc->fmt == NULL) {
 signed_print:
 		fprintf(trace->output, ") = %ld", ret);
-	} else if (ret < 0 && sc->fmt->errmsg) {
+	} else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) {
 		char bf[STRERR_BUFSIZE];
 		const char *emsg = strerror_r(-ret, bf, sizeof(bf)),
 			   *e = audit_errno_to_name(-ret);
@@ -2166,7 +2168,16 @@ signed_print:
 		fprintf(trace->output, ") = 0 Timeout");
 	else if (sc->fmt->hexret)
 		fprintf(trace->output, ") = %#lx", ret);
-	else
+	else if (sc->fmt->errpid) {
+		struct thread *child = machine__find_thread(trace->host, ret, ret);
+
+		if (child != NULL) {
+			fprintf(trace->output, ") = %ld", ret);
+			if (child->comm_set)
+				fprintf(trace->output, " (%s)", thread__comm_str(child));
+			thread__put(child);
+		}
+	} else
 		goto signed_print;
 
 	fputc('\n', trace->output);
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 04/19] perf tools: Remove superfluous ARCH Makefile includes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 18/19] perf symbols: Record text offset in dso to calculate objdump address Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 08/19] perf trace: Infrastructure to show COMM strings for syscalls returning PIDs Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:00 +0200
  [PATCH 01/19] perf config: Fix build with older toolchain. Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 11/19] perf tools: Introduce trim function Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 03/19] perf script perl: Do error checking on new backtrace routine Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 06/19] perf trace: Beautify sched_setscheduler 'policy' argument Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 07/19] perf trace: Beautify wait4/waitid 'options' argument Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 09/19] perf trace: Beautify set_tid_address, getpid, getppid return values Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 15/19] perf trace: Move syscall table id <-> name routines to separate class Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 14/19] perf trace: Beautify mode_t arguments Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 12/19] perf tools: Add dedicated unwind addr_space member into thread struct Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 13/19] perf script: Process event update events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 16/19] perf tools: Allow generating per-arch syscall table arrays Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 05/19] perf list: Document event specifications better Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 02/19] perf probe: Check if dwarf_getlocations() is available Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  [PATCH 10/19] perf trace: Beautify pid_t arguments Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-07 23:10 +0200
  Re: [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-08 15:20 +0200
    Re: [GIT PULL 00/19] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-04-13 09:00 +0200

csiph-web