Skip to content

Commit 5ded57a

Browse files
committed
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 <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5852a44 commit 5ded57a

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

tools/perf/builtin-inject.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
#include "util/parse-options.h"
1616

17-
static bool inject_build_ids;
17+
struct perf_inject {
18+
struct perf_tool tool;
19+
bool build_ids;
20+
};
1821

1922
static int perf_event__repipe_synth(struct perf_tool *tool __maybe_unused,
2023
union perf_event *event,
@@ -207,48 +210,32 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
207210
return 0;
208211
}
209212

210-
struct 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-
226213
extern volatile int session_done;
227214

228215
static void sig_handler(int sig __maybe_unused)
229216
{
230217
session_done = 1;
231218
}
232219

233-
static int __cmd_inject(void)
220+
static int __cmd_inject(struct perf_inject *inject)
234221
{
235222
struct perf_session *session;
236223
int ret = -EINVAL;
237224

238225
signal(SIGINT, sig_handler);
239226

240-
if (inject_build_ids) {
241-
perf_inject.sample = perf_event__inject_buildid;
242-
perf_inject.mmap = perf_event__repipe_mmap;
243-
perf_inject.fork = perf_event__repipe_task;
244-
perf_inject.tracing_data = perf_event__repipe_tracing_data;
227+
if (inject->build_ids) {
228+
inject->tool.sample = perf_event__inject_buildid;
229+
inject->tool.mmap = perf_event__repipe_mmap;
230+
inject->tool.fork = perf_event__repipe_task;
231+
inject->tool.tracing_data = perf_event__repipe_tracing_data;
245232
}
246233

247-
session = perf_session__new("-", O_RDONLY, false, true, &perf_inject);
234+
session = perf_session__new("-", O_RDONLY, false, true, &inject->tool);
248235
if (session == NULL)
249236
return -ENOMEM;
250237

251-
ret = perf_session__process_events(session, &perf_inject);
238+
ret = perf_session__process_events(session, &inject->tool);
252239

253240
perf_session__delete(session);
254241

@@ -260,16 +247,33 @@ static const char * const report_usage[] = {
260247
NULL
261248
};
262249

263-
static 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-
271250
int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
272251
{
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+
273277
argc = parse_options(argc, argv, options, report_usage, 0);
274278

275279
/*
@@ -281,5 +285,5 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
281285
if (symbol__init() < 0)
282286
return -1;
283287

284-
return __cmd_inject();
288+
return __cmd_inject(&inject);
285289
}

0 commit comments

Comments
 (0)