Skip to content

Commit d20deb6

Browse files
committed
perf tools: Pass tool context in the the perf_event_ops functions
So that we don't need to have that many globals. Next steps will remove the 'session' pointer, that in most cases is not needed. Then we can rename perf_event_ops to 'perf_tool' that better describes this class hierarchy. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> 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-wp4djox7x6w1i2bab1pt4xxp@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7009cc3 commit d20deb6

20 files changed

Lines changed: 520 additions & 373 deletions

‎tools/perf/builtin-annotate.c‎

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030

3131
#include <linux/bitmap.h>
3232

33-
static struct perf_annotate {
33+
struct perf_annotate {
34+
struct perf_event_ops ops;
3435
char const *input_name;
3536
bool force, use_tui, use_stdio;
3637
bool full_paths;
3738
bool print_line;
3839
const char *sym_hist_filter;
3940
const char *cpu_list;
4041
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
41-
} annotate = {
42-
.input_name = "perf.data",
43-
}, *ann = &annotate;
42+
};
4443

4544
static int perf_evsel__add_sample(struct perf_evsel *evsel,
4645
struct perf_sample *sample,
47-
struct addr_location *al)
46+
struct addr_location *al,
47+
struct perf_annotate *ann)
4848
{
4949
struct hist_entry *he;
5050
int ret;
@@ -79,11 +79,13 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
7979
return ret;
8080
}
8181

