path: root/tools/perf/trace
diff options
authorArnaldo Carvalho de Melo <>2016-04-26 12:33:46 -0300
committerArnaldo Carvalho de Melo <>2016-04-26 13:15:00 -0300
commit073e5fca53d30ffe9e2fc637a001c78b2cdca7dd (patch)
tree883fad3a1e54ccc6e7503268437d6651f671d6fd /tools/perf/trace
parent2f3027ac28bf6bc3ac7eb851eab06f2a38af5caa (diff)
perf trace: Read thread's COMM from /proc when not set
We get notifications for threads that gets created while we're tracing, but for preexisting threads we may end not having synthesized them, like when tracing a 'perf trace' session that will use '--pid' to trace some other thread. And besides we should probably stop synthesizing those records and instead read thread information in a lazy way, i.e. just when we need, like done in this patch: Now the 'pid_t' argument in 'perf_event_open' gets translated to a COMM: # perf trace -e perf_event_open perf stat -e cycles -p 31601 0.027 ( 0.027 ms): perf/23393 perf_event_open(attr_uptr: 0x2fdd0d8, pid: 31601 (abrt-dump-journ), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = 3 ^C And in other syscalls containing pid_t without thread->comm_set at the time of the formatting. Cc: Adrian Hunter <> Cc: Borislav Petkov <> Cc: David Ahern <> Cc: Jiri Olsa <> Cc: Milian Wolff <> Cc: Namhyung Kim <> Cc: Wang Nan <> Link: Signed-off-by: Arnaldo Carvalho de Melo <>
Diffstat (limited to 'tools/perf/trace')
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/perf/trace/beauty/pid.c b/tools/perf/trace/beauty/pid.c
index 111ae08d38f1..07486ea65ae3 100644
--- a/tools/perf/trace/beauty/pid.c
+++ b/tools/perf/trace/beauty/pid.c
@@ -3,9 +3,12 @@ static size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_a
int pid = arg->val;
struct trace *trace = arg->trace;
size_t printed = scnprintf(bf, size, "%d", pid);
- struct thread *thread = machine__find_thread(trace->host, pid, pid);
+ struct thread *thread = machine__findnew_thread(trace->host, pid, pid);
if (thread != NULL) {
+ if (!thread->comm_set)
+ thread__set_comm_from_proc(thread);
if (thread->comm_set)
printed += scnprintf(bf + printed, size - printed,
" (%s)", thread__comm_str(thread));