Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 1 | /* |
| 2 | * builtin-inject.c |
| 3 | * |
| 4 | * Builtin inject command: Examine the live mode (stdin) event stream |
| 5 | * and repipe it to stdout while optionally injecting additional |
| 6 | * events into it. |
| 7 | */ |
| 8 | #include "builtin.h" |
| 9 | |
| 10 | #include "perf.h" |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 11 | #include "util/color.h" |
| 12 | #include "util/evlist.h" |
| 13 | #include "util/evsel.h" |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 14 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 15 | #include "util/tool.h" |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 16 | #include "util/debug.h" |
Andrew Vagin | 54a3cf5 | 2012-08-07 16:56:05 +0400 | [diff] [blame] | 17 | #include "util/build-id.h" |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 18 | #include "util/data.h" |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 19 | #include "util/auxtrace.h" |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 20 | |
| 21 | #include "util/parse-options.h" |
| 22 | |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 23 | #include <linux/list.h> |
| 24 | |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 25 | struct perf_inject { |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 26 | struct perf_tool tool; |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 27 | struct perf_session *session; |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 28 | bool build_ids; |
| 29 | bool sched_stat; |
Adrian Hunter | cd10b28 | 2015-04-30 17:37:26 +0300 | [diff] [blame] | 30 | bool have_auxtrace; |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 31 | const char *input_name; |
| 32 | struct perf_data_file output; |
| 33 | u64 bytes_written; |
Adrian Hunter | 7311730 | 2015-09-25 16:15:54 +0300 | [diff] [blame^] | 34 | u64 aux_id; |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 35 | struct list_head samples; |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 36 | struct itrace_synth_opts itrace_synth_opts; |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct event_entry { |
| 40 | struct list_head node; |
| 41 | u32 tid; |
| 42 | union perf_event event[0]; |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 43 | }; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 44 | |
Adrian Hunter | cd17a9b | 2015-04-21 12:21:54 +0300 | [diff] [blame] | 45 | static int output_bytes(struct perf_inject *inject, void *buf, size_t sz) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 46 | { |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 47 | ssize_t size; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 48 | |
Adrian Hunter | cd17a9b | 2015-04-21 12:21:54 +0300 | [diff] [blame] | 49 | size = perf_data_file__write(&inject->output, buf, sz); |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 50 | if (size < 0) |
| 51 | return -errno; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 52 | |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 53 | inject->bytes_written += size; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
Adrian Hunter | cd17a9b | 2015-04-21 12:21:54 +0300 | [diff] [blame] | 57 | static int perf_event__repipe_synth(struct perf_tool *tool, |
| 58 | union perf_event *event) |
| 59 | { |
| 60 | struct perf_inject *inject = container_of(tool, struct perf_inject, |
| 61 | tool); |
| 62 | |
| 63 | return output_bytes(inject, event, event->header.size); |
| 64 | } |
| 65 | |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 66 | static int perf_event__repipe_oe_synth(struct perf_tool *tool, |
| 67 | union perf_event *event, |
| 68 | struct ordered_events *oe __maybe_unused) |
| 69 | { |
| 70 | return perf_event__repipe_synth(tool, event); |
| 71 | } |
| 72 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 73 | static int perf_event__repipe_op2_synth(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 74 | union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 75 | struct perf_session *session |
| 76 | __maybe_unused) |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 77 | { |
Adrian Hunter | 63c2c9f | 2013-07-04 16:20:20 +0300 | [diff] [blame] | 78 | return perf_event__repipe_synth(tool, event); |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 79 | } |
| 80 | |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 81 | static int perf_event__repipe_attr(struct perf_tool *tool, |
| 82 | union perf_event *event, |
| 83 | struct perf_evlist **pevlist) |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 84 | { |
Adrian Hunter | 89c97d9 | 2013-10-22 10:34:09 +0300 | [diff] [blame] | 85 | struct perf_inject *inject = container_of(tool, struct perf_inject, |
| 86 | tool); |
Stephane Eranian | 1a1ed1b | 2012-05-15 13:28:11 +0200 | [diff] [blame] | 87 | int ret; |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 88 | |
| 89 | ret = perf_event__process_attr(tool, event, pevlist); |
Stephane Eranian | 1a1ed1b | 2012-05-15 13:28:11 +0200 | [diff] [blame] | 90 | if (ret) |
| 91 | return ret; |
| 92 | |
Jiri Olsa | a261e4a | 2014-06-05 18:51:44 +0200 | [diff] [blame] | 93 | if (!inject->output.is_pipe) |
Adrian Hunter | 89c97d9 | 2013-10-22 10:34:09 +0300 | [diff] [blame] | 94 | return 0; |
| 95 | |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 96 | return perf_event__repipe_synth(tool, event); |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 97 | } |
| 98 | |
Adrian Hunter | e31f0d0 | 2015-04-30 17:37:27 +0300 | [diff] [blame] | 99 | #ifdef HAVE_AUXTRACE_SUPPORT |
| 100 | |
| 101 | static int copy_bytes(struct perf_inject *inject, int fd, off_t size) |
| 102 | { |
| 103 | char buf[4096]; |
| 104 | ssize_t ssz; |
| 105 | int ret; |
| 106 | |
| 107 | while (size > 0) { |
| 108 | ssz = read(fd, buf, min(size, (off_t)sizeof(buf))); |
| 109 | if (ssz < 0) |
| 110 | return -errno; |
| 111 | ret = output_bytes(inject, buf, ssz); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | size -= ssz; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Adrian Hunter | cd17a9b | 2015-04-21 12:21:54 +0300 | [diff] [blame] | 120 | static s64 perf_event__repipe_auxtrace(struct perf_tool *tool, |
| 121 | union perf_event *event, |
| 122 | struct perf_session *session |
| 123 | __maybe_unused) |
| 124 | { |
| 125 | struct perf_inject *inject = container_of(tool, struct perf_inject, |
| 126 | tool); |
| 127 | int ret; |
| 128 | |
Adrian Hunter | cd10b28 | 2015-04-30 17:37:26 +0300 | [diff] [blame] | 129 | inject->have_auxtrace = true; |
| 130 | |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 131 | if (!inject->output.is_pipe) { |
| 132 | off_t offset; |
| 133 | |
| 134 | offset = lseek(inject->output.fd, 0, SEEK_CUR); |
| 135 | if (offset == -1) |
| 136 | return -errno; |
| 137 | ret = auxtrace_index__auxtrace_event(&session->auxtrace_index, |
| 138 | event, offset); |
| 139 | if (ret < 0) |
| 140 | return ret; |
| 141 | } |
| 142 | |
Adrian Hunter | cd17a9b | 2015-04-21 12:21:54 +0300 | [diff] [blame] | 143 | if (perf_data_file__is_pipe(session->file) || !session->one_mmap) { |
| 144 | ret = output_bytes(inject, event, event->header.size); |
| 145 | if (ret < 0) |
| 146 | return ret; |
| 147 | ret = copy_bytes(inject, perf_data_file__fd(session->file), |
| 148 | event->auxtrace.size); |
| 149 | } else { |
| 150 | ret = output_bytes(inject, event, |
| 151 | event->header.size + event->auxtrace.size); |
| 152 | } |
| 153 | if (ret < 0) |
| 154 | return ret; |
| 155 | |
| 156 | return event->auxtrace.size; |
| 157 | } |
| 158 | |
Adrian Hunter | e31f0d0 | 2015-04-30 17:37:27 +0300 | [diff] [blame] | 159 | #else |
| 160 | |
| 161 | static s64 |
| 162 | perf_event__repipe_auxtrace(struct perf_tool *tool __maybe_unused, |
| 163 | union perf_event *event __maybe_unused, |
| 164 | struct perf_session *session __maybe_unused) |
| 165 | { |
| 166 | pr_err("AUX area tracing not supported\n"); |
| 167 | return -EINVAL; |
| 168 | } |
| 169 | |
| 170 | #endif |
| 171 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 172 | static int perf_event__repipe(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 173 | union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 174 | struct perf_sample *sample __maybe_unused, |
Adrian Hunter | 63c2c9f | 2013-07-04 16:20:20 +0300 | [diff] [blame] | 175 | struct machine *machine __maybe_unused) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 176 | { |
Adrian Hunter | 63c2c9f | 2013-07-04 16:20:20 +0300 | [diff] [blame] | 177 | return perf_event__repipe_synth(tool, event); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 178 | } |
| 179 | |
Adrian Hunter | 7311730 | 2015-09-25 16:15:54 +0300 | [diff] [blame^] | 180 | static int perf_event__drop_aux(struct perf_tool *tool, |
| 181 | union perf_event *event __maybe_unused, |
| 182 | struct perf_sample *sample, |
| 183 | struct machine *machine __maybe_unused) |
| 184 | { |
| 185 | struct perf_inject *inject = container_of(tool, struct perf_inject, tool); |
| 186 | |
| 187 | if (!inject->aux_id) |
| 188 | inject->aux_id = sample->id; |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 193 | typedef int (*inject_handler)(struct perf_tool *tool, |
| 194 | union perf_event *event, |
| 195 | struct perf_sample *sample, |
| 196 | struct perf_evsel *evsel, |
| 197 | struct machine *machine); |
| 198 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 199 | static int perf_event__repipe_sample(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 200 | union perf_event *event, |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 201 | struct perf_sample *sample, |
| 202 | struct perf_evsel *evsel, |
| 203 | struct machine *machine) |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 204 | { |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 205 | if (evsel->handler) { |
| 206 | inject_handler f = evsel->handler; |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 207 | return f(tool, event, sample, evsel, machine); |
| 208 | } |
| 209 | |
Andrew Vagin | 54a3cf5 | 2012-08-07 16:56:05 +0400 | [diff] [blame] | 210 | build_id__mark_dso_hit(tool, event, sample, evsel, machine); |
| 211 | |
Adrian Hunter | 63c2c9f | 2013-07-04 16:20:20 +0300 | [diff] [blame] | 212 | return perf_event__repipe_synth(tool, event); |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 213 | } |
| 214 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 215 | static int perf_event__repipe_mmap(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 216 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 217 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 218 | struct machine *machine) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 219 | { |
| 220 | int err; |
| 221 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 222 | err = perf_event__process_mmap(tool, event, sample, machine); |
| 223 | perf_event__repipe(tool, event, sample, machine); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 224 | |
| 225 | return err; |
| 226 | } |
| 227 | |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 228 | static int perf_event__repipe_mmap2(struct perf_tool *tool, |
| 229 | union perf_event *event, |
| 230 | struct perf_sample *sample, |
| 231 | struct machine *machine) |
| 232 | { |
| 233 | int err; |
| 234 | |
| 235 | err = perf_event__process_mmap2(tool, event, sample, machine); |
| 236 | perf_event__repipe(tool, event, sample, machine); |
| 237 | |
| 238 | return err; |
| 239 | } |
| 240 | |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 241 | static int perf_event__repipe_fork(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 242 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 243 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 244 | struct machine *machine) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 245 | { |
| 246 | int err; |
| 247 | |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 248 | err = perf_event__process_fork(tool, event, sample, machine); |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 249 | perf_event__repipe(tool, event, sample, machine); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 250 | |
| 251 | return err; |
| 252 | } |
| 253 | |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 254 | static int perf_event__repipe_comm(struct perf_tool *tool, |
| 255 | union perf_event *event, |
| 256 | struct perf_sample *sample, |
| 257 | struct machine *machine) |
| 258 | { |
| 259 | int err; |
| 260 | |
| 261 | err = perf_event__process_comm(tool, event, sample, machine); |
| 262 | perf_event__repipe(tool, event, sample, machine); |
| 263 | |
| 264 | return err; |
| 265 | } |
| 266 | |
| 267 | static int perf_event__repipe_exit(struct perf_tool *tool, |
| 268 | union perf_event *event, |
| 269 | struct perf_sample *sample, |
| 270 | struct machine *machine) |
| 271 | { |
| 272 | int err; |
| 273 | |
| 274 | err = perf_event__process_exit(tool, event, sample, machine); |
| 275 | perf_event__repipe(tool, event, sample, machine); |
| 276 | |
| 277 | return err; |
| 278 | } |
| 279 | |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 280 | static int perf_event__repipe_tracing_data(struct perf_tool *tool, |
| 281 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 282 | struct perf_session *session) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 283 | { |
| 284 | int err; |
| 285 | |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 286 | perf_event__repipe_synth(tool, event); |
| 287 | err = perf_event__process_tracing_data(tool, event, session); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 288 | |
| 289 | return err; |
| 290 | } |
| 291 | |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 292 | static int perf_event__repipe_id_index(struct perf_tool *tool, |
| 293 | union perf_event *event, |
| 294 | struct perf_session *session) |
| 295 | { |
| 296 | int err; |
| 297 | |
| 298 | perf_event__repipe_synth(tool, event); |
| 299 | err = perf_event__process_id_index(tool, event, session); |
| 300 | |
| 301 | return err; |
| 302 | } |
| 303 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 304 | static int dso__read_build_id(struct dso *dso) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 305 | { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 306 | if (dso->has_build_id) |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 307 | return 0; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 308 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 309 | if (filename__read_build_id(dso->long_name, dso->build_id, |
| 310 | sizeof(dso->build_id)) > 0) { |
| 311 | dso->has_build_id = true; |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 312 | return 0; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 313 | } |
| 314 | |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 315 | return -1; |
| 316 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 317 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 318 | static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 319 | struct machine *machine) |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 320 | { |
| 321 | u16 misc = PERF_RECORD_MISC_USER; |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 322 | int err; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 323 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 324 | if (dso__read_build_id(dso) < 0) { |
| 325 | pr_debug("no build_id found for %s\n", dso->long_name); |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 326 | return -1; |
| 327 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 328 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 329 | if (dso->kernel) |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 330 | misc = PERF_RECORD_MISC_KERNEL; |
| 331 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 332 | err = perf_event__synthesize_build_id(tool, dso, misc, perf_event__repipe, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 333 | machine); |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 334 | if (err) { |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 335 | pr_err("Can't synthesize build_id event for %s\n", dso->long_name); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 336 | return -1; |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 342 | static int perf_event__inject_buildid(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 343 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 344 | struct perf_sample *sample, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 345 | struct perf_evsel *evsel __maybe_unused, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 346 | struct machine *machine) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 347 | { |
| 348 | struct addr_location al; |
| 349 | struct thread *thread; |
| 350 | u8 cpumode; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 351 | |
| 352 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
| 353 | |
Namhyung Kim | 13ce34d | 2014-05-12 09:56:42 +0900 | [diff] [blame] | 354 | thread = machine__findnew_thread(machine, sample->pid, sample->tid); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 355 | if (thread == NULL) { |
| 356 | pr_err("problem processing %d event, skipping it.\n", |
| 357 | event->header.type); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 358 | goto repipe; |
| 359 | } |
| 360 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 361 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 362 | |
| 363 | if (al.map != NULL) { |
| 364 | if (!al.map->dso->hit) { |
| 365 | al.map->dso->hit = 1; |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 366 | if (map__load(al.map, NULL) >= 0) { |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 367 | dso__inject_build_id(al.map->dso, tool, machine); |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 368 | /* |
| 369 | * If this fails, too bad, let the other side |
| 370 | * account this as unresolved. |
| 371 | */ |
Namhyung Kim | 393be2e | 2012-08-06 13:41:21 +0900 | [diff] [blame] | 372 | } else { |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 373 | #ifdef HAVE_LIBELF_SUPPORT |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 374 | pr_warning("no symbols found in %s, maybe " |
| 375 | "install a debug package?\n", |
| 376 | al.map->dso->long_name); |
Namhyung Kim | 393be2e | 2012-08-06 13:41:21 +0900 | [diff] [blame] | 377 | #endif |
| 378 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 382 | thread__put(thread); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 383 | repipe: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 384 | perf_event__repipe(tool, event, sample, machine); |
Arnaldo Carvalho de Melo | 090f720 | 2010-05-02 19:46:36 -0300 | [diff] [blame] | 385 | return 0; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 386 | } |
| 387 | |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 388 | static int perf_inject__sched_process_exit(struct perf_tool *tool, |
| 389 | union perf_event *event __maybe_unused, |
| 390 | struct perf_sample *sample, |
| 391 | struct perf_evsel *evsel __maybe_unused, |
| 392 | struct machine *machine __maybe_unused) |
| 393 | { |
| 394 | struct perf_inject *inject = container_of(tool, struct perf_inject, tool); |
| 395 | struct event_entry *ent; |
| 396 | |
| 397 | list_for_each_entry(ent, &inject->samples, node) { |
| 398 | if (sample->tid == ent->tid) { |
| 399 | list_del_init(&ent->node); |
| 400 | free(ent); |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int perf_inject__sched_switch(struct perf_tool *tool, |
| 409 | union perf_event *event, |
| 410 | struct perf_sample *sample, |
| 411 | struct perf_evsel *evsel, |
| 412 | struct machine *machine) |
| 413 | { |
| 414 | struct perf_inject *inject = container_of(tool, struct perf_inject, tool); |
| 415 | struct event_entry *ent; |
| 416 | |
| 417 | perf_inject__sched_process_exit(tool, event, sample, evsel, machine); |
| 418 | |
| 419 | ent = malloc(event->header.size + sizeof(struct event_entry)); |
| 420 | if (ent == NULL) { |
| 421 | color_fprintf(stderr, PERF_COLOR_RED, |
| 422 | "Not enough memory to process sched switch event!"); |
| 423 | return -1; |
| 424 | } |
| 425 | |
| 426 | ent->tid = sample->tid; |
| 427 | memcpy(&ent->event, event, event->header.size); |
| 428 | list_add(&ent->node, &inject->samples); |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int perf_inject__sched_stat(struct perf_tool *tool, |
| 433 | union perf_event *event __maybe_unused, |
| 434 | struct perf_sample *sample, |
| 435 | struct perf_evsel *evsel, |
| 436 | struct machine *machine) |
| 437 | { |
| 438 | struct event_entry *ent; |
| 439 | union perf_event *event_sw; |
| 440 | struct perf_sample sample_sw; |
| 441 | struct perf_inject *inject = container_of(tool, struct perf_inject, tool); |
| 442 | u32 pid = perf_evsel__intval(evsel, sample, "pid"); |
| 443 | |
| 444 | list_for_each_entry(ent, &inject->samples, node) { |
| 445 | if (pid == ent->tid) |
| 446 | goto found; |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | found: |
| 451 | event_sw = &ent->event[0]; |
| 452 | perf_evsel__parse_sample(evsel, event_sw, &sample_sw); |
| 453 | |
| 454 | sample_sw.period = sample->period; |
| 455 | sample_sw.time = sample->time; |
| 456 | perf_event__synthesize_sample(event_sw, evsel->attr.sample_type, |
Adrian Hunter | d03f217 | 2013-08-27 11:23:11 +0300 | [diff] [blame] | 457 | evsel->attr.read_format, &sample_sw, |
| 458 | false); |
Andrew Vagin | 54a3cf5 | 2012-08-07 16:56:05 +0400 | [diff] [blame] | 459 | build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine); |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 460 | return perf_event__repipe(tool, event_sw, &sample_sw, machine); |
| 461 | } |
| 462 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 463 | static void sig_handler(int sig __maybe_unused) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 464 | { |
| 465 | session_done = 1; |
| 466 | } |
| 467 | |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 468 | static int perf_evsel__check_stype(struct perf_evsel *evsel, |
| 469 | u64 sample_type, const char *sample_msg) |
| 470 | { |
| 471 | struct perf_event_attr *attr = &evsel->attr; |
| 472 | const char *name = perf_evsel__name(evsel); |
| 473 | |
| 474 | if (!(attr->sample_type & sample_type)) { |
| 475 | pr_err("Samples for %s event do not have %s attribute set.", |
| 476 | name, sample_msg); |
| 477 | return -EINVAL; |
| 478 | } |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 483 | static int __cmd_inject(struct perf_inject *inject) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 484 | { |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 485 | int ret = -EINVAL; |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 486 | struct perf_session *session = inject->session; |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 487 | struct perf_data_file *file_out = &inject->output; |
Namhyung Kim | 42aa276 | 2015-01-29 17:06:48 +0900 | [diff] [blame] | 488 | int fd = perf_data_file__fd(file_out); |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 489 | u64 output_data_offset; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 490 | |
| 491 | signal(SIGINT, sig_handler); |
| 492 | |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 493 | if (inject->build_ids || inject->sched_stat || |
| 494 | inject->itrace_synth_opts.set) { |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 495 | inject->tool.mmap = perf_event__repipe_mmap; |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 496 | inject->tool.mmap2 = perf_event__repipe_mmap2; |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 497 | inject->tool.fork = perf_event__repipe_fork; |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 498 | inject->tool.tracing_data = perf_event__repipe_tracing_data; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 499 | } |
| 500 | |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 501 | output_data_offset = session->header.data_offset; |
| 502 | |
Andrew Vagin | 54a3cf5 | 2012-08-07 16:56:05 +0400 | [diff] [blame] | 503 | if (inject->build_ids) { |
| 504 | inject->tool.sample = perf_event__inject_buildid; |
| 505 | } else if (inject->sched_stat) { |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 506 | struct perf_evsel *evsel; |
| 507 | |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 508 | evlist__for_each(session->evlist, evsel) { |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 509 | const char *name = perf_evsel__name(evsel); |
| 510 | |
| 511 | if (!strcmp(name, "sched:sched_switch")) { |
| 512 | if (perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID")) |
| 513 | return -EINVAL; |
| 514 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 515 | evsel->handler = perf_inject__sched_switch; |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 516 | } else if (!strcmp(name, "sched:sched_process_exit")) |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 517 | evsel->handler = perf_inject__sched_process_exit; |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 518 | else if (!strncmp(name, "sched:sched_stat_", 17)) |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 519 | evsel->handler = perf_inject__sched_stat; |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 520 | } |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 521 | } else if (inject->itrace_synth_opts.set) { |
| 522 | session->itrace_synth_opts = &inject->itrace_synth_opts; |
| 523 | inject->itrace_synth_opts.inject = true; |
| 524 | inject->tool.comm = perf_event__repipe_comm; |
| 525 | inject->tool.exit = perf_event__repipe_exit; |
| 526 | inject->tool.id_index = perf_event__repipe_id_index; |
| 527 | inject->tool.auxtrace_info = perf_event__process_auxtrace_info; |
| 528 | inject->tool.auxtrace = perf_event__process_auxtrace; |
Adrian Hunter | 7311730 | 2015-09-25 16:15:54 +0300 | [diff] [blame^] | 529 | inject->tool.aux = perf_event__drop_aux; |
| 530 | inject->tool.itrace_start = perf_event__drop_aux, |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 531 | inject->tool.ordered_events = true; |
| 532 | inject->tool.ordering_requires_timestamps = true; |
| 533 | /* Allow space in the header for new attributes */ |
| 534 | output_data_offset = 4096; |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 535 | } |
| 536 | |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 537 | if (!inject->itrace_synth_opts.set) |
| 538 | auxtrace_index__free(&session->auxtrace_index); |
| 539 | |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 540 | if (!file_out->is_pipe) |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 541 | lseek(fd, output_data_offset, SEEK_SET); |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 542 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 543 | ret = perf_session__process_events(session); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 544 | |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 545 | if (!file_out->is_pipe) { |
Adrian Hunter | cd10b28 | 2015-04-30 17:37:26 +0300 | [diff] [blame] | 546 | if (inject->build_ids) { |
Adrian Hunter | e38b43c | 2014-07-14 13:02:34 +0300 | [diff] [blame] | 547 | perf_header__set_feat(&session->header, |
| 548 | HEADER_BUILD_ID); |
Adrian Hunter | cd10b28 | 2015-04-30 17:37:26 +0300 | [diff] [blame] | 549 | if (inject->have_auxtrace) |
| 550 | dsos__hit_all(session); |
| 551 | } |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 552 | /* |
| 553 | * The AUX areas have been removed and replaced with |
Adrian Hunter | 7311730 | 2015-09-25 16:15:54 +0300 | [diff] [blame^] | 554 | * synthesized hardware events, so clear the feature flag and |
| 555 | * remove the evsel. |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 556 | */ |
Adrian Hunter | 051a01b | 2015-09-25 16:15:43 +0300 | [diff] [blame] | 557 | if (inject->itrace_synth_opts.set) { |
Adrian Hunter | 7311730 | 2015-09-25 16:15:54 +0300 | [diff] [blame^] | 558 | struct perf_evsel *evsel; |
| 559 | |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 560 | perf_header__clear_feat(&session->header, |
| 561 | HEADER_AUXTRACE); |
Adrian Hunter | 051a01b | 2015-09-25 16:15:43 +0300 | [diff] [blame] | 562 | if (inject->itrace_synth_opts.last_branch) |
| 563 | perf_header__set_feat(&session->header, |
| 564 | HEADER_BRANCH_STACK); |
Adrian Hunter | 7311730 | 2015-09-25 16:15:54 +0300 | [diff] [blame^] | 565 | evsel = perf_evlist__id2evsel_strict(session->evlist, |
| 566 | inject->aux_id); |
| 567 | if (evsel) { |
| 568 | pr_debug("Deleting %s\n", |
| 569 | perf_evsel__name(evsel)); |
| 570 | perf_evlist__remove(session->evlist, evsel); |
| 571 | perf_evsel__delete(evsel); |
| 572 | } |
Adrian Hunter | 051a01b | 2015-09-25 16:15:43 +0300 | [diff] [blame] | 573 | } |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 574 | session->header.data_offset = output_data_offset; |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 575 | session->header.data_size = inject->bytes_written; |
Namhyung Kim | 42aa276 | 2015-01-29 17:06:48 +0900 | [diff] [blame] | 576 | perf_session__write_header(session, session->evlist, fd, true); |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 577 | } |
| 578 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 579 | return ret; |
| 580 | } |
| 581 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 582 | int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 583 | { |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 584 | struct perf_inject inject = { |
| 585 | .tool = { |
| 586 | .sample = perf_event__repipe_sample, |
| 587 | .mmap = perf_event__repipe, |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 588 | .mmap2 = perf_event__repipe, |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 589 | .comm = perf_event__repipe, |
| 590 | .fork = perf_event__repipe, |
| 591 | .exit = perf_event__repipe, |
| 592 | .lost = perf_event__repipe, |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 593 | .aux = perf_event__repipe, |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 594 | .itrace_start = perf_event__repipe, |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 595 | .context_switch = perf_event__repipe, |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 596 | .read = perf_event__repipe_sample, |
| 597 | .throttle = perf_event__repipe, |
| 598 | .unthrottle = perf_event__repipe, |
| 599 | .attr = perf_event__repipe_attr, |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 600 | .tracing_data = perf_event__repipe_op2_synth, |
Adrian Hunter | cd17a9b | 2015-04-21 12:21:54 +0300 | [diff] [blame] | 601 | .auxtrace_info = perf_event__repipe_op2_synth, |
| 602 | .auxtrace = perf_event__repipe_auxtrace, |
| 603 | .auxtrace_error = perf_event__repipe_op2_synth, |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 604 | .finished_round = perf_event__repipe_oe_synth, |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 605 | .build_id = perf_event__repipe_op2_synth, |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 606 | .id_index = perf_event__repipe_op2_synth, |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 607 | }, |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 608 | .input_name = "-", |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 609 | .samples = LIST_HEAD_INIT(inject.samples), |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 610 | .output = { |
| 611 | .path = "-", |
| 612 | .mode = PERF_DATA_MODE_WRITE, |
| 613 | }, |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 614 | }; |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 615 | struct perf_data_file file = { |
| 616 | .mode = PERF_DATA_MODE_READ, |
| 617 | }; |
| 618 | int ret; |
| 619 | |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 620 | const struct option options[] = { |
| 621 | OPT_BOOLEAN('b', "build-ids", &inject.build_ids, |
| 622 | "Inject build-ids into the output stream"), |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 623 | OPT_STRING('i', "input", &inject.input_name, "file", |
| 624 | "input file name"), |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 625 | OPT_STRING('o', "output", &inject.output.path, "file", |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 626 | "output file name"), |
Andrew Vagin | 26a031e | 2012-08-07 16:56:04 +0400 | [diff] [blame] | 627 | OPT_BOOLEAN('s', "sched-stat", &inject.sched_stat, |
| 628 | "Merge sched-stat and sched-switch for getting events " |
| 629 | "where and how long tasks slept"), |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 630 | OPT_INCR('v', "verbose", &verbose, |
| 631 | "be more verbose (show build ids, etc)"), |
Adrian Hunter | a7a2b8b | 2014-07-22 16:17:38 +0300 | [diff] [blame] | 632 | OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file", |
| 633 | "kallsyms pathname"), |
Yunlong Song | ccaa474 | 2015-04-02 21:47:11 +0800 | [diff] [blame] | 634 | OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), |
Adrian Hunter | 0f0aa5e | 2015-04-09 18:54:00 +0300 | [diff] [blame] | 635 | OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts, |
| 636 | NULL, "opts", "Instruction Tracing options", |
| 637 | itrace_parse_synth_opts), |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 638 | OPT_END() |
| 639 | }; |
Arnaldo Carvalho de Melo | 002439e | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 640 | const char * const inject_usage[] = { |
| 641 | "perf inject [<options>]", |
| 642 | NULL |
| 643 | }; |
Arnaldo Carvalho de Melo | 5ded57a | 2012-09-30 19:54:10 -0300 | [diff] [blame] | 644 | |
Arnaldo Carvalho de Melo | 002439e | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 645 | argc = parse_options(argc, argv, options, inject_usage, 0); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 646 | |
| 647 | /* |
| 648 | * Any (unrecognized) arguments left? |
| 649 | */ |
| 650 | if (argc) |
Arnaldo Carvalho de Melo | 002439e | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 651 | usage_with_options(inject_usage, options); |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 652 | |
Jiri Olsa | 3406912 | 2013-10-29 19:04:57 +0100 | [diff] [blame] | 653 | if (perf_data_file__open(&inject.output)) { |
| 654 | perror("failed to create output file"); |
| 655 | return -1; |
Andrew Vagin | e558a5b | 2012-08-07 16:56:02 +0400 | [diff] [blame] | 656 | } |
| 657 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 658 | inject.tool.ordered_events = inject.sched_stat; |
| 659 | |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 660 | file.path = inject.input_name; |
| 661 | inject.session = perf_session__new(&file, true, &inject.tool); |
| 662 | if (inject.session == NULL) |
Taeung Song | 52e0283 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 663 | return -1; |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 664 | |
Taeung Song | 9fedfb0 | 2015-06-30 17:15:20 +0900 | [diff] [blame] | 665 | ret = symbol__init(&inject.session->header.env); |
| 666 | if (ret < 0) |
| 667 | goto out_delete; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 668 | |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 669 | ret = __cmd_inject(&inject); |
| 670 | |
Taeung Song | 9fedfb0 | 2015-06-30 17:15:20 +0900 | [diff] [blame] | 671 | out_delete: |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 672 | perf_session__delete(inject.session); |
Namhyung Kim | 1cb8bdc | 2014-08-12 15:40:37 +0900 | [diff] [blame] | 673 | return ret; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 674 | } |