aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-inject.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-12 21:20:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-12 21:20:11 -0400
commitade0899b298ba2c43bfd6abd8cbc2545944cde0c (patch)
treea448dfb440b3b958b6306bb43620cd5d76f504bf /tools/perf/builtin-inject.c
parent871a0596cb2f51b57dc583d1a7c4be0186582fe7 (diff)
parent95cf59ea72331d0093010543b8951bb43f262cac (diff)
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "This tree includes some late late perf items that missed the first round: tools: - Bash auto completion improvements, now we can auto complete the tools long options, tracepoint event names, etc, from Namhyung Kim. - Look up thread using tid instead of pid in 'perf sched'. - Move global variables into a perf_kvm struct, from David Ahern. - Hists refactorings, preparatory for improved 'diff' command, from Jiri Olsa. - Hists refactorings, preparatory for event group viewieng work, from Namhyung Kim. - Remove double negation on optional feature macro definitions, from Namhyung Kim. - Remove several cases of needless global variables, on most builtins. - misc fixes kernel: - sysfs support for IBS on AMD CPUs, from Robert Richter. - Support for an upcoming Intel CPU, the Xeon-Phi / Knights Corner HPC blade PMU, from Vince Weaver. - misc fixes" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (46 commits) perf: Fix perf_cgroup_switch for sw-events perf: Clarify perf_cpu_context::active_pmu usage by renaming it to ::unique_pmu perf/AMD/IBS: Add sysfs support perf hists: Add more helpers for hist entry stat perf hists: Move he->stat.nr_events initialization to a template perf hists: Introduce struct he_stat perf diff: Removing the total_period argument from output code perf tool: Add hpp interface to enable/disable hpp column perf tools: Removing hists pair argument from output path perf hists: Separate overhead and baseline columns perf diff: Refactor diff displacement possition info perf hists: Add struct hists pointer to struct hist_entry perf tools: Complete tracepoint event names perf/x86: Add support for Intel Xeon-Phi Knights Corner PMU perf evlist: Remove some unused methods perf evlist: Introduce add_newtp method perf kvm: Move global variables into a perf_kvm struct perf tools: Convert to BACKTRACE_SUPPORT perf tools: Long option completion support for each subcommands perf tools: Complete long option names of perf command ...
Diffstat (limited to 'tools/perf/builtin-inject.c')
-rw-r--r--tools/perf/builtin-inject.c88
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
17static char const *input_name = "-"; 17struct perf_inject {
18static bool inject_build_ids; 18 struct perf_tool tool;
19 bool build_ids;
20};
19 21
20static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused, 22static 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
211struct 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
227extern volatile int session_done; 213extern volatile int session_done;
228 214
229static void sig_handler(int sig __maybe_unused) 215static 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
234static int __cmd_inject(void) 220static 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
259static const char * const report_usage[] = {
260 "perf inject [<options>]",
261 NULL
262};
263
264static 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
272int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) 245int 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}