aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-09-30 18:54:10 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-10-02 17:36:27 -0400
commit5ded57ac1bdb99b716c1da96eb8b5d387f5eb676 (patch)
treeaa40671b77f51a20f95fb77a5c36059b61c8b4ef /tools/perf
parent5852a445a00f346302411f50aa168e422c7e7ab2 (diff)
perf inject: Remove static variables
We want to reduce the impact that each of the builtins has on perf as a whole, so use the superclassing of perf_tool mechanizm to move its config knobs to the stack, so that only if we use that tool, its impact will be felt. In this case is more about consistency, as the impact of this tool is minimal. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-z2b3matvawihtenmez9hkcja@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-inject.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index e249f244b22a..3c9ab55f49e6 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -14,7 +14,10 @@
14 14
15#include "util/parse-options.h" 15#include "util/parse-options.h"
16 16
17static bool inject_build_ids; 17struct perf_inject {
18 struct perf_tool tool;
19 bool build_ids;
20};
18 21
19static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused, 22static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused,
20 union perf_event *event, 23 union perf_event *event,
@@ -207,22 +210,6 @@ repipe:
207 return 0; 210 return 0;
208} 211}
209 212
210struct perf_tool perf_inject = {
211 .sample = perf_event__repipe_sample,
212 .mmap = perf_event__repipe,
213 .comm = perf_event__repipe,
214 .fork = perf_event__repipe,
215 .exit = perf_event__repipe,
216 .lost = perf_event__repipe,
217 .read = perf_event__repipe_sample,
218 .throttle = perf_event__repipe,
219 .unthrottle = perf_event__repipe,
220 .attr = perf_event__repipe_attr,
221 .event_type = perf_event__repipe_event_type_synth,
222 .tracing_data = perf_event__repipe_tracing_data_synth,
223 .build_id = perf_event__repipe_op2_synth,
224};
225
226extern volatile int session_done; 213extern volatile int session_done;
227 214
228static void sig_handler(int sig __maybe_unused) 215static void sig_handler(int sig __maybe_unused)
@@ -230,25 +217,25 @@ static void sig_handler(int sig __maybe_unused)
230 session_done = 1; 217 session_done = 1;
231} 218}
232 219
233static int __cmd_inject(void) 220static int __cmd_inject(struct perf_inject *inject)
234{ 221{
235 struct perf_session *session; 222 struct perf_session *session;
236 int ret = -EINVAL; 223 int ret = -EINVAL;
237 224
238 signal(SIGINT, sig_handler); 225 signal(SIGINT, sig_handler);
239 226
240 if (inject_build_ids) { 227 if (inject->build_ids) {
241 perf_inject.sample = perf_event__inject_buildid; 228 inject->tool.sample = perf_event__inject_buildid;
242 perf_inject.mmap = perf_event__repipe_mmap; 229 inject->tool.mmap = perf_event__repipe_mmap;
243 perf_inject.fork = perf_event__repipe_task; 230 inject->tool.fork = perf_event__repipe_task;
244 perf_inject.tracing_data = perf_event__repipe_tracing_data; 231 inject->tool.tracing_data = perf_event__repipe_tracing_data;
245 } 232 }
246 233
247 session = perf_session__new("-", O_RDONLY, false, true, &perf_inject); 234 session = perf_session__new("-", O_RDONLY, false, true, &inject->tool);
248 if (session == NULL) 235 if (session == NULL)
249 return -ENOMEM; 236 return -ENOMEM;
250 237
251 ret = perf_session__process_events(session, &perf_inject); 238 ret = perf_session__process_events(session, &inject->tool);
252 239
253 perf_session__delete(session); 240 perf_session__delete(session);
254 241
@@ -260,16 +247,33 @@ static const char * const report_usage[] = {
260 NULL 247 NULL
261}; 248};
262 249
263static const struct option options[] = {
264 OPT_BOOLEAN('b', "build-ids", &inject_build_ids,
265 "Inject build-ids into the output stream"),
266 OPT_INCR('v', "verbose", &verbose,
267 "be more verbose (show build ids, etc)"),
268 OPT_END()
269};
270
271int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) 250int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
272{ 251{
252 struct perf_inject inject = {
253 .tool = {
254 .sample = perf_event__repipe_sample,
255 .mmap = perf_event__repipe,
256 .comm = perf_event__repipe,
257 .fork = perf_event__repipe,
258 .exit = perf_event__repipe,
259 .lost = perf_event__repipe,
260 .read = perf_event__repipe_sample,
261 .throttle = perf_event__repipe,
262 .unthrottle = perf_event__repipe,
263 .attr = perf_event__repipe_attr,
264 .event_type = perf_event__repipe_event_type_synth,
265 .tracing_data = perf_event__repipe_tracing_data_synth,
266 .build_id = perf_event__repipe_op2_synth,
267 },
268 };
269 const struct option options[] = {
270 OPT_BOOLEAN('b', "build-ids", &inject.build_ids,
271 "Inject build-ids into the output stream"),
272 OPT_INCR('v', "verbose", &verbose,
273 "be more verbose (show build ids, etc)"),
274 OPT_END()
275 };
276
273 argc = parse_options(argc, argv, options, report_usage, 0); 277 argc = parse_options(argc, argv, options, report_usage, 0);
274 278
275 /* 279 /*
@@ -281,5 +285,5 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
281 if (symbol__init() < 0) 285 if (symbol__init() < 0)
282 return -1; 286 return -1;
283 287
284 return __cmd_inject(); 288 return __cmd_inject(&inject);
285} 289}