82-
static int process_sample_event(union perf_event *event,
82+
static int process_sample_event(struct perf_event_ops *ops,
83+
union perf_event *event,
8384
struct perf_sample *sample,
8485
struct perf_evsel *evsel,
8586
struct perf_session *session)
8687
{
88+
struct perf_annotate *ann = container_of(ops, struct perf_annotate, ops);
8789
struct addr_location al;
8890

8991
if (perf_event__preprocess_sample(event, session, &al, sample,
@@ -96,7 +98,7 @@ static int process_sample_event(union perf_event *event,
9698
if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
9799
return 0;
98100

99-
if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al)) {
101+
if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
100102
pr_warning("problem incrementing symbol count, "
101103
"skipping event\n");
102104
return -1;
@@ -105,13 +107,15 @@ static int process_sample_event(union perf_event *event,
105107
return 0;
106108
}
107109

108-
static int hist_entry__tty_annotate(struct hist_entry *he, int evidx)
110+
static int hist_entry__tty_annotate(struct hist_entry *he, int evidx,
111+
struct perf_annotate *ann)
109112
{
110113
return symbol__tty_annotate(he->ms.sym, he->ms.map, evidx,
111114
ann->print_line, ann->full_paths, 0, 0);
112115
}
113116

114-
static void hists__find_annotations(struct hists *self, int evidx)
117+
static void hists__find_annotations(struct hists *self, int evidx,
118+
struct perf_annotate *ann)
115119
{
116120
struct rb_node *nd = rb_first(&self->entries), *next;
117121
int key = K_RIGHT;
@@ -149,7 +153,7 @@ static void hists__find_annotations(struct hists *self, int evidx)
149153
if (next != NULL)
150154
nd = next;
151155
} else {
152-
hist_entry__tty_annotate(he, evidx);
156+
hist_entry__tty_annotate(he, evidx, ann);
153157
nd = rb_next(nd);
154158
/*
155159
* Since we have a hist_entry per IP for the same
@@ -162,24 +166,15 @@ static void hists__find_annotations(struct hists *self, int evidx)
162166
}
163167
}
164168

165-
static struct perf_event_ops event_ops = {
166-
.sample = process_sample_event,
167-
.mmap = perf_event__process_mmap,
168-
.comm = perf_event__process_comm,
169-
.fork = perf_event__process_task,
170-
.ordered_samples = true,
171-
.ordering_requires_timestamps = true,
172-
};
173-
174-
static int __cmd_annotate(void)
169+
static int __cmd_annotate(struct perf_annotate *ann)
175170
{
176171
int ret;
177172
struct perf_session *session;
178173
struct perf_evsel *pos;
179174
u64 total_nr_samples;
180175

181176
session = perf_session__new(ann->input_name, O_RDONLY,
182-
ann->force, false, &event_ops);
177+
ann->force, false, &ann->ops);
183178
if (session == NULL)
184179
return -ENOMEM;
185180

@@ -190,7 +185,7 @@ static int __cmd_annotate(void)
190185
goto out_delete;
191186
}
192187

193-
ret = perf_session__process_events(session, &event_ops);
188+
ret = perf_session__process_events(session, &ann->ops);
194189
if (ret)
195190
goto out_delete;
196191

@@ -214,7 +209,7 @@ static int __cmd_annotate(void)
214209
total_nr_samples += nr_samples;
215210
hists__collapse_resort(hists);
216211
hists__output_resort(hists);
217-
hists__find_annotations(hists, pos->idx);
212+
hists__find_annotations(hists, pos->idx, ann);
218213
}
219214
}
220215

@@ -243,7 +238,20 @@ static const char * const annotate_usage[] = {
243238
NULL
244239
};
245240

246-
static const struct option options[] = {
241+
int cmd_annotate(int argc, const char **argv, const char *prefix __used)
242+
{
243+
struct perf_annotate annotate = {
244+
.ops = {
245+
.sample = process_sample_event,
246+
.mmap = perf_event__process_mmap,
247+
.comm = perf_event__process_comm,
248+
.fork = perf_event__process_task,
249+
.ordered_samples = true,
250+
.ordering_requires_timestamps = true,
251+
},
252+
.input_name = "perf.data",
253+
};
254+
const struct option options[] = {
247255
OPT_STRING('i', "input", &annotate.input_name, "file",
248256
"input file name"),
249257
OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
@@ -275,10 +283,8 @@ static const struct option options[] = {
275283
OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
276284
"Specify disassembler style (e.g. -M intel for intel syntax)"),
277285
OPT_END()
278-
};
286+
};
279287

280-
int cmd_annotate(int argc, const char **argv, const char *prefix __used)
281-
{
282288
argc = parse_options(argc, argv, options, annotate_usage, 0);
283289

284290
if (annotate.use_stdio)
@@ -312,5 +318,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
312318
return -1;
313319
}
314320

315-
return __cmd_annotate();
321+
return __cmd_annotate(&annotate);
316322
}

‎tools/perf/builtin-diff.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ static int hists__add_entry(struct hists *self,
3030
return -ENOMEM;
3131
}
3232

33-
static int diff__process_sample_event(union perf_event *event,
33+
static int diff__process_sample_event(struct perf_event_ops *ops __used,
34+
union perf_event *event,
3435
struct perf_sample *sample,
3536
struct perf_evsel *evsel __used,
3637
struct perf_session *session)

‎tools/perf/builtin-inject.c‎

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
static char const *input_name = "-";
1717
static bool inject_build_ids;
1818

19-
static int perf_event__repipe_synth(union perf_event *event,
19+
static int perf_event__repipe_synth(struct perf_event_ops *ops __used,
20+
union perf_event *event,
2021
struct perf_session *session __used)
2122
{
2223
uint32_t size;
@@ -36,47 +37,57 @@ static int perf_event__repipe_synth(union perf_event *event,
3637
return 0;
3738
}
3839

40+
static int perf_event__repipe_tracing_data_synth(union perf_event *event,
41+
struct perf_session *session)
42+
{
43+
return perf_event__repipe_synth(NULL, event, session);
44+
}
45+
3946
static int perf_event__repipe_attr(union perf_event *event,
4047
struct perf_evlist **pevlist __used)
4148
{
42-
return perf_event__repipe_synth(event, NULL);
49+
return perf_event__repipe_synth(NULL, event, NULL);
4350
}
4451

45-
static int perf_event__repipe(union perf_event *event,
52+
static int perf_event__repipe(struct perf_event_ops *ops,
53+
union perf_event *event,
4654
struct perf_sample *sample __used,
4755
struct perf_session *session)
4856
{
49-
return perf_event__repipe_synth(event, session);
57+
return perf_event__repipe_synth(ops, event, session);
5058
}
5159

52-
static int perf_event__repipe_sample(union perf_event *event,
60+
static int perf_event__repipe_sample(struct perf_event_ops *ops,
61+
union perf_event *event,
5362
struct perf_sample *sample __used,
5463
struct perf_evsel *evsel __used,
5564
struct perf_session *session)
5665
{
57-
return perf_event__repipe_synth(event, session);
66+
return perf_event__repipe_synth(ops, event, session);
5867
}
5968

60-
static int perf_event__repipe_mmap(union perf_event *event,
69+
static int perf_event__repipe_mmap(struct perf_event_ops *ops,
70+
union perf_event *event,
6171
struct perf_sample *sample,
6272
struct perf_session *session)
6373
{
6474
int err;
6575

66-
err = perf_event__process_mmap(event, sample, session);
67-
perf_event__repipe(event, sample, session);
76+
err = perf_event__process_mmap(ops, event, sample, session);
77+
perf_event__repipe(ops, event, sample, session);
6878

6979
return err;
7080
}
7181

72-
static int perf_event__repipe_task(union perf_event *event,
82+
static int perf_event__repipe_task(struct perf_event_ops *ops,
83+
union perf_event *event,
7384
struct perf_sample *sample,
7485
struct perf_session *session)
7586
{
7687
int err;
7788

78-
err = perf_event__process_task(event, sample, session);
79-
perf_event__repipe(event, sample, session);
89+
err = perf_event__process_task(ops, event, sample, session);
90+
perf_event__repipe(ops, event, sample, session);
8091

8192
return err;
8293
}
@@ -86,7 +97,7 @@ static int perf_event__repipe_tracing_data(union perf_event *event,
8697
{
8798
int err;
8899

89-
perf_event__repipe_synth(event, session);
100+
perf_event__repipe_synth(NULL, event, session);
90101
err = perf_event__process_tracing_data(event, session);
91102

92103
return err;
@@ -106,7 +117,8 @@ static int dso__read_build_id(struct dso *self)
106117
return -1;
107118
}
108119

109-
static int dso__inject_build_id(struct dso *self, struct perf_session *session)
120+
static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops,
121+
struct perf_session *session)
110122
{
111123
u16 misc = PERF_RECORD_MISC_USER;
112124
struct machine *machine;
@@ -126,7 +138,7 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session)
126138
if (self->kernel)
127139
misc = PERF_RECORD_MISC_KERNEL;
128140

129-
err = perf_event__synthesize_build_id(self, misc, perf_event__repipe,
141+
err = perf_event__synthesize_build_id(ops, self, misc, perf_event__repipe,
130142
machine, session);
131143
if (err) {
132144
pr_err("Can't synthesize build_id event for %s\n", self->long_name);
@@ -136,7 +148,8 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session)
136148
return 0;
137149
}
138150

139-
static int perf_event__inject_buildid(union perf_event *event,
151+
static int perf_event__inject_buildid(struct perf_event_ops *ops,
152+
union perf_event *event,
140153
struct perf_sample *sample,
141154
struct perf_evsel *evsel __used,
142155
struct perf_session *session)
@@ -161,7 +174,7 @@ static int perf_event__inject_buildid(union perf_event *event,
161174
if (!al.map->dso->hit) {
162175
al.map->dso->hit = 1;
163176
if (map__load(al.map, NULL) >= 0) {
164-
dso__inject_build_id(al.map->dso, session);
177+
dso__inject_build_id(al.map->dso, ops, session);
165178
/*
166179
* If this fails, too bad, let the other side
167180
* account this as unresolved.
@@ -174,7 +187,7 @@ static int perf_event__inject_buildid(union perf_event *event,
174187
}
175188

176189
repipe:
177-
perf_event__repipe(event, sample, session);
190+
perf_event__repipe(ops, event, sample, session);
178191
return 0;
179192
}
180193

@@ -189,9 +202,9 @@ struct perf_event_ops inject_ops = {
189202
.throttle = perf_event__repipe,
190203
.unthrottle = perf_event__repipe,
191204
.attr = perf_event__repipe_attr,
192-
.event_type = perf_event__repipe_synth,
193-
.tracing_data = perf_event__repipe_synth,
194-
.build_id = perf_event__repipe_synth,
205+
.event_type = perf_event__repipe_synth,
206+
.tracing_data = perf_event__repipe_tracing_data_synth,
207+
.build_id = perf_event__repipe_synth,
195208
};
196209

197210
extern volatile int session_done;

‎tools/perf/builtin-kmem.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ static void process_raw_event(union perf_event *raw_event __used, void *data,
303303
}
304304
}
305305

306-
static int process_sample_event(union perf_event *event,
306+
static int process_sample_event(struct perf_event_ops *ops __used,
307+
union perf_event *event,
307308
struct perf_sample *sample,
308309
struct perf_evsel *evsel __used,
309310
struct perf_session *session)

‎tools/perf/builtin-lock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ static void dump_info(void)
845845
die("Unknown type of information\n");
846846
}
847847

848-
static int process_sample_event(union perf_event *event,
848+
static int process_sample_event(struct perf_event_ops *ops __used,
849+
union perf_event *event,
849850
struct perf_sample *sample,
850851
struct perf_evsel *evsel __used,
851852
struct perf_session *s)

0 commit comments

Comments
 (0)