diff options
Diffstat (limited to 'tools/perf/builtin-inject.c')
-rw-r--r-- | tools/perf/builtin-inject.c | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 1eaa6617c814..4688bea95c12 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -14,8 +14,10 @@ | |||
14 | 14 | ||
15 | #include "util/parse-options.h" | 15 | #include "util/parse-options.h" |
16 | 16 | ||
17 | static char const *input_name = "-"; | 17 | struct perf_inject { |
18 | static bool inject_build_ids; | 18 | struct perf_tool tool; |
19 | bool build_ids; | ||
20 | }; | ||
19 | 21 | ||
20 | static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused, | 22 | static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused, |
21 | union perf_event *event, | 23 | union perf_event *event, |
@@ -194,7 +196,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool, | |||
194 | * account this as unresolved. | 196 | * account this as unresolved. |
195 | */ | 197 | */ |
196 | } else { | 198 | } else { |
197 | #ifndef NO_LIBELF_SUPPORT | 199 | #ifdef LIBELF_SUPPORT |
198 | pr_warning("no symbols found in %s, maybe " | 200 | pr_warning("no symbols found in %s, maybe " |
199 | "install a debug package?\n", | 201 | "install a debug package?\n", |
200 | al.map->dso->long_name); | 202 | al.map->dso->long_name); |
@@ -208,22 +210,6 @@ repipe: | |||
208 | return 0; | 210 | return 0; |
209 | } | 211 | } |
210 | 212 | ||
211 | struct perf_tool perf_inject = { | ||
212 | .sample = perf_event__repipe_sample, | ||
213 | .mmap = perf_event__repipe, | ||
214 | .comm = perf_event__repipe, | ||
215 | .fork = perf_event__repipe, | ||
216 | .exit = perf_event__repipe, | ||
217 | .lost = perf_event__repipe, | ||
218 | .read = perf_event__repipe_sample, | ||
219 | .throttle = perf_event__repipe, | ||
220 | .unthrottle = perf_event__repipe, | ||
221 | .attr = perf_event__repipe_attr, | ||
222 | .event_type = perf_event__repipe_event_type_synth, | ||
223 | .tracing_data = perf_event__repipe_tracing_data_synth, | ||
224 | .build_id = perf_event__repipe_op2_synth, | ||
225 | }; | ||
226 | |||
227 | extern volatile int session_done; | 213 | extern volatile int session_done; |
228 | 214 | ||
229 | static void sig_handler(int sig __maybe_unused) | 215 | static void sig_handler(int sig __maybe_unused) |
@@ -231,56 +217,72 @@ static void sig_handler(int sig __maybe_unused) | |||
231 | session_done = 1; | 217 | session_done = 1; |
232 | } | 218 | } |
233 | 219 | ||
234 | static int __cmd_inject(void) | 220 | static int __cmd_inject(struct perf_inject *inject) |
235 | { | 221 | { |
236 | struct perf_session *session; | 222 | struct perf_session *session; |
237 | int ret = -EINVAL; | 223 | int ret = -EINVAL; |
238 | 224 | ||
239 | signal(SIGINT, sig_handler); | 225 | signal(SIGINT, sig_handler); |
240 | 226 | ||
241 | if (inject_build_ids) { | 227 | if (inject->build_ids) { |
242 | perf_inject.sample = perf_event__inject_buildid; | 228 | inject->tool.sample = perf_event__inject_buildid; |
243 | perf_inject.mmap = perf_event__repipe_mmap; | 229 | inject->tool.mmap = perf_event__repipe_mmap; |
244 | perf_inject.fork = perf_event__repipe_task; | 230 | inject->tool.fork = perf_event__repipe_task; |
245 | perf_inject.tracing_data = perf_event__repipe_tracing_data; | 231 | inject->tool.tracing_data = perf_event__repipe_tracing_data; |
246 | } | 232 | } |
247 | 233 | ||
248 | session = perf_session__new(input_name, O_RDONLY, false, true, &perf_inject); | 234 | session = perf_session__new("-", O_RDONLY, false, true, &inject->tool); |
249 | if (session == NULL) | 235 | if (session == NULL) |
250 | return -ENOMEM; | 236 | return -ENOMEM; |
251 | 237 | ||
252 | ret = perf_session__process_events(session, &perf_inject); | 238 | ret = perf_session__process_events(session, &inject->tool); |
253 | 239 | ||
254 | perf_session__delete(session); | 240 | perf_session__delete(session); |
255 | 241 | ||
256 | return ret; | 242 | return ret; |
257 | } | 243 | } |
258 | 244 | ||
259 | static const char * const report_usage[] = { | ||
260 | "perf inject [<options>]", | ||
261 | NULL | ||
262 | }; | ||
263 | |||
264 | static const struct option options[] = { | ||
265 | OPT_BOOLEAN('b', "build-ids", &inject_build_ids, | ||
266 | "Inject build-ids into the output stream"), | ||
267 | OPT_INCR('v', "verbose", &verbose, | ||
268 | "be more verbose (show build ids, etc)"), | ||
269 | OPT_END() | ||
270 | }; | ||
271 | |||
272 | int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) | 245 | int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) |
273 | { | 246 | { |
274 | argc = parse_options(argc, argv, options, report_usage, 0); | 247 | struct perf_inject inject = { |
248 | .tool = { | ||
249 | .sample = perf_event__repipe_sample, | ||
250 | .mmap = perf_event__repipe, | ||
251 | .comm = perf_event__repipe, | ||
252 | .fork = perf_event__repipe, | ||
253 | .exit = perf_event__repipe, | ||
254 | .lost = perf_event__repipe, | ||
255 | .read = perf_event__repipe_sample, | ||
256 | .throttle = perf_event__repipe, | ||
257 | .unthrottle = perf_event__repipe, | ||
258 | .attr = perf_event__repipe_attr, | ||
259 | .event_type = perf_event__repipe_event_type_synth, | ||
260 | .tracing_data = perf_event__repipe_tracing_data_synth, | ||
261 | .build_id = perf_event__repipe_op2_synth, | ||
262 | }, | ||
263 | }; | ||
264 | const struct option options[] = { | ||
265 | OPT_BOOLEAN('b', "build-ids", &inject.build_ids, | ||
266 | "Inject build-ids into the output stream"), | ||
267 | OPT_INCR('v', "verbose", &verbose, | ||
268 | "be more verbose (show build ids, etc)"), | ||
269 | OPT_END() | ||
270 | }; | ||
271 | const char * const inject_usage[] = { | ||
272 | "perf inject [<options>]", | ||
273 | NULL | ||
274 | }; | ||
275 | |||
276 | argc = parse_options(argc, argv, options, inject_usage, 0); | ||
275 | 277 | ||
276 | /* | 278 | /* |
277 | * Any (unrecognized) arguments left? | 279 | * Any (unrecognized) arguments left? |
278 | */ | 280 | */ |
279 | if (argc) | 281 | if (argc) |
280 | usage_with_options(report_usage, options); | 282 | usage_with_options(inject_usage, options); |
281 | 283 | ||
282 | if (symbol__init() < 0) | 284 | if (symbol__init() < 0) |
283 | return -1; | 285 | return -1; |
284 | 286 | ||
285 | return __cmd_inject(); | 287 | return __cmd_inject(&inject); |
286 | } | 288 | } |