blob: 3499addcfc12e1b5a12fa2ce00c6357522f4c914 [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"
Arnaldo Carvalho de Melo1101f692019-01-27 13:42:37 +010015#include "util/map.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050016#include "util/session.h"
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020017#include "util/tool.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050018#include "util/debug.h"
Andrew Vagin54a3cf52012-08-07 16:56:05 +040019#include "util/build-id.h"
Jiri Olsaf5fc14122013-10-15 16:27:32 +020020#include "util/data.h"
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +030021#include "util/auxtrace.h"
Stephane Eranian9b07e272015-11-30 10:02:21 +010022#include "util/jit.h"
Arnaldo Carvalho de Meloe7ff8922017-04-19 21:34:35 -030023#include "util/thread.h"
Tom Zanussi454c4072010-05-01 01:41:20 -050024
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060025#include <subcmd/parse-options.h>
Tom Zanussi454c4072010-05-01 01:41:20 -050026
Andrew Vagin26a031e2012-08-07 16:56:04 +040027#include <linux/list.h>
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -030028#include <errno.h>
Arnaldo Carvalho de Melo9607ad32017-04-19 15:49:18 -030029#include <signal.h>
Andrew Vagin26a031e2012-08-07 16:56:04 +040030
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -030031struct perf_inject {
Jiri Olsa34069122013-10-29 19:04:57 +010032 struct perf_tool tool;
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +090033 struct perf_session *session;
Jiri Olsa34069122013-10-29 19:04:57 +010034 bool build_ids;
35 bool sched_stat;
Adrian Huntercd10b282015-04-30 17:37:26 +030036 bool have_auxtrace;
Adrian Hunterf56fb982015-09-25 16:15:55 +030037 bool strip;
Stephane Eranian9b07e272015-11-30 10:02:21 +010038 bool jit_mode;
Jiri Olsa34069122013-10-29 19:04:57 +010039 const char *input_name;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010040 struct perf_data output;
Jiri Olsa34069122013-10-29 19:04:57 +010041 u64 bytes_written;
Adrian Hunter73117302015-09-25 16:15:54 +030042 u64 aux_id;
Jiri Olsa34069122013-10-29 19:04:57 +010043 struct list_head samples;
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +030044 struct itrace_synth_opts itrace_synth_opts;
Andrew Vagin26a031e2012-08-07 16:56:04 +040045};
46
47struct event_entry {
48 struct list_head node;
49 u32 tid;
50 union perf_event event[0];
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -030051};
Tom Zanussi454c4072010-05-01 01:41:20 -050052
Adrian Huntercd17a9b2015-04-21 12:21:54 +030053static int output_bytes(struct perf_inject *inject, void *buf, size_t sz)
Tom Zanussi454c4072010-05-01 01:41:20 -050054{
Jiri Olsa34069122013-10-29 19:04:57 +010055 ssize_t size;
Tom Zanussi454c4072010-05-01 01:41:20 -050056
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010057 size = perf_data__write(&inject->output, buf, sz);
Jiri Olsa34069122013-10-29 19:04:57 +010058 if (size < 0)
59 return -errno;
Tom Zanussi454c4072010-05-01 01:41:20 -050060
Jiri Olsa34069122013-10-29 19:04:57 +010061 inject->bytes_written += size;
Tom Zanussi454c4072010-05-01 01:41:20 -050062 return 0;
63}
64
Adrian Huntercd17a9b2015-04-21 12:21:54 +030065static int perf_event__repipe_synth(struct perf_tool *tool,
66 union perf_event *event)
67{
68 struct perf_inject *inject = container_of(tool, struct perf_inject,
69 tool);
70
71 return output_bytes(inject, event, event->header.size);
72}
73
Arnaldo Carvalho de Melod704ebd2015-03-03 12:37:54 -030074static int perf_event__repipe_oe_synth(struct perf_tool *tool,
75 union perf_event *event,
76 struct ordered_events *oe __maybe_unused)
77{
78 return perf_event__repipe_synth(tool, event);
79}
80
Jiri Olsae12b2022016-03-10 17:41:13 +010081#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +010082static int perf_event__drop_oe(struct perf_tool *tool __maybe_unused,
83 union perf_event *event __maybe_unused,
84 struct ordered_events *oe __maybe_unused)
85{
86 return 0;
87}
88#endif
89
Jiri Olsa89f16882018-09-13 14:54:03 +020090static int perf_event__repipe_op2_synth(struct perf_session *session,
91 union perf_event *event)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020092{
Jiri Olsa89f16882018-09-13 14:54:03 +020093 return perf_event__repipe_synth(session->tool, event);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020094}
95
Adrian Hunter47c3d102013-07-04 16:20:21 +030096static int perf_event__repipe_attr(struct perf_tool *tool,
97 union perf_event *event,
98 struct perf_evlist **pevlist)
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020099{
Adrian Hunter89c97d92013-10-22 10:34:09 +0300100 struct perf_inject *inject = container_of(tool, struct perf_inject,
101 tool);
Stephane Eranian1a1ed1b2012-05-15 13:28:11 +0200102 int ret;
Adrian Hunter47c3d102013-07-04 16:20:21 +0300103
104 ret = perf_event__process_attr(tool, event, pevlist);
Stephane Eranian1a1ed1b2012-05-15 13:28:11 +0200105 if (ret)
106 return ret;
107
Jiri Olsaa261e4a2014-06-05 18:51:44 +0200108 if (!inject->output.is_pipe)
Adrian Hunter89c97d92013-10-22 10:34:09 +0300109 return 0;
110
Adrian Hunter47c3d102013-07-04 16:20:21 +0300111 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -0200112}
113
Adrian Huntere31f0d02015-04-30 17:37:27 +0300114#ifdef HAVE_AUXTRACE_SUPPORT
115
116static int copy_bytes(struct perf_inject *inject, int fd, off_t size)
117{
118 char buf[4096];
119 ssize_t ssz;
120 int ret;
121
122 while (size > 0) {
123 ssz = read(fd, buf, min(size, (off_t)sizeof(buf)));
124 if (ssz < 0)
125 return -errno;
126 ret = output_bytes(inject, buf, ssz);
127 if (ret)
128 return ret;
129 size -= ssz;
130 }
131
132 return 0;
133}
134
Jiri Olsa73365552018-09-13 14:54:04 +0200135static s64 perf_event__repipe_auxtrace(struct perf_session *session,
136 union perf_event *event)
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300137{
Jiri Olsa73365552018-09-13 14:54:04 +0200138 struct perf_tool *tool = session->tool;
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300139 struct perf_inject *inject = container_of(tool, struct perf_inject,
140 tool);
141 int ret;
142
Adrian Huntercd10b282015-04-30 17:37:26 +0300143 inject->have_auxtrace = true;
144
Adrian Hunter99fa2982015-04-30 17:37:25 +0300145 if (!inject->output.is_pipe) {
146 off_t offset;
147
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100148 offset = lseek(inject->output.file.fd, 0, SEEK_CUR);
Adrian Hunter99fa2982015-04-30 17:37:25 +0300149 if (offset == -1)
150 return -errno;
151 ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
152 event, offset);
153 if (ret < 0)
154 return ret;
155 }
156
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100157 if (perf_data__is_pipe(session->data) || !session->one_mmap) {
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300158 ret = output_bytes(inject, event, event->header.size);
159 if (ret < 0)
160 return ret;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100161 ret = copy_bytes(inject, perf_data__fd(session->data),
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300162 event->auxtrace.size);
163 } else {
164 ret = output_bytes(inject, event,
165 event->header.size + event->auxtrace.size);
166 }
167 if (ret < 0)
168 return ret;
169
170 return event->auxtrace.size;
171}
172
Adrian Huntere31f0d02015-04-30 17:37:27 +0300173#else
174
175static s64
Jiri Olsa73365552018-09-13 14:54:04 +0200176perf_event__repipe_auxtrace(struct perf_session *session __maybe_unused,
177 union perf_event *event __maybe_unused)
Adrian Huntere31f0d02015-04-30 17:37:27 +0300178{
179 pr_err("AUX area tracing not supported\n");
180 return -EINVAL;
181}
182
183#endif
184
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200185static int perf_event__repipe(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200186 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300187 struct perf_sample *sample __maybe_unused,
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300188 struct machine *machine __maybe_unused)
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200189{
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300190 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -0200191}
192
Adrian Hunterf56fb982015-09-25 16:15:55 +0300193static int perf_event__drop(struct perf_tool *tool __maybe_unused,
194 union perf_event *event __maybe_unused,
195 struct perf_sample *sample __maybe_unused,
196 struct machine *machine __maybe_unused)
197{
198 return 0;
199}
200
Adrian Hunter73117302015-09-25 16:15:54 +0300201static int perf_event__drop_aux(struct perf_tool *tool,
202 union perf_event *event __maybe_unused,
203 struct perf_sample *sample,
204 struct machine *machine __maybe_unused)
205{
206 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
207
208 if (!inject->aux_id)
209 inject->aux_id = sample->id;
210
211 return 0;
212}
213
Andrew Vagin26a031e2012-08-07 16:56:04 +0400214typedef int (*inject_handler)(struct perf_tool *tool,
215 union perf_event *event,
216 struct perf_sample *sample,
217 struct perf_evsel *evsel,
218 struct machine *machine);
219
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200220static int perf_event__repipe_sample(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200221 union perf_event *event,
Andrew Vagin26a031e2012-08-07 16:56:04 +0400222 struct perf_sample *sample,
223 struct perf_evsel *evsel,
224 struct machine *machine)
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300225{
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300226 if (evsel->handler) {
227 inject_handler f = evsel->handler;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400228 return f(tool, event, sample, evsel, machine);
229 }
230
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400231 build_id__mark_dso_hit(tool, event, sample, evsel, machine);
232
Adrian Hunter63c2c9f2013-07-04 16:20:20 +0300233 return perf_event__repipe_synth(tool, event);
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -0300234}
235
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200236static int perf_event__repipe_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200237 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200238 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200239 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500240{
241 int err;
242
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200243 err = perf_event__process_mmap(tool, event, sample, machine);
244 perf_event__repipe(tool, event, sample, machine);
Tom Zanussi454c4072010-05-01 01:41:20 -0500245
246 return err;
247}
248
Jiri Olsae12b2022016-03-10 17:41:13 +0100249#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100250static int perf_event__jit_repipe_mmap(struct perf_tool *tool,
251 union perf_event *event,
252 struct perf_sample *sample,
253 struct machine *machine)
254{
255 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
256 u64 n = 0;
Adrian Hunter570735b2016-03-07 16:44:40 -0300257 int ret;
Stephane Eranian9b07e272015-11-30 10:02:21 +0100258
259 /*
260 * if jit marker, then inject jit mmaps and generate ELF images
261 */
Adrian Hunter570735b2016-03-07 16:44:40 -0300262 ret = jit_process(inject->session, &inject->output, machine,
263 event->mmap.filename, sample->pid, &n);
264 if (ret < 0)
265 return ret;
266 if (ret) {
Stephane Eranian9b07e272015-11-30 10:02:21 +0100267 inject->bytes_written += n;
268 return 0;
269 }
270 return perf_event__repipe_mmap(tool, event, sample, machine);
271}
272#endif
273
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200274static int perf_event__repipe_mmap2(struct perf_tool *tool,
275 union perf_event *event,
276 struct perf_sample *sample,
277 struct machine *machine)
278{
279 int err;
280
281 err = perf_event__process_mmap2(tool, event, sample, machine);
282 perf_event__repipe(tool, event, sample, machine);
283
284 return err;
285}
286
Jiri Olsae12b2022016-03-10 17:41:13 +0100287#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100288static int perf_event__jit_repipe_mmap2(struct perf_tool *tool,
289 union perf_event *event,
290 struct perf_sample *sample,
291 struct machine *machine)
292{
293 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
294 u64 n = 0;
Adrian Hunter570735b2016-03-07 16:44:40 -0300295 int ret;
Stephane Eranian9b07e272015-11-30 10:02:21 +0100296
297 /*
298 * if jit marker, then inject jit mmaps and generate ELF images
299 */
Adrian Hunter570735b2016-03-07 16:44:40 -0300300 ret = jit_process(inject->session, &inject->output, machine,
301 event->mmap2.filename, sample->pid, &n);
302 if (ret < 0)
303 return ret;
304 if (ret) {
Stephane Eranian9b07e272015-11-30 10:02:21 +0100305 inject->bytes_written += n;
306 return 0;
307 }
308 return perf_event__repipe_mmap2(tool, event, sample, machine);
309}
310#endif
311
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300312static int perf_event__repipe_fork(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200313 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200314 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200315 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500316{
317 int err;
318
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300319 err = perf_event__process_fork(tool, event, sample, machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200320 perf_event__repipe(tool, event, sample, machine);
Tom Zanussi454c4072010-05-01 01:41:20 -0500321
322 return err;
323}
324
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300325static int perf_event__repipe_comm(struct perf_tool *tool,
326 union perf_event *event,
327 struct perf_sample *sample,
328 struct machine *machine)
329{
330 int err;
331
332 err = perf_event__process_comm(tool, event, sample, machine);
333 perf_event__repipe(tool, event, sample, machine);
334
335 return err;
336}
337
Hari Bathinif3b36142017-03-08 02:11:43 +0530338static int perf_event__repipe_namespaces(struct perf_tool *tool,
339 union perf_event *event,
340 struct perf_sample *sample,
341 struct machine *machine)
342{
343 int err = perf_event__process_namespaces(tool, event, sample, machine);
344
345 perf_event__repipe(tool, event, sample, machine);
346
347 return err;
348}
349
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300350static int perf_event__repipe_exit(struct perf_tool *tool,
351 union perf_event *event,
352 struct perf_sample *sample,
353 struct machine *machine)
354{
355 int err;
356
357 err = perf_event__process_exit(tool, event, sample, machine);
358 perf_event__repipe(tool, event, sample, machine);
359
360 return err;
361}
362
Jiri Olsa89f16882018-09-13 14:54:03 +0200363static int perf_event__repipe_tracing_data(struct perf_session *session,
364 union perf_event *event)
Tom Zanussi454c4072010-05-01 01:41:20 -0500365{
366 int err;
367
Jiri Olsa89f16882018-09-13 14:54:03 +0200368 perf_event__repipe_synth(session->tool, event);
369 err = perf_event__process_tracing_data(session, event);
Tom Zanussi454c4072010-05-01 01:41:20 -0500370
371 return err;
372}
373
Jiri Olsa89f16882018-09-13 14:54:03 +0200374static int perf_event__repipe_id_index(struct perf_session *session,
375 union perf_event *event)
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300376{
377 int err;
378
Jiri Olsa89f16882018-09-13 14:54:03 +0200379 perf_event__repipe_synth(session->tool, event);
380 err = perf_event__process_id_index(session, event);
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300381
382 return err;
383}
384
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300385static int dso__read_build_id(struct dso *dso)
Tom Zanussi454c4072010-05-01 01:41:20 -0500386{
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300387 if (dso->has_build_id)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300388 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500389
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300390 if (filename__read_build_id(dso->long_name, dso->build_id,
391 sizeof(dso->build_id)) > 0) {
392 dso->has_build_id = true;
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300393 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500394 }
395
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300396 return -1;
397}
Tom Zanussi454c4072010-05-01 01:41:20 -0500398
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300399static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200400 struct machine *machine)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300401{
402 u16 misc = PERF_RECORD_MISC_USER;
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300403 int err;
Tom Zanussi454c4072010-05-01 01:41:20 -0500404
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300405 if (dso__read_build_id(dso) < 0) {
406 pr_debug("no build_id found for %s\n", dso->long_name);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300407 return -1;
408 }
Tom Zanussi454c4072010-05-01 01:41:20 -0500409
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300410 if (dso->kernel)
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300411 misc = PERF_RECORD_MISC_KERNEL;
412
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300413 err = perf_event__synthesize_build_id(tool, dso, misc, perf_event__repipe,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200414 machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300415 if (err) {
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300416 pr_err("Can't synthesize build_id event for %s\n", dso->long_name);
Tom Zanussi454c4072010-05-01 01:41:20 -0500417 return -1;
418 }
419
420 return 0;
421}
422
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200423static int perf_event__inject_buildid(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200424 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200425 struct perf_sample *sample,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300426 struct perf_evsel *evsel __maybe_unused,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200427 struct machine *machine)
Tom Zanussi454c4072010-05-01 01:41:20 -0500428{
429 struct addr_location al;
430 struct thread *thread;
Tom Zanussi454c4072010-05-01 01:41:20 -0500431
Namhyung Kim13ce34d2014-05-12 09:56:42 +0900432 thread = machine__findnew_thread(machine, sample->pid, sample->tid);
Tom Zanussi454c4072010-05-01 01:41:20 -0500433 if (thread == NULL) {
434 pr_err("problem processing %d event, skipping it.\n",
435 event->header.type);
Tom Zanussi454c4072010-05-01 01:41:20 -0500436 goto repipe;
437 }
438
Arnaldo Carvalho de Melo71a84b52018-04-24 11:58:56 -0300439 if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
Tom Zanussi454c4072010-05-01 01:41:20 -0500440 if (!al.map->dso->hit) {
441 al.map->dso->hit = 1;
Arnaldo Carvalho de Melobe39db92016-09-01 19:25:52 -0300442 if (map__load(al.map) >= 0) {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200443 dso__inject_build_id(al.map->dso, tool, machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300444 /*
445 * If this fails, too bad, let the other side
446 * account this as unresolved.
447 */
Namhyung Kim393be2e2012-08-06 13:41:21 +0900448 } else {
Ingo Molnar89fe8082013-09-30 12:07:11 +0200449#ifdef HAVE_LIBELF_SUPPORT
Tom Zanussi454c4072010-05-01 01:41:20 -0500450 pr_warning("no symbols found in %s, maybe "
451 "install a debug package?\n",
452 al.map->dso->long_name);
Namhyung Kim393be2e2012-08-06 13:41:21 +0900453#endif
454 }
Tom Zanussi454c4072010-05-01 01:41:20 -0500455 }
456 }
457
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300458 thread__put(thread);
Tom Zanussi454c4072010-05-01 01:41:20 -0500459repipe:
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200460 perf_event__repipe(tool, event, sample, machine);
Arnaldo Carvalho de Melo090f7202010-05-02 19:46:36 -0300461 return 0;
Tom Zanussi454c4072010-05-01 01:41:20 -0500462}
463
Andrew Vagin26a031e2012-08-07 16:56:04 +0400464static int perf_inject__sched_process_exit(struct perf_tool *tool,
465 union perf_event *event __maybe_unused,
466 struct perf_sample *sample,
467 struct perf_evsel *evsel __maybe_unused,
468 struct machine *machine __maybe_unused)
469{
470 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
471 struct event_entry *ent;
472
473 list_for_each_entry(ent, &inject->samples, node) {
474 if (sample->tid == ent->tid) {
475 list_del_init(&ent->node);
476 free(ent);
477 break;
478 }
479 }
480
481 return 0;
482}
483
484static int perf_inject__sched_switch(struct perf_tool *tool,
485 union perf_event *event,
486 struct perf_sample *sample,
487 struct perf_evsel *evsel,
488 struct machine *machine)
489{
490 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
491 struct event_entry *ent;
492
493 perf_inject__sched_process_exit(tool, event, sample, evsel, machine);
494
495 ent = malloc(event->header.size + sizeof(struct event_entry));
496 if (ent == NULL) {
497 color_fprintf(stderr, PERF_COLOR_RED,
498 "Not enough memory to process sched switch event!");
499 return -1;
500 }
501
502 ent->tid = sample->tid;
503 memcpy(&ent->event, event, event->header.size);
504 list_add(&ent->node, &inject->samples);
505 return 0;
506}
507
508static int perf_inject__sched_stat(struct perf_tool *tool,
509 union perf_event *event __maybe_unused,
510 struct perf_sample *sample,
511 struct perf_evsel *evsel,
512 struct machine *machine)
513{
514 struct event_entry *ent;
515 union perf_event *event_sw;
516 struct perf_sample sample_sw;
517 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
518 u32 pid = perf_evsel__intval(evsel, sample, "pid");
519
520 list_for_each_entry(ent, &inject->samples, node) {
521 if (pid == ent->tid)
522 goto found;
523 }
524
525 return 0;
526found:
527 event_sw = &ent->event[0];
528 perf_evsel__parse_sample(evsel, event_sw, &sample_sw);
529
530 sample_sw.period = sample->period;
531 sample_sw.time = sample->time;
532 perf_event__synthesize_sample(event_sw, evsel->attr.sample_type,
Adrian Hunter936f1f32018-01-16 15:14:52 +0200533 evsel->attr.read_format, &sample_sw);
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400534 build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine);
Andrew Vagin26a031e2012-08-07 16:56:04 +0400535 return perf_event__repipe(tool, event_sw, &sample_sw, machine);
536}
537
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300538static void sig_handler(int sig __maybe_unused)
Tom Zanussi454c4072010-05-01 01:41:20 -0500539{
540 session_done = 1;
541}
542
Andrew Vagin26a031e2012-08-07 16:56:04 +0400543static int perf_evsel__check_stype(struct perf_evsel *evsel,
544 u64 sample_type, const char *sample_msg)
545{
546 struct perf_event_attr *attr = &evsel->attr;
547 const char *name = perf_evsel__name(evsel);
548
549 if (!(attr->sample_type & sample_type)) {
550 pr_err("Samples for %s event do not have %s attribute set.",
551 name, sample_msg);
552 return -EINVAL;
553 }
554
555 return 0;
556}
557
Adrian Hunterf56fb982015-09-25 16:15:55 +0300558static int drop_sample(struct perf_tool *tool __maybe_unused,
559 union perf_event *event __maybe_unused,
560 struct perf_sample *sample __maybe_unused,
561 struct perf_evsel *evsel __maybe_unused,
562 struct machine *machine __maybe_unused)
563{
564 return 0;
565}
566
567static void strip_init(struct perf_inject *inject)
568{
569 struct perf_evlist *evlist = inject->session->evlist;
570 struct perf_evsel *evsel;
571
572 inject->tool.context_switch = perf_event__drop;
573
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300574 evlist__for_each_entry(evlist, evsel)
Adrian Hunterf56fb982015-09-25 16:15:55 +0300575 evsel->handler = drop_sample;
576}
577
578static bool has_tracking(struct perf_evsel *evsel)
579{
580 return evsel->attr.mmap || evsel->attr.mmap2 || evsel->attr.comm ||
581 evsel->attr.task;
582}
583
584#define COMPAT_MASK (PERF_SAMPLE_ID | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
585 PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER)
586
587/*
588 * In order that the perf.data file is parsable, tracking events like MMAP need
589 * their selected event to exist, except if there is only 1 selected event left
590 * and it has a compatible sample type.
591 */
592static bool ok_to_remove(struct perf_evlist *evlist,
593 struct perf_evsel *evsel_to_remove)
594{
595 struct perf_evsel *evsel;
596 int cnt = 0;
597 bool ok = false;
598
599 if (!has_tracking(evsel_to_remove))
600 return true;
601
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300602 evlist__for_each_entry(evlist, evsel) {
Adrian Hunterf56fb982015-09-25 16:15:55 +0300603 if (evsel->handler != drop_sample) {
604 cnt += 1;
605 if ((evsel->attr.sample_type & COMPAT_MASK) ==
606 (evsel_to_remove->attr.sample_type & COMPAT_MASK))
607 ok = true;
608 }
609 }
610
611 return ok && cnt == 1;
612}
613
614static void strip_fini(struct perf_inject *inject)
615{
616 struct perf_evlist *evlist = inject->session->evlist;
617 struct perf_evsel *evsel, *tmp;
618
619 /* Remove non-synthesized evsels if possible */
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300620 evlist__for_each_entry_safe(evlist, tmp, evsel) {
Adrian Hunterf56fb982015-09-25 16:15:55 +0300621 if (evsel->handler == drop_sample &&
622 ok_to_remove(evlist, evsel)) {
623 pr_debug("Deleting %s\n", perf_evsel__name(evsel));
624 perf_evlist__remove(evlist, evsel);
625 perf_evsel__delete(evsel);
626 }
627 }
628}
629
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300630static int __cmd_inject(struct perf_inject *inject)
Tom Zanussi454c4072010-05-01 01:41:20 -0500631{
Tom Zanussi454c4072010-05-01 01:41:20 -0500632 int ret = -EINVAL;
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900633 struct perf_session *session = inject->session;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100634 struct perf_data *data_out = &inject->output;
635 int fd = perf_data__fd(data_out);
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300636 u64 output_data_offset;
Tom Zanussi454c4072010-05-01 01:41:20 -0500637
638 signal(SIGINT, sig_handler);
639
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300640 if (inject->build_ids || inject->sched_stat ||
641 inject->itrace_synth_opts.set) {
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300642 inject->tool.mmap = perf_event__repipe_mmap;
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200643 inject->tool.mmap2 = perf_event__repipe_mmap2;
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300644 inject->tool.fork = perf_event__repipe_fork;
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300645 inject->tool.tracing_data = perf_event__repipe_tracing_data;
Tom Zanussi454c4072010-05-01 01:41:20 -0500646 }
647
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300648 output_data_offset = session->header.data_offset;
649
Andrew Vagin54a3cf52012-08-07 16:56:05 +0400650 if (inject->build_ids) {
651 inject->tool.sample = perf_event__inject_buildid;
652 } else if (inject->sched_stat) {
Andrew Vagin26a031e2012-08-07 16:56:04 +0400653 struct perf_evsel *evsel;
654
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300655 evlist__for_each_entry(session->evlist, evsel) {
Andrew Vagin26a031e2012-08-07 16:56:04 +0400656 const char *name = perf_evsel__name(evsel);
657
658 if (!strcmp(name, "sched:sched_switch")) {
659 if (perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID"))
660 return -EINVAL;
661
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300662 evsel->handler = perf_inject__sched_switch;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400663 } else if (!strcmp(name, "sched:sched_process_exit"))
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300664 evsel->handler = perf_inject__sched_process_exit;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400665 else if (!strncmp(name, "sched:sched_stat_", 17))
Arnaldo Carvalho de Melo744a9712013-11-06 10:17:38 -0300666 evsel->handler = perf_inject__sched_stat;
Andrew Vagin26a031e2012-08-07 16:56:04 +0400667 }
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300668 } else if (inject->itrace_synth_opts.set) {
669 session->itrace_synth_opts = &inject->itrace_synth_opts;
670 inject->itrace_synth_opts.inject = true;
671 inject->tool.comm = perf_event__repipe_comm;
Hari Bathinif3b36142017-03-08 02:11:43 +0530672 inject->tool.namespaces = perf_event__repipe_namespaces;
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300673 inject->tool.exit = perf_event__repipe_exit;
674 inject->tool.id_index = perf_event__repipe_id_index;
675 inject->tool.auxtrace_info = perf_event__process_auxtrace_info;
676 inject->tool.auxtrace = perf_event__process_auxtrace;
Adrian Hunter73117302015-09-25 16:15:54 +0300677 inject->tool.aux = perf_event__drop_aux;
678 inject->tool.itrace_start = perf_event__drop_aux,
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300679 inject->tool.ordered_events = true;
680 inject->tool.ordering_requires_timestamps = true;
681 /* Allow space in the header for new attributes */
682 output_data_offset = 4096;
Adrian Hunterf56fb982015-09-25 16:15:55 +0300683 if (inject->strip)
684 strip_init(inject);
Andrew Vagin26a031e2012-08-07 16:56:04 +0400685 }
686
Adrian Hunter99fa2982015-04-30 17:37:25 +0300687 if (!inject->itrace_synth_opts.set)
688 auxtrace_index__free(&session->auxtrace_index);
689
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100690 if (!data_out->is_pipe)
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300691 lseek(fd, output_data_offset, SEEK_SET);
Andrew Vagine558a5b2012-08-07 16:56:02 +0400692
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300693 ret = perf_session__process_events(session);
David Carrillo-Cisnerosbb8d5212017-04-10 13:14:26 -0700694 if (ret)
695 return ret;
Tom Zanussi454c4072010-05-01 01:41:20 -0500696
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100697 if (!data_out->is_pipe) {
Adrian Hunter640dad42016-03-07 16:44:38 -0300698 if (inject->build_ids)
Adrian Huntere38b43c2014-07-14 13:02:34 +0300699 perf_header__set_feat(&session->header,
700 HEADER_BUILD_ID);
Adrian Hunter640dad42016-03-07 16:44:38 -0300701 /*
702 * Keep all buildids when there is unprocessed AUX data because
703 * it is not known which ones the AUX trace hits.
704 */
705 if (perf_header__has_feat(&session->header, HEADER_BUILD_ID) &&
706 inject->have_auxtrace && !inject->itrace_synth_opts.set)
707 dsos__hit_all(session);
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300708 /*
709 * The AUX areas have been removed and replaced with
Adrian Hunter73117302015-09-25 16:15:54 +0300710 * synthesized hardware events, so clear the feature flag and
711 * remove the evsel.
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300712 */
Adrian Hunter051a01b2015-09-25 16:15:43 +0300713 if (inject->itrace_synth_opts.set) {
Adrian Hunter73117302015-09-25 16:15:54 +0300714 struct perf_evsel *evsel;
715
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300716 perf_header__clear_feat(&session->header,
717 HEADER_AUXTRACE);
Adrian Hunter051a01b2015-09-25 16:15:43 +0300718 if (inject->itrace_synth_opts.last_branch)
719 perf_header__set_feat(&session->header,
720 HEADER_BRANCH_STACK);
Adrian Hunter73117302015-09-25 16:15:54 +0300721 evsel = perf_evlist__id2evsel_strict(session->evlist,
722 inject->aux_id);
723 if (evsel) {
724 pr_debug("Deleting %s\n",
725 perf_evsel__name(evsel));
726 perf_evlist__remove(session->evlist, evsel);
727 perf_evsel__delete(evsel);
728 }
Adrian Hunterf56fb982015-09-25 16:15:55 +0300729 if (inject->strip)
730 strip_fini(inject);
Adrian Hunter051a01b2015-09-25 16:15:43 +0300731 }
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300732 session->header.data_offset = output_data_offset;
Andrew Vagine558a5b2012-08-07 16:56:02 +0400733 session->header.data_size = inject->bytes_written;
Namhyung Kim42aa2762015-01-29 17:06:48 +0900734 perf_session__write_header(session, session->evlist, fd, true);
Andrew Vagine558a5b2012-08-07 16:56:02 +0400735 }
736
Tom Zanussi454c4072010-05-01 01:41:20 -0500737 return ret;
738}
739
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -0300740int cmd_inject(int argc, const char **argv)
Tom Zanussi454c4072010-05-01 01:41:20 -0500741{
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300742 struct perf_inject inject = {
743 .tool = {
744 .sample = perf_event__repipe_sample,
745 .mmap = perf_event__repipe,
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200746 .mmap2 = perf_event__repipe,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300747 .comm = perf_event__repipe,
748 .fork = perf_event__repipe,
749 .exit = perf_event__repipe,
750 .lost = perf_event__repipe,
Adrian Hunterd8145b32015-11-13 11:48:32 +0200751 .lost_samples = perf_event__repipe,
Adrian Hunter4a96f7a2015-04-30 17:37:29 +0300752 .aux = perf_event__repipe,
Adrian Hunter0ad21f62015-04-30 17:37:30 +0300753 .itrace_start = perf_event__repipe,
Adrian Hunter02860392015-07-21 12:44:03 +0300754 .context_switch = perf_event__repipe,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300755 .read = perf_event__repipe_sample,
756 .throttle = perf_event__repipe,
757 .unthrottle = perf_event__repipe,
758 .attr = perf_event__repipe_attr,
Adrian Hunter47c3d102013-07-04 16:20:21 +0300759 .tracing_data = perf_event__repipe_op2_synth,
Adrian Huntercd17a9b2015-04-21 12:21:54 +0300760 .auxtrace_info = perf_event__repipe_op2_synth,
761 .auxtrace = perf_event__repipe_auxtrace,
762 .auxtrace_error = perf_event__repipe_op2_synth,
Adrian Hunter46bc29b2016-03-08 10:38:44 +0200763 .time_conv = perf_event__repipe_op2_synth,
Arnaldo Carvalho de Melod704ebd2015-03-03 12:37:54 -0300764 .finished_round = perf_event__repipe_oe_synth,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300765 .build_id = perf_event__repipe_op2_synth,
Adrian Hunter3c659ee2014-10-27 15:49:22 +0200766 .id_index = perf_event__repipe_op2_synth,
David Carrillo-Cisnerose9def1b2017-07-17 21:25:48 -0700767 .feature = perf_event__repipe_op2_synth,
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300768 },
Andrew Vagine558a5b2012-08-07 16:56:02 +0400769 .input_name = "-",
Andrew Vagin26a031e2012-08-07 16:56:04 +0400770 .samples = LIST_HEAD_INIT(inject.samples),
Jiri Olsa34069122013-10-29 19:04:57 +0100771 .output = {
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100772 .file = {
773 .path = "-",
774 },
775 .mode = PERF_DATA_MODE_WRITE,
Jiri Olsa34069122013-10-29 19:04:57 +0100776 },
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300777 };
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100778 struct perf_data data = {
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900779 .mode = PERF_DATA_MODE_READ,
780 };
781 int ret;
782
Stephane Eranian9b07e272015-11-30 10:02:21 +0100783 struct option options[] = {
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300784 OPT_BOOLEAN('b', "build-ids", &inject.build_ids,
785 "Inject build-ids into the output stream"),
Andrew Vagine558a5b2012-08-07 16:56:02 +0400786 OPT_STRING('i', "input", &inject.input_name, "file",
787 "input file name"),
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100788 OPT_STRING('o', "output", &inject.output.file.path, "file",
Andrew Vagine558a5b2012-08-07 16:56:02 +0400789 "output file name"),
Andrew Vagin26a031e2012-08-07 16:56:04 +0400790 OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat,
791 "Merge sched-stat and sched-switch for getting events "
792 "where and how long tasks slept"),
Jiri Olsae12b2022016-03-10 17:41:13 +0100793#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100794 OPT_BOOLEAN('j', "jit", &inject.jit_mode, "merge jitdump files into perf.data file"),
Jiri Olsae12b2022016-03-10 17:41:13 +0100795#endif
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300796 OPT_INCR('v', "verbose", &verbose,
797 "be more verbose (show build ids, etc)"),
Adrian Huntera7a2b8b2014-07-22 16:17:38 +0300798 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file",
799 "kallsyms pathname"),
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100800 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300801 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,
Andi Kleenc12e0392018-09-13 20:10:31 -0700802 NULL, "opts", "Instruction Tracing options\n"
803 ITRACE_HELP,
Adrian Hunter0f0aa5e2015-04-09 18:54:00 +0300804 itrace_parse_synth_opts),
Adrian Hunterf56fb982015-09-25 16:15:55 +0300805 OPT_BOOLEAN(0, "strip", &inject.strip,
806 "strip non-synthesized events (use with --itrace)"),
Arnaldo Carvalho de Melo5ded57a2012-09-30 19:54:10 -0300807 OPT_END()
808 };
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300809 const char * const inject_usage[] = {
810 "perf inject [<options>]",
811 NULL
812 };
Jiri Olsae12b2022016-03-10 17:41:13 +0100813#ifndef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100814 set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true);
815#endif
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300816 argc = parse_options(argc, argv, options, inject_usage, 0);
Tom Zanussi454c4072010-05-01 01:41:20 -0500817
818 /*
819 * Any (unrecognized) arguments left?
820 */
821 if (argc)
Arnaldo Carvalho de Melo002439e2012-10-01 15:20:58 -0300822 usage_with_options(inject_usage, options);
Tom Zanussi454c4072010-05-01 01:41:20 -0500823
Adrian Hunterf56fb982015-09-25 16:15:55 +0300824 if (inject.strip && !inject.itrace_synth_opts.set) {
825 pr_err("--strip option requires --itrace option\n");
826 return -1;
827 }
828
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100829 if (perf_data__open(&inject.output)) {
Jiri Olsa34069122013-10-29 19:04:57 +0100830 perror("failed to create output file");
831 return -1;
Andrew Vagine558a5b2012-08-07 16:56:02 +0400832 }
833
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300834 inject.tool.ordered_events = inject.sched_stat;
835
Jiri Olsaeae8ad82017-01-23 22:25:41 +0100836 data.file.path = inject.input_name;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +0100837 inject.session = perf_session__new(&data, true, &inject.tool);
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900838 if (inject.session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +0900839 return -1;
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900840
Arnaldo Carvalho de Melo921f3fa2016-01-22 18:41:00 -0300841 if (inject.build_ids) {
842 /*
843 * to make sure the mmap records are ordered correctly
844 * and so that the correct especially due to jitted code
845 * mmaps. We cannot generate the buildid hit list and
846 * inject the jit mmaps at the same time for now.
847 */
848 inject.tool.ordered_events = true;
849 inject.tool.ordering_requires_timestamps = true;
850 }
Jiri Olsae12b2022016-03-10 17:41:13 +0100851#ifdef HAVE_JITDUMP
Stephane Eranian9b07e272015-11-30 10:02:21 +0100852 if (inject.jit_mode) {
Stephane Eranian9b07e272015-11-30 10:02:21 +0100853 inject.tool.mmap2 = perf_event__jit_repipe_mmap2;
854 inject.tool.mmap = perf_event__jit_repipe_mmap;
855 inject.tool.ordered_events = true;
856 inject.tool.ordering_requires_timestamps = true;
857 /*
858 * JIT MMAP injection injects all MMAP events in one go, so it
859 * does not obey finished_round semantics.
860 */
861 inject.tool.finished_round = perf_event__drop_oe;
862 }
863#endif
Taeung Song9fedfb02015-06-30 17:15:20 +0900864 ret = symbol__init(&inject.session->header.env);
865 if (ret < 0)
866 goto out_delete;
Tom Zanussi454c4072010-05-01 01:41:20 -0500867
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900868 ret = __cmd_inject(&inject);
869
Taeung Song9fedfb02015-06-30 17:15:20 +0900870out_delete:
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900871 perf_session__delete(inject.session);
Namhyung Kim1cb8bdc2014-08-12 15:40:37 +0900872 return ret;
Tom Zanussi454c4072010-05-01 01:41:20 -0500873}