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