blob: eda41673c4f3c6360a821a625127917993f8a485 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Tom Zanussi454c4072010-05-01 01:41:20 -05002/*
3 * builtin-inject.c
4 *
5 * Builtin inject command: Examine the live mode (stdin) event stream
6 * and repipe it to stdout while optionally injecting additional
7 * events into it.
8 */
9#include "builtin.h"
10
11#include "perf.h"
Andrew Vagin26a031e2012-08-07 16:56:04 +040012#include "util/color.h"
13#include "util/evlist.h"
14#include "util/evsel.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050015#include "util/session.h"
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020016#include "util/tool.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050017#include "util/debug.h"
Andrew Vagin54a3cf52012-08-07 16:56:05 +040018#include "util/build-id.h"
Jiri Olsaf5fc14122013-10-15 16:27:32 +020019#include "util/data.h"
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +030020#include "util/auxtrace.h"
Stephane Eranian9b07e272015-11-30 10:02:21 +010021#include "util/jit.h"
Arnaldo Carvalho de Meloe7ff8922017-04-19 21:34:35 -030022#include "util/thread.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050023
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060024#include <subcmd/parse-options.h>
Tom Zanussi454c4072010-05-01 01:41:20 -050025
Andrew Vagin26a031e2012-08-07 16:56:04 +040026#include <linux/list.h>
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -030027#include <errno.h>
Arnaldo Carvalho de Melo9607ad32017-04-19 15:49:18 -030028#include <signal.h>
Andrew Vagin26a031e2012-08-07 16:56:04 +040029
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -030030struct perf_inject {
Jiri Olsa34069122013-10-29 19:04:57 +010031 struct perf_tool tool;
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +090032 struct perf_session *session;
Jiri Olsa34069122013-10-29 19:04:57 +010033 bool build_ids;
34 bool sched_stat;
Adrian Huntercd10b282015-04-30 17:37:26 +030035 bool have_auxtrace;
Adrian Hunterf56fb982015-09-25 16:15:55 +030036 bool strip;
Stephane Eranian9b07e272015-11-30 10:02:21 +010037 bool jit_mode;
Jiri Olsa34069122013-10-29 19:04:57 +010038 const char *input_name;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010039 struct perf_data output;
Jiri Olsa34069122013-10-29 19:04:57 +010040 u64 bytes_written;
Adrian Hunter73117302015-09-25 16:15:54 +030041 u64 aux_id;
Jiri Olsa34069122013-10-29 19:04:57 +010042 struct list_head samples;
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +030043 struct itrace_synth_opts itrace_synth_opts;
Andrew Vagin26a031e2012-08-07 16:56:04 +040044};
45
46struct event_entry {
47 struct list_head node;
48 u32 tid;
49 union perf_event event[0];
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -030050};
Tom Zanussi454c4072010-05-01 01:41:20 -050051
Adrian Huntercd17a9b2015-04-21 12:21:54 +030052static int output_bytes(struct perf_inject *inject, void *buf, size_t sz)
Tom Zanussi454c4072010-05-01 01:41:20 -050053{
Jiri Olsa34069122013-10-29 19:04:57 +010054 ssize_t size;
Tom Zanussi454c4072010-05-01 01:41:20 -050055
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010056 size = perf_data__write(&inject->output, buf, sz);
Jiri Olsa34069122013-10-29 19:04:57 +010057 if (size < 0)
58 return -errno;
Tom Zanussi454c4072010-05-01 01:41:20 -050059
Jiri Olsa34069122013-10-29 19:04:57 +010060 inject->bytes_written += size;
Tom Zanussi454c4072010-05-01 01:41:20 -050061 return 0;
62}
63
Adrian Huntercd17a9b2015-04-21 12:21:54 +030064static int perf_event__repipe_synth(struct perf_tool *tool,
65 union perf_event *event)
66{
67 struct perf_inject *inject = container_of(tool, struct perf_inject,
68 tool);
69
70 return output_bytes(inject, event, event->header.size);
71}
72
Arnaldo Carvalho de Melod704ebd2015-03-03 12:37:54 -030073static int perf_event__repipe_oe_synth(struct perf_tool *tool,
74 union perf_event *event,
75 struct ordered_events *oe __maybe_unused)
76{
77 return perf_event__repipe_synth(tool, event);
78}
79
Jiri Olsae12b2022016-03-10 17:41:13 +010080#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +010081static int perf_event__drop_oe(struct perf_tool *tool __maybe_unused,
82 union perf_event *event __maybe_unused,
83 struct ordered_events *oe __maybe_unused)
84{
85 return 0;
86}
87#endif
88
Jiri Olsa89f16882018-09-13 14:54:03 +020089static int perf_event__repipe_op2_synth(struct perf_session *session,
90 union perf_event *event)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020091{
Jiri Olsa89f16882018-09-13 14:54:03 +020092 return perf_event__repipe_synth(session->tool, event);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020093}
94
Adrian Hunter47c3d102013-07-04 16:20:21 +030095static int perf_event__repipe_attr(struct perf_tool *tool,
96 union perf_event *event,
97 struct perf_evlist **pevlist)
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020098{
Adrian Hunter89c97d92013-10-22 10:34:09 +030099 struct perf_inject *inject = container_of(tool, struct perf_inject,
100 tool);
Stephane Eranian1a1ed1b2012-05-15 13:28:11 +0200101 int ret;
Adrian Hunter47c3d102013-07-04 16:20:21 +0300102
103 ret = perf_event__process_attr(tool, event, pevlist);
Stephane Eranian1a1ed1b2012-05-15 13:28:11 +0200104 if (ret)
105 return ret;
106
Jiri Olsaa261e4a2014-06-05 18:51:44 +0200107 if (!inject->output.is_pipe)
Adrian Hunter89c97d92013-10-22 10:34:09 +0300108 return 0;
109
Adrian Hunter47c3d102013-07-04 16:20:21 +0300110 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -0200111}
112
Adrian Huntere31f0d02015-04-30 17:37:27 +0300113#ifdef HAVE_AUXTRACE_SUPPORT
114
115static int copy_bytes(struct perf_inject *inject, int fd, off_t size)
116{
117 char buf[4096];
118 ssize_t ssz;
119 int ret;
120
121 while (size > 0) {
122 ssz = read(fd, buf, min(size, (off_t)sizeof(buf)));
123 if (ssz < 0)
124 return -errno;
125 ret = output_bytes(inject, buf, ssz);
126 if (ret)
127 return ret;
128 size -= ssz;
129 }
130
131 return 0;
132}
133
Jiri Olsa73365552018-09-13 14:54:04 +0200134static s64 perf_event__repipe_auxtrace(struct perf_session *session,
135 union perf_event *event)
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300136{
Jiri Olsa73365552018-09-13 14:54:04 +0200137 struct perf_tool *tool = session->tool;
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300138 struct perf_inject *inject = container_of(tool, struct perf_inject,
139 tool);
140 int ret;
141
Adrian Huntercd10b282015-04-30 17:37:26 +0300142 inject->have_auxtrace = true;
143
Adrian Hunter99fa2982015-04-30 17:37:25 +0300144 if (!inject->output.is_pipe) {
145 off_t offset;
146
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100147 offset = lseek(inject->output.file.fd, 0, SEEK_CUR);
Adrian Hunter99fa2982015-04-30 17:37:25 +0300148 if (offset == -1)
149 return -errno;
150 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
151 event, offset);
152 if (ret < 0)
153 return ret;
154 }
155
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100156 if (perf_data__is_pipe(session->data) || !session->one_mmap) {
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300157 ret = output_bytes(inject, event, event->header.size);
158 if (ret < 0)
159 return ret;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100160 ret = copy_bytes(inject, perf_data__fd(session->data),
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300161 event->auxtrace.size);
162 } else {
163 ret = output_bytes(inject, event,
164 event->header.size + event->auxtrace.size);
165 }
166 if (ret < 0)
167 return ret;
168
169 return event->auxtrace.size;
170}
171
Adrian Huntere31f0d02015-04-30 17:37:27 +0300172#else
173
174static s64
Jiri Olsa73365552018-09-13 14:54:04 +0200175perf_event__repipe_auxtrace(struct perf_session *session __maybe_unused,
176 union perf_event *event __maybe_unused)
Adrian Huntere31f0d02015-04-30 17:37:27 +0300177{
178 pr_err("AUX area tracing not supported\n");
179 return -EINVAL;
180}
181
182#endif
183
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200184static int perf_event__repipe(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200185 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300186 struct perf_sample *sample __maybe_unused,
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300187 struct machine *machine __maybe_unused)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200188{
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300189 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200190}
191
Adrian Hunterf56fb982015-09-25 16:15:55 +0300192static int perf_event__drop(struct perf_tool *tool __maybe_unused,
193 union perf_event *event __maybe_unused,
194 struct perf_sample *sample __maybe_unused,
195 struct machine *machine __maybe_unused)
196{
197 return 0;
198}
199
Adrian Hunter73117302015-09-25 16:15:54 +0300200static int perf_event__drop_aux(struct perf_tool *tool,
201 union perf_event *event __maybe_unused,
202 struct perf_sample *sample,
203 struct machine *machine __maybe_unused)
204{
205 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
206
207 if (!inject->aux_id)
208 inject->aux_id = sample->id;
209
210 return 0;
211}
212
Andrew Vagin26a031e2012-08-07 16:56:04 +0400213typedef int (*inject_handler)(struct perf_tool *tool,
214 union perf_event *event,
215 struct perf_sample *sample,
216 struct perf_evsel *evsel,
217 struct machine *machine);
218
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200219static int perf_event__repipe_sample(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200220 union perf_event *event,
Andrew Vagin26a031e2012-08-07 16:56:04 +0400221 struct perf_sample *sample,
222 struct perf_evsel *evsel,
223 struct machine *machine)
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300224{
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300225 if (evsel->handler) {
226 inject_handler f = evsel->handler;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400227 return f(tool, event, sample, evsel, machine);
228 }
229
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400230 build_id__mark_dso_hit(tool, event, sample, evsel, machine);
231
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300232 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300233}
234
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200235static int perf_event__repipe_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200236 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200237 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200238 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500239{
240 int err;
241
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200242 err = perf_event__process_mmap(tool, event, sample, machine);
243 perf_event__repipe(tool, event, sample, machine);
Tom Zanussi454c4072010-05-01 01:41:20 -0500244
245 return err;
246}
247
Jiri Olsae12b2022016-03-10 17:41:13 +0100248#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100249static int perf_event__jit_repipe_mmap(struct perf_tool *tool,
250 union perf_event *event,
251 struct perf_sample *sample,
252 struct machine *machine)
253{
254 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
255 u64 n = 0;
Adrian Hunter570735b2016-03-07 16:44:40 -0300256 int ret;
Stephane Eranian9b07e272015-11-30 10:02:21 +0100257
258 /*
259 * if jit marker, then inject jit mmaps and generate ELF images
260 */
Adrian Hunter570735b2016-03-07 16:44:40 -0300261 ret = jit_process(inject->session, &inject->output, machine,
262 event->mmap.filename, sample->pid, &n);
263 if (ret < 0)
264 return ret;
265 if (ret) {
Stephane Eranian9b07e272015-11-30 10:02:21 +0100266 inject->bytes_written += n;
267 return 0;
268 }
269 return perf_event__repipe_mmap(tool, event, sample, machine);
270}
271#endif
272
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200273static int perf_event__repipe_mmap2(struct perf_tool *tool,
274 union perf_event *event,
275 struct perf_sample *sample,
276 struct machine *machine)
277{
278 int err;
279
280 err = perf_event__process_mmap2(tool, event, sample, machine);
281 perf_event__repipe(tool, event, sample, machine);
282
283 return err;
284}
285
Jiri Olsae12b2022016-03-10 17:41:13 +0100286#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100287static int perf_event__jit_repipe_mmap2(struct perf_tool *tool,
288 union perf_event *event,
289 struct perf_sample *sample,
290 struct machine *machine)
291{
292 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
293 u64 n = 0;
Adrian Hunter570735b2016-03-07 16:44:40 -0300294 int ret;
Stephane Eranian9b07e272015-11-30 10:02:21 +0100295
296 /*
297 * if jit marker, then inject jit mmaps and generate ELF images
298 */
Adrian Hunter570735b2016-03-07 16:44:40 -0300299 ret = jit_process(inject->session, &inject->output, machine,
300 event->mmap2.filename, sample->pid, &n);
301 if (ret < 0)
302 return ret;
303 if (ret) {
Stephane Eranian9b07e272015-11-30 10:02:21 +0100304 inject->bytes_written += n;
305 return 0;
306 }
307 return perf_event__repipe_mmap2(tool, event, sample, machine);
308}
309#endif
310
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300311static int perf_event__repipe_fork(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200312 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200313 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200314 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500315{
316 int err;
317
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300318 err = perf_event__process_fork(tool, event, sample, machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200319 perf_event__repipe(tool, event, sample, machine);
Tom Zanussi454c4072010-05-01 01:41:20 -0500320
321 return err;
322}
323
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300324static int perf_event__repipe_comm(struct perf_tool *tool,
325 union perf_event *event,
326 struct perf_sample *sample,
327 struct machine *machine)
328{
329 int err;
330
331 err = perf_event__process_comm(tool, event, sample, machine);
332 perf_event__repipe(tool, event, sample, machine);
333
334 return err;
335}
336
Hari Bathinif3b36142017-03-08 02:11:43 +0530337static int perf_event__repipe_namespaces(struct perf_tool *tool,
338 union perf_event *event,
339 struct perf_sample *sample,
340 struct machine *machine)
341{
342 int err = perf_event__process_namespaces(tool, event, sample, machine);
343
344 perf_event__repipe(tool, event, sample, machine);
345
346 return err;
347}
348
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300349static int perf_event__repipe_exit(struct perf_tool *tool,
350 union perf_event *event,
351 struct perf_sample *sample,
352 struct machine *machine)
353{
354 int err;
355
356 err = perf_event__process_exit(tool, event, sample, machine);
357 perf_event__repipe(tool, event, sample, machine);
358
359 return err;
360}
361
Jiri Olsa89f16882018-09-13 14:54:03 +0200362static int perf_event__repipe_tracing_data(struct perf_session *session,
363 union perf_event *event)
Tom Zanussi454c4072010-05-01 01:41:20 -0500364{
365 int err;
366
Jiri Olsa89f16882018-09-13 14:54:03 +0200367 perf_event__repipe_synth(session->tool, event);
368 err = perf_event__process_tracing_data(session, event);
Tom Zanussi454c4072010-05-01 01:41:20 -0500369
370 return err;
371}
372
Jiri Olsa89f16882018-09-13 14:54:03 +0200373static int perf_event__repipe_id_index(struct perf_session *session,
374 union perf_event *event)
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300375{
376 int err;
377
Jiri Olsa89f16882018-09-13 14:54:03 +0200378 perf_event__repipe_synth(session->tool, event);
379 err = perf_event__process_id_index(session, event);
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300380
381 return err;
382}
383
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300384static int dso__read_build_id(struct dso *dso)
Tom Zanussi454c4072010-05-01 01:41:20 -0500385{
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300386 if (dso->has_build_id)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300387 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500388
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300389 if (filename__read_build_id(dso->long_name, dso->build_id,
390 sizeof(dso->build_id)) > 0) {
391 dso->has_build_id = true;
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300392 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500393 }
394
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300395 return -1;
396}
Tom Zanussi454c4072010-05-01 01:41:20 -0500397
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300398static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200399 struct machine *machine)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300400{
401 u16 misc = PERF_RECORD_MISC_USER;
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300402 int err;
Tom Zanussi454c4072010-05-01 01:41:20 -0500403
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300404 if (dso__read_build_id(dso) < 0) {
405 pr_debug("no build_id found for %s\n", dso->long_name);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300406 return -1;
407 }
Tom Zanussi454c4072010-05-01 01:41:20 -0500408
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300409 if (dso->kernel)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300410 misc = PERF_RECORD_MISC_KERNEL;
411
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300412 err = perf_event__synthesize_build_id(tool, dso, misc, perf_event__repipe,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200413 machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300414 if (err) {
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300415 pr_err("Can't synthesize build_id event for %s\n", dso->long_name);
Tom Zanussi454c4072010-05-01 01:41:20 -0500416 return -1;
417 }
418
419 return 0;
420}
421
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200422static int perf_event__inject_buildid(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200423 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200424 struct perf_sample *sample,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300425 struct perf_evsel *evsel __maybe_unused,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200426 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500427{
428 struct addr_location al;
429 struct thread *thread;
Tom Zanussi454c4072010-05-01 01:41:20 -0500430
Namhyung Kim13ce34d2014-05-12 09:56:42 +0900431 thread = machine__findnew_thread(machine, sample->pid, sample->tid);
Tom Zanussi454c4072010-05-01 01:41:20 -0500432 if (thread == NULL) {
433 pr_err("problem processing %d event, skipping it.\n",
434 event->header.type);
Tom Zanussi454c4072010-05-01 01:41:20 -0500435 goto repipe;
436 }
437
Arnaldo Carvalho de Melo71a84b52018-04-24 11:58:56 -0300438 if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
Tom Zanussi454c4072010-05-01 01:41:20 -0500439 if (!al.map->dso->hit) {
440 al.map->dso->hit = 1;
Arnaldo Carvalho de Melobe39db92016-09-01 19:25:52 -0300441 if (map__load(al.map) >= 0) {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200442 dso__inject_build_id(al.map->dso, tool, machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300443 /*
444 * If this fails, too bad, let the other side
445 * account this as unresolved.
446 */
Namhyung Kim393be2e2012-08-06 13:41:21 +0900447 } else {
Ingo Molnar89fe8082013-09-30 12:07:11 +0200448#ifdef HAVE_LIBELF_SUPPORT
Tom Zanussi454c4072010-05-01 01:41:20 -0500449 pr_warning("no symbols found in %s, maybe "
450 "install a debug package?\n",
451 al.map->dso->long_name);
Namhyung Kim393be2e2012-08-06 13:41:21 +0900452#endif
453 }
Tom Zanussi454c4072010-05-01 01:41:20 -0500454 }
455 }
456
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300457 thread__put(thread);
Tom Zanussi454c4072010-05-01 01:41:20 -0500458repipe:
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200459 perf_event__repipe(tool, event, sample, machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300460 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500461}
462
Andrew Vagin26a031e2012-08-07 16:56:04 +0400463static int perf_inject__sched_process_exit(struct perf_tool *tool,
464 union perf_event *event __maybe_unused,
465 struct perf_sample *sample,
466 struct perf_evsel *evsel __maybe_unused,
467 struct machine *machine __maybe_unused)
468{
469 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
470 struct event_entry *ent;
471
472 list_for_each_entry(ent, &inject->samples, node) {
473 if (sample->tid == ent->tid) {
474 list_del_init(&ent->node);
475 free(ent);
476 break;
477 }
478 }
479
480 return 0;
481}
482
483static int perf_inject__sched_switch(struct perf_tool *tool,
484 union perf_event *event,
485 struct perf_sample *sample,
486 struct perf_evsel *evsel,
487 struct machine *machine)
488{
489 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
490 struct event_entry *ent;
491
492 perf_inject__sched_process_exit(tool, event, sample, evsel, machine);
493
494 ent = malloc(event->header.size + sizeof(struct event_entry));
495 if (ent == NULL) {
496 color_fprintf(stderr, PERF_COLOR_RED,
497 "Not enough memory to process sched switch event!");
498 return -1;
499 }
500
501 ent->tid = sample->tid;
502 memcpy(&ent->event, event, event->header.size);
503 list_add(&ent->node, &inject->samples);
504 return 0;
505}
506
507static int perf_inject__sched_stat(struct perf_tool *tool,
508 union perf_event *event __maybe_unused,
509 struct perf_sample *sample,
510 struct perf_evsel *evsel,
511 struct machine *machine)
512{
513 struct event_entry *ent;
514 union perf_event *event_sw;
515 struct perf_sample sample_sw;
516 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
517 u32 pid = perf_evsel__intval(evsel, sample, "pid");
518
519 list_for_each_entry(ent, &inject->samples, node) {
520 if (pid == ent->tid)
521 goto found;
522 }
523
524 return 0;
525found:
526 event_sw = &ent->event[0];
527 perf_evsel__parse_sample(evsel, event_sw, &sample_sw);
528
529 sample_sw.period = sample->period;
530 sample_sw.time = sample->time;
531 perf_event__synthesize_sample(event_sw, evsel->attr.sample_type,
Adrian Hunter936f1f32018-01-16 15:14:52 +0200532 evsel->attr.read_format, &sample_sw);
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400533 build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine);
Andrew Vagin26a031e2012-08-07 16:56:04 +0400534 return perf_event__repipe(tool, event_sw, &sample_sw, machine);
535}
536
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300537static void sig_handler(int sig __maybe_unused)
Tom Zanussi454c4072010-05-01 01:41:20 -0500538{
539 session_done = 1;
540}
541
Andrew Vagin26a031e2012-08-07 16:56:04 +0400542static int perf_evsel__check_stype(struct perf_evsel *evsel,
543 u64 sample_type, const char *sample_msg)
544{
545 struct perf_event_attr *attr = &evsel->attr;
546 const char *name = perf_evsel__name(evsel);
547
548 if (!(attr->sample_type & sample_type)) {
549 pr_err("Samples for %s event do not have %s attribute set.",
550 name, sample_msg);
551 return -EINVAL;
552 }
553
554 return 0;
555}
556
Adrian Hunterf56fb982015-09-25 16:15:55 +0300557static int drop_sample(struct perf_tool *tool __maybe_unused,
558 union perf_event *event __maybe_unused,
559 struct perf_sample *sample __maybe_unused,
560 struct perf_evsel *evsel __maybe_unused,
561 struct machine *machine __maybe_unused)
562{
563 return 0;
564}
565
566static void strip_init(struct perf_inject *inject)
567{
568 struct perf_evlist *evlist = inject->session->evlist;
569 struct perf_evsel *evsel;
570
571 inject->tool.context_switch = perf_event__drop;
572
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300573 evlist__for_each_entry(evlist, evsel)
Adrian Hunterf56fb982015-09-25 16:15:55 +0300574 evsel->handler = drop_sample;
575}
576
577static bool has_tracking(struct perf_evsel *evsel)
578{
579 return evsel->attr.mmap || evsel->attr.mmap2 || evsel->attr.comm ||
580 evsel->attr.task;
581}
582
583#define COMPAT_MASK (PERF_SAMPLE_ID | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
584 PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER)
585
586/*
587 * In order that the perf.data file is parsable, tracking events like MMAP need
588 * their selected event to exist, except if there is only 1 selected event left
589 * and it has a compatible sample type.
590 */
591static bool ok_to_remove(struct perf_evlist *evlist,
592 struct perf_evsel *evsel_to_remove)
593{
594 struct perf_evsel *evsel;
595 int cnt = 0;
596 bool ok = false;
597
598 if (!has_tracking(evsel_to_remove))
599 return true;
600
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300601 evlist__for_each_entry(evlist, evsel) {
Adrian Hunterf56fb982015-09-25 16:15:55 +0300602 if (evsel->handler != drop_sample) {
603 cnt += 1;
604 if ((evsel->attr.sample_type & COMPAT_MASK) ==
605 (evsel_to_remove->attr.sample_type & COMPAT_MASK))
606 ok = true;
607 }
608 }
609
610 return ok && cnt == 1;
611}
612
613static void strip_fini(struct perf_inject *inject)
614{
615 struct perf_evlist *evlist = inject->session->evlist;
616 struct perf_evsel *evsel, *tmp;
617
618 /* Remove non-synthesized evsels if possible */
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300619 evlist__for_each_entry_safe(evlist, tmp, evsel) {
Adrian Hunterf56fb982015-09-25 16:15:55 +0300620 if (evsel->handler == drop_sample &&
621 ok_to_remove(evlist, evsel)) {
622 pr_debug("Deleting %s\n", perf_evsel__name(evsel));
623 perf_evlist__remove(evlist, evsel);
624 perf_evsel__delete(evsel);
625 }
626 }
627}
628
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300629static int __cmd_inject(struct perf_inject *inject)
Tom Zanussi454c4072010-05-01 01:41:20 -0500630{
Tom Zanussi454c4072010-05-01 01:41:20 -0500631 int ret = -EINVAL;
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900632 struct perf_session *session = inject->session;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100633 struct perf_data *data_out = &inject->output;
634 int fd = perf_data__fd(data_out);
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300635 u64 output_data_offset;
Tom Zanussi454c4072010-05-01 01:41:20 -0500636
637 signal(SIGINT, sig_handler);
638
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300639 if (inject->build_ids || inject->sched_stat ||
640 inject->itrace_synth_opts.set) {
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300641 inject->tool.mmap = perf_event__repipe_mmap;
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200642 inject->tool.mmap2 = perf_event__repipe_mmap2;
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300643 inject->tool.fork = perf_event__repipe_fork;
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300644 inject->tool.tracing_data = perf_event__repipe_tracing_data;
Tom Zanussi454c4072010-05-01 01:41:20 -0500645 }
646
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300647 output_data_offset = session->header.data_offset;
648
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400649 if (inject->build_ids) {
650 inject->tool.sample = perf_event__inject_buildid;
651 } else if (inject->sched_stat) {
Andrew Vagin26a031e2012-08-07 16:56:04 +0400652 struct perf_evsel *evsel;
653
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300654 evlist__for_each_entry(session->evlist, evsel) {
Andrew Vagin26a031e2012-08-07 16:56:04 +0400655 const char *name = perf_evsel__name(evsel);
656
657 if (!strcmp(name, "sched:sched_switch")) {
658 if (perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID"))
659 return -EINVAL;
660
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300661 evsel->handler = perf_inject__sched_switch;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400662 } else if (!strcmp(name, "sched:sched_process_exit"))
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300663 evsel->handler = perf_inject__sched_process_exit;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400664 else if (!strncmp(name, "sched:sched_stat_", 17))
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300665 evsel->handler = perf_inject__sched_stat;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400666 }
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300667 } else if (inject->itrace_synth_opts.set) {
668 session->itrace_synth_opts = &inject->itrace_synth_opts;
669 inject->itrace_synth_opts.inject = true;
670 inject->tool.comm = perf_event__repipe_comm;
Hari Bathinif3b36142017-03-08 02:11:43 +0530671 inject->tool.namespaces = perf_event__repipe_namespaces;
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300672 inject->tool.exit = perf_event__repipe_exit;
673 inject->tool.id_index = perf_event__repipe_id_index;
674 inject->tool.auxtrace_info = perf_event__process_auxtrace_info;
675 inject->tool.auxtrace = perf_event__process_auxtrace;
Adrian Hunter73117302015-09-25 16:15:54 +0300676 inject->tool.aux = perf_event__drop_aux;
677 inject->tool.itrace_start = perf_event__drop_aux,
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300678 inject->tool.ordered_events = true;
679 inject->tool.ordering_requires_timestamps = true;
680 /* Allow space in the header for new attributes */
681 output_data_offset = 4096;
Adrian Hunterf56fb982015-09-25 16:15:55 +0300682 if (inject->strip)
683 strip_init(inject);
Andrew Vagin26a031e2012-08-07 16:56:04 +0400684 }
685
Adrian Hunter99fa2982015-04-30 17:37:25 +0300686 if (!inject->itrace_synth_opts.set)
687 auxtrace_index__free(&session->auxtrace_index);
688
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100689 if (!data_out->is_pipe)
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300690 lseek(fd, output_data_offset, SEEK_SET);
Andrew Vagine558a5b2012-08-07 16:56:02 +0400691
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300692 ret = perf_session__process_events(session);
David Carrillo-Cisnerosbb8d5212017-04-10 13:14:26 -0700693 if (ret)
694 return ret;
Tom Zanussi454c4072010-05-01 01:41:20 -0500695
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100696 if (!data_out->is_pipe) {
Adrian Hunter640dad42016-03-07 16:44:38 -0300697 if (inject->build_ids)
Adrian Huntere38b43c2014-07-14 13:02:34 +0300698 perf_header__set_feat(&session->header,
699 HEADER_BUILD_ID);
Adrian Hunter640dad42016-03-07 16:44:38 -0300700 /*
701 * Keep all buildids when there is unprocessed AUX data because
702 * it is not known which ones the AUX trace hits.
703 */
704 if (perf_header__has_feat(&session->header, HEADER_BUILD_ID) &&
705 inject->have_auxtrace && !inject->itrace_synth_opts.set)
706 dsos__hit_all(session);
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300707 /*
708 * The AUX areas have been removed and replaced with
Adrian Hunter73117302015-09-25 16:15:54 +0300709 * synthesized hardware events, so clear the feature flag and
710 * remove the evsel.
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300711 */
Adrian Hunter051a01b2015-09-25 16:15:43 +0300712 if (inject->itrace_synth_opts.set) {
Adrian Hunter73117302015-09-25 16:15:54 +0300713 struct perf_evsel *evsel;
714
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300715 perf_header__clear_feat(&session->header,
716 HEADER_AUXTRACE);
Adrian Hunter051a01b2015-09-25 16:15:43 +0300717 if (inject->itrace_synth_opts.last_branch)
718 perf_header__set_feat(&session->header,
719 HEADER_BRANCH_STACK);
Adrian Hunter73117302015-09-25 16:15:54 +0300720 evsel = perf_evlist__id2evsel_strict(session->evlist,
721 inject->aux_id);
722 if (evsel) {
723 pr_debug("Deleting %s\n",
724 perf_evsel__name(evsel));
725 perf_evlist__remove(session->evlist, evsel);
726 perf_evsel__delete(evsel);
727 }
Adrian Hunterf56fb982015-09-25 16:15:55 +0300728 if (inject->strip)
729 strip_fini(inject);
Adrian Hunter051a01b2015-09-25 16:15:43 +0300730 }
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300731 session->header.data_offset = output_data_offset;
Andrew Vagine558a5b2012-08-07 16:56:02 +0400732 session->header.data_size = inject->bytes_written;
Namhyung Kim42aa2762015-01-29 17:06:48 +0900733 perf_session__write_header(session, session->evlist, fd, true);
Andrew Vagine558a5b2012-08-07 16:56:02 +0400734 }
735
Tom Zanussi454c4072010-05-01 01:41:20 -0500736 return ret;
737}
738
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -0300739int cmd_inject(int argc, const char **argv)
Tom Zanussi454c4072010-05-01 01:41:20 -0500740{
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300741 struct perf_inject inject = {
742 .tool = {
743 .sample = perf_event__repipe_sample,
744 .mmap = perf_event__repipe,
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200745 .mmap2 = perf_event__repipe,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300746 .comm = perf_event__repipe,
747 .fork = perf_event__repipe,
748 .exit = perf_event__repipe,
749 .lost = perf_event__repipe,
Adrian Hunterd8145b32015-11-13 11:48:32 +0200750 .lost_samples = perf_event__repipe,
Adrian Hunter4a96f7a2015-04-30 17:37:29 +0300751 .aux = perf_event__repipe,
Adrian Hunter0ad21f62015-04-30 17:37:30 +0300752 .itrace_start = perf_event__repipe,
Adrian Hunter02860392015-07-21 12:44:03 +0300753 .context_switch = perf_event__repipe,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300754 .read = perf_event__repipe_sample,
755 .throttle = perf_event__repipe,
756 .unthrottle = perf_event__repipe,
757 .attr = perf_event__repipe_attr,
Adrian Hunter47c3d102013-07-04 16:20:21 +0300758 .tracing_data = perf_event__repipe_op2_synth,
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300759 .auxtrace_info = perf_event__repipe_op2_synth,
760 .auxtrace = perf_event__repipe_auxtrace,
761 .auxtrace_error = perf_event__repipe_op2_synth,
Adrian Hunter46bc29b2016-03-08 10:38:44 +0200762 .time_conv = perf_event__repipe_op2_synth,
Arnaldo Carvalho de Melod704ebd2015-03-03 12:37:54 -0300763 .finished_round = perf_event__repipe_oe_synth,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300764 .build_id = perf_event__repipe_op2_synth,
Adrian Hunter3c659ee2014-10-27 15:49:22 +0200765 .id_index = perf_event__repipe_op2_synth,
David Carrillo-Cisnerose9def1b2017-07-17 21:25:48 -0700766 .feature = perf_event__repipe_op2_synth,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300767 },
Andrew Vagine558a5b2012-08-07 16:56:02 +0400768 .input_name = "-",
Andrew Vagin26a031e2012-08-07 16:56:04 +0400769 .samples = LIST_HEAD_INIT(inject.samples),
Jiri Olsa34069122013-10-29 19:04:57 +0100770 .output = {
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100771 .file = {
772 .path = "-",
773 },
774 .mode = PERF_DATA_MODE_WRITE,
Jiri Olsa34069122013-10-29 19:04:57 +0100775 },
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300776 };
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100777 struct perf_data data = {
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900778 .mode = PERF_DATA_MODE_READ,
779 };
780 int ret;
781
Stephane Eranian9b07e272015-11-30 10:02:21 +0100782 struct option options[] = {
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300783 OPT_BOOLEAN('b', "build-ids", &inject.build_ids,
784 "Inject build-ids into the output stream"),
Andrew Vagine558a5b2012-08-07 16:56:02 +0400785 OPT_STRING('i', "input", &inject.input_name, "file",
786 "input file name"),
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100787 OPT_STRING('o', "output", &inject.output.file.path, "file",
Andrew Vagine558a5b2012-08-07 16:56:02 +0400788 "output file name"),
Andrew Vagin26a031e2012-08-07 16:56:04 +0400789 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
790 "Merge sched-stat and sched-switch for getting events "
791 "where and how long tasks slept"),
Jiri Olsae12b2022016-03-10 17:41:13 +0100792#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100793 OPT_BOOLEAN('j', "jit", &inject.jit_mode, "merge jitdump files into perf.data file"),
Jiri Olsae12b2022016-03-10 17:41:13 +0100794#endif
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300795 OPT_INCR('v', "verbose", &verbose,
796 "be more verbose (show build ids, etc)"),
Adrian Huntera7a2b8b2014-07-22 16:17:38 +0300797 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file",
798 "kallsyms pathname"),
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100799 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300800 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,
Andi Kleenc12e0392018-09-13 20:10:31 -0700801 NULL, "opts", "Instruction Tracing options\n"
802 ITRACE_HELP,
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300803 itrace_parse_synth_opts),
Adrian Hunterf56fb982015-09-25 16:15:55 +0300804 OPT_BOOLEAN(0, "strip", &inject.strip,
805 "strip non-synthesized events (use with --itrace)"),
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300806 OPT_END()
807 };
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300808 const char * const inject_usage[] = {
809 "perf inject [<options>]",
810 NULL
811 };
Jiri Olsae12b2022016-03-10 17:41:13 +0100812#ifndef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100813 set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true);
814#endif
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300815 argc = parse_options(argc, argv, options, inject_usage, 0);
Tom Zanussi454c4072010-05-01 01:41:20 -0500816
817 /*
818 * Any (unrecognized) arguments left?
819 */
820 if (argc)
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300821 usage_with_options(inject_usage, options);
Tom Zanussi454c4072010-05-01 01:41:20 -0500822
Adrian Hunterf56fb982015-09-25 16:15:55 +0300823 if (inject.strip && !inject.itrace_synth_opts.set) {
824 pr_err("--strip option requires --itrace option\n");
825 return -1;
826 }
827
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100828 if (perf_data__open(&inject.output)) {
Jiri Olsa34069122013-10-29 19:04:57 +0100829 perror("failed to create output file");
830 return -1;
Andrew Vagine558a5b2012-08-07 16:56:02 +0400831 }
832
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300833 inject.tool.ordered_events = inject.sched_stat;
834
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100835 data.file.path = inject.input_name;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100836 inject.session = perf_session__new(&data, true, &inject.tool);
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900837 if (inject.session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +0900838 return -1;
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900839
Arnaldo Carvalho de Melo921f3fa2016-01-22 18:41:00 -0300840 if (inject.build_ids) {
841 /*
842 * to make sure the mmap records are ordered correctly
843 * and so that the correct especially due to jitted code
844 * mmaps. We cannot generate the buildid hit list and
845 * inject the jit mmaps at the same time for now.
846 */
847 inject.tool.ordered_events = true;
848 inject.tool.ordering_requires_timestamps = true;
849 }
Jiri Olsae12b2022016-03-10 17:41:13 +0100850#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100851 if (inject.jit_mode) {
Stephane Eranian9b07e272015-11-30 10:02:21 +0100852 inject.tool.mmap2 = perf_event__jit_repipe_mmap2;
853 inject.tool.mmap = perf_event__jit_repipe_mmap;
854 inject.tool.ordered_events = true;
855 inject.tool.ordering_requires_timestamps = true;
856 /*
857 * JIT MMAP injection injects all MMAP events in one go, so it
858 * does not obey finished_round semantics.
859 */
860 inject.tool.finished_round = perf_event__drop_oe;
861 }
862#endif
Taeung Song9fedfb02015-06-30 17:15:20 +0900863 ret = symbol__init(&inject.session->header.env);
864 if (ret < 0)
865 goto out_delete;
Tom Zanussi454c4072010-05-01 01:41:20 -0500866
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900867 ret = __cmd_inject(&inject);
868
Taeung Song9fedfb02015-06-30 17:15:20 +0900869out_delete:
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900870 perf_session__delete(inject.session);
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900871 return ret;
Tom Zanussi454c4072010-05-01 01:41:20 -0500872}