diff options
Diffstat (limited to 'tools/perf/util/event.c')
-rw-r--r-- | tools/perf/util/event.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 9e806d855b04..d5efa5092ce6 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -95,9 +95,7 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len) | |||
95 | return tgid; | 95 | return tgid; |
96 | } | 96 | } |
97 | 97 | ||
98 | static pid_t perf_event__synthesize_comm(struct perf_tool *tool, | 98 | static pid_t perf_event__prepare_comm(union perf_event *event, pid_t pid, |
99 | union perf_event *event, pid_t pid, | ||
100 | perf_event__handler_t process, | ||
101 | struct machine *machine) | 99 | struct machine *machine) |
102 | { | 100 | { |
103 | size_t size; | 101 | size_t size; |
@@ -124,6 +122,19 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, | |||
124 | (sizeof(event->comm.comm) - size) + | 122 | (sizeof(event->comm.comm) - size) + |
125 | machine->id_hdr_size); | 123 | machine->id_hdr_size); |
126 | event->comm.tid = pid; | 124 | event->comm.tid = pid; |
125 | out: | ||
126 | return tgid; | ||
127 | } | ||
128 | |||
129 | static pid_t perf_event__synthesize_comm(struct perf_tool *tool, | ||
130 | union perf_event *event, pid_t pid, | ||
131 | perf_event__handler_t process, | ||
132 | struct machine *machine) | ||
133 | { | ||
134 | pid_t tgid = perf_event__prepare_comm(event, pid, machine); | ||
135 | |||
136 | if (tgid == -1) | ||
137 | goto out; | ||
127 | 138 | ||
128 | if (process(tool, event, &synth_sample, machine) != 0) | 139 | if (process(tool, event, &synth_sample, machine) != 0) |
129 | return -1; | 140 | return -1; |
@@ -139,7 +150,6 @@ static int perf_event__synthesize_fork(struct perf_tool *tool, | |||
139 | { | 150 | { |
140 | memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size); | 151 | memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size); |
141 | 152 | ||
142 | /* this is really a clone event but we use fork to synthesize it */ | ||
143 | event->fork.ppid = tgid; | 153 | event->fork.ppid = tgid; |
144 | event->fork.ptid = tgid; | 154 | event->fork.ptid = tgid; |
145 | event->fork.pid = tgid; | 155 | event->fork.pid = tgid; |
@@ -368,19 +378,23 @@ static int __event__synthesize_thread(union perf_event *comm_event, | |||
368 | if (*end) | 378 | if (*end) |
369 | continue; | 379 | continue; |
370 | 380 | ||
371 | tgid = perf_event__synthesize_comm(tool, comm_event, _pid, | 381 | tgid = perf_event__prepare_comm(comm_event, _pid, machine); |
372 | process, machine); | ||
373 | if (tgid == -1) | 382 | if (tgid == -1) |
374 | return -1; | 383 | return -1; |
375 | 384 | ||
385 | if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid, | ||
386 | process, machine) < 0) | ||
387 | return -1; | ||
388 | /* | ||
389 | * Send the prepared comm event | ||
390 | */ | ||
391 | if (process(tool, comm_event, &synth_sample, machine) != 0) | ||
392 | return -1; | ||
393 | |||
376 | if (_pid == pid) { | 394 | if (_pid == pid) { |
377 | /* process the parent's maps too */ | 395 | /* process the parent's maps too */ |
378 | rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, | 396 | rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, |
379 | process, machine, mmap_data); | 397 | process, machine, mmap_data); |
380 | } else { | ||
381 | /* only fork the tid's map, to save time */ | ||
382 | rc = perf_event__synthesize_fork(tool, fork_event, _pid, tgid, | ||
383 | process, machine); | ||
384 | } | 398 | } |
385 | 399 | ||
386 | if (rc) | 400 | if (rc) |