aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 05:30:20 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 07:39:28 -0500
commit45694aa7702bc44d538a3bcb51bb2bb96cf190c0 (patch)
tree81bc1f449f55984556d89b63c461dcf181dc97e5 /tools
parent743eb868657bdb1b26c7b24077ca21c67c82c777 (diff)
perf tools: Rename perf_event_ops to perf_tool
To better reflect that it became the base class for all tools, that must be in each tool struct and where common stuff will be put. 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-qgpc4msetqlwr8y2k7537cxe@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/builtin-annotate.c13
-rw-r--r--tools/perf/builtin-diff.c11
-rw-r--r--tools/perf/builtin-inject.c55
-rw-r--r--tools/perf/builtin-kmem.c9
-rw-r--r--tools/perf/builtin-lock.c5
-rw-r--r--tools/perf/builtin-record.c35
-rw-r--r--tools/perf/builtin-report.c17
-rw-r--r--tools/perf/builtin-sched.c9
-rw-r--r--tools/perf/builtin-script.c9
-rw-r--r--tools/perf/builtin-timechart.c15
-rw-r--r--tools/perf/builtin-top.c6
-rw-r--r--tools/perf/util/build-id.c7
-rw-r--r--tools/perf/util/build-id.h2
-rw-r--r--tools/perf/util/event.c54
-rw-r--r--tools/perf/util/event.h22
-rw-r--r--tools/perf/util/header.c28
-rw-r--r--tools/perf/util/header.h16
-rw-r--r--tools/perf/util/session.c163
-rw-r--r--tools/perf/util/session.h49
-rw-r--r--tools/perf/util/tool.h45
-rw-r--r--tools/perf/util/top.h7
22 files changed, 301 insertions, 277 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index b98e3075646b..ac86d67b636e 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -278,6 +278,7 @@ LIB_H += util/strbuf.h
278LIB_H += util/strlist.h 278LIB_H += util/strlist.h
279LIB_H += util/strfilter.h 279LIB_H += util/strfilter.h
280LIB_H += util/svghelper.h 280LIB_H += util/svghelper.h
281LIB_H += util/tool.h
281LIB_H += util/run-command.h 282LIB_H += util/run-command.h
282LIB_H += util/sigchain.h 283LIB_H += util/sigchain.h
283LIB_H += util/symbol.h 284LIB_H += util/symbol.h
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index dff081a388bb..c01139fa4a10 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -27,11 +27,12 @@
27#include "util/sort.h" 27#include "util/sort.h"
28#include "util/hist.h" 28#include "util/hist.h"
29#include "util/session.h" 29#include "util/session.h"
30#include "util/tool.h"
30 31
31#include <linux/bitmap.h> 32#include <linux/bitmap.h>
32 33
33struct perf_annotate { 34struct perf_annotate {
34 struct perf_event_ops ops; 35 struct perf_tool tool;
35 char const *input_name; 36 char const *input_name;
36 bool force, use_tui, use_stdio; 37 bool force, use_tui, use_stdio;
37 bool full_paths; 38 bool full_paths;
@@ -79,13 +80,13 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
79 return ret; 80 return ret;
80} 81}
81 82
82static int process_sample_event(struct perf_event_ops *ops, 83static int process_sample_event(struct perf_tool *tool,
83 union perf_event *event, 84 union perf_event *event,
84 struct perf_sample *sample, 85 struct perf_sample *sample,
85 struct perf_evsel *evsel, 86 struct perf_evsel *evsel,
86 struct machine *machine) 87 struct machine *machine)
87{ 88{
88 struct perf_annotate *ann = container_of(ops, struct perf_annotate, ops); 89 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
89 struct addr_location al; 90 struct addr_location al;
90 91
91 if (perf_event__preprocess_sample(event, machine, &al, sample, 92 if (perf_event__preprocess_sample(event, machine, &al, sample,
@@ -174,7 +175,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
174 u64 total_nr_samples; 175 u64 total_nr_samples;
175 176
176 session = perf_session__new(ann->input_name, O_RDONLY, 177 session = perf_session__new(ann->input_name, O_RDONLY,
177 ann->force, false, &ann->ops); 178 ann->force, false, &ann->tool);
178 if (session == NULL) 179 if (session == NULL)
179 return -ENOMEM; 180 return -ENOMEM;
180 181
@@ -185,7 +186,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
185 goto out_delete; 186 goto out_delete;
186 } 187 }
187 188
188 ret = perf_session__process_events(session, &ann->ops); 189 ret = perf_session__process_events(session, &ann->tool);
189 if (ret) 190 if (ret)
190 goto out_delete; 191 goto out_delete;
191 192
@@ -241,7 +242,7 @@ static const char * const annotate_usage[] = {
241int cmd_annotate(int argc, const char **argv, const char *prefix __used) 242int cmd_annotate(int argc, const char **argv, const char *prefix __used)
242{ 243{
243 struct perf_annotate annotate = { 244 struct perf_annotate annotate = {
244 .ops = { 245 .tool = {
245 .sample = process_sample_event, 246 .sample = process_sample_event,
246 .mmap = perf_event__process_mmap, 247 .mmap = perf_event__process_mmap,
247 .comm = perf_event__process_comm, 248 .comm = perf_event__process_comm,
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 478b0aeb2a62..4f19513d7dda 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -11,6 +11,7 @@
11#include "util/hist.h" 11#include "util/hist.h"
12#include "util/evsel.h" 12#include "util/evsel.h"
13#include "util/session.h" 13#include "util/session.h"
14#include "util/tool.h"
14#include "util/sort.h" 15#include "util/sort.h"
15#include "util/symbol.h" 16#include "util/symbol.h"
16#include "util/util.h" 17#include "util/util.h"
@@ -31,7 +32,7 @@ static int hists__add_entry(struct hists *self,
31 return -ENOMEM; 32 return -ENOMEM;
32} 33}
33 34
34static int diff__process_sample_event(struct perf_event_ops *ops __used, 35static int diff__process_sample_event(struct perf_tool *tool __used,
35 union perf_event *event, 36 union perf_event *event,
36 struct perf_sample *sample, 37 struct perf_sample *sample,
37 struct perf_evsel *evsel __used, 38 struct perf_evsel *evsel __used,
@@ -57,7 +58,7 @@ static int diff__process_sample_event(struct perf_event_ops *ops __used,
57 return 0; 58 return 0;
58} 59}
59 60
60static struct perf_event_ops event_ops = { 61static struct perf_tool perf_diff = {
61 .sample = diff__process_sample_event, 62 .sample = diff__process_sample_event,
62 .mmap = perf_event__process_mmap, 63 .mmap = perf_event__process_mmap,
63 .comm = perf_event__process_comm, 64 .comm = perf_event__process_comm,
@@ -147,13 +148,13 @@ static int __cmd_diff(void)
147 int ret, i; 148 int ret, i;
148 struct perf_session *session[2]; 149 struct perf_session *session[2];
149 150
150 session[0] = perf_session__new(input_old, O_RDONLY, force, false, &event_ops); 151 session[0] = perf_session__new(input_old, O_RDONLY, force, false, &perf_diff);
151 session[1] = perf_session__new(input_new, O_RDONLY, force, false, &event_ops); 152 session[1] = perf_session__new(input_new, O_RDONLY, force, false, &perf_diff);
152 if (session[0] == NULL || session[1] == NULL) 153 if (session[0] == NULL || session[1] == NULL)
153 return -ENOMEM; 154 return -ENOMEM;
154 155
155 for (i = 0; i < 2; ++i) { 156 for (i = 0; i < 2; ++i) {
156 ret = perf_session__process_events(session[i], &event_ops); 157 ret = perf_session__process_events(session[i], &perf_diff);
157 if (ret) 158 if (ret)
158 goto out_delete; 159 goto out_delete;
159 } 160 }
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index a5bcf81776fc..09c106193e65 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -9,6 +9,7 @@
9 9
10#include "perf.h" 10#include "perf.h"
11#include "util/session.h" 11#include "util/session.h"
12#include "util/tool.h"
12#include "util/debug.h" 13#include "util/debug.h"
13 14
14#include "util/parse-options.h" 15#include "util/parse-options.h"
@@ -16,7 +17,7 @@
16static char const *input_name = "-"; 17static char const *input_name = "-";
17static bool inject_build_ids; 18static bool inject_build_ids;
18 19
19static int perf_event__repipe_synth(struct perf_event_ops *ops __used, 20static int perf_event__repipe_synth(struct perf_tool *tool __used,
20 union perf_event *event, 21 union perf_event *event,
21 struct machine *machine __used) 22 struct machine *machine __used)
22{ 23{
@@ -37,17 +38,17 @@ static int perf_event__repipe_synth(struct perf_event_ops *ops __used,
37 return 0; 38 return 0;
38} 39}
39 40
40static int perf_event__repipe_op2_synth(struct perf_event_ops *ops, 41static int perf_event__repipe_op2_synth(struct perf_tool *tool,
41 union perf_event *event, 42 union perf_event *event,
42 struct perf_session *session __used) 43 struct perf_session *session __used)
43{ 44{
44 return perf_event__repipe_synth(ops, event, NULL); 45 return perf_event__repipe_synth(tool, event, NULL);
45} 46}
46 47
47static int perf_event__repipe_event_type_synth(struct perf_event_ops *ops, 48static int perf_event__repipe_event_type_synth(struct perf_tool *tool,
48 union perf_event *event) 49 union perf_event *event)
49{ 50{
50 return perf_event__repipe_synth(ops, event, NULL); 51 return perf_event__repipe_synth(tool, event, NULL);
51} 52}
52 53
53static int perf_event__repipe_tracing_data_synth(union perf_event *event, 54static int perf_event__repipe_tracing_data_synth(union perf_event *event,
@@ -62,45 +63,45 @@ static int perf_event__repipe_attr(union perf_event *event,
62 return perf_event__repipe_synth(NULL, event, NULL); 63 return perf_event__repipe_synth(NULL, event, NULL);
63} 64}
64 65
65static int perf_event__repipe(struct perf_event_ops *ops, 66static int perf_event__repipe(struct perf_tool *tool,
66 union perf_event *event, 67 union perf_event *event,
67 struct perf_sample *sample __used, 68 struct perf_sample *sample __used,
68 struct machine *machine) 69 struct machine *machine)
69{ 70{
70 return perf_event__repipe_synth(ops, event, machine); 71 return perf_event__repipe_synth(tool, event, machine);
71} 72}
72 73
73static int perf_event__repipe_sample(struct perf_event_ops *ops, 74static int perf_event__repipe_sample(struct perf_tool *tool,
74 union perf_event *event, 75 union perf_event *event,
75 struct perf_sample *sample __used, 76 struct perf_sample *sample __used,
76 struct perf_evsel *evsel __used, 77 struct perf_evsel *evsel __used,
77 struct machine *machine) 78 struct machine *machine)
78{ 79{
79 return perf_event__repipe_synth(ops, event, machine); 80 return perf_event__repipe_synth(tool, event, machine);
80} 81}
81 82
82static int perf_event__repipe_mmap(struct perf_event_ops *ops, 83static int perf_event__repipe_mmap(struct perf_tool *tool,
83 union perf_event *event, 84 union perf_event *event,
84 struct perf_sample *sample, 85 struct perf_sample *sample,
85 struct machine *machine) 86 struct machine *machine)
86{ 87{
87 int err; 88 int err;
88 89
89 err = perf_event__process_mmap(ops, event, sample, machine); 90 err = perf_event__process_mmap(tool, event, sample, machine);
90 perf_event__repipe(ops, event, sample, machine); 91 perf_event__repipe(tool, event, sample, machine);
91 92
92 return err; 93 return err;
93} 94}
94 95
95static int perf_event__repipe_task(struct perf_event_ops *ops, 96static int perf_event__repipe_task(struct perf_tool *tool,
96 union perf_event *event, 97 union perf_event *event,
97 struct perf_sample *sample, 98 struct perf_sample *sample,
98 struct machine *machine) 99 struct machine *machine)
99{ 100{
100 int err; 101 int err;
101 102
102 err = perf_event__process_task(ops, event, sample, machine); 103 err = perf_event__process_task(tool, event, sample, machine);
103 perf_event__repipe(ops, event, sample, machine); 104 perf_event__repipe(tool, event, sample, machine);
104 105
105 return err; 106 return err;
106} 107}
@@ -130,7 +131,7 @@ static int dso__read_build_id(struct dso *self)
130 return -1; 131 return -1;
131} 132}
132 133
133static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops, 134static int dso__inject_build_id(struct dso *self, struct perf_tool *tool,
134 struct machine *machine) 135 struct machine *machine)
135{ 136{
136 u16 misc = PERF_RECORD_MISC_USER; 137 u16 misc = PERF_RECORD_MISC_USER;
@@ -144,7 +145,7 @@ static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops,
144 if (self->kernel) 145 if (self->kernel)
145 misc = PERF_RECORD_MISC_KERNEL; 146 misc = PERF_RECORD_MISC_KERNEL;
146 147
147 err = perf_event__synthesize_build_id(ops, self, misc, perf_event__repipe, 148 err = perf_event__synthesize_build_id(tool, self, misc, perf_event__repipe,
148 machine); 149 machine);
149 if (err) { 150 if (err) {
150 pr_err("Can't synthesize build_id event for %s\n", self->long_name); 151 pr_err("Can't synthesize build_id event for %s\n", self->long_name);
@@ -154,7 +155,7 @@ static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops,
154 return 0; 155 return 0;
155} 156}
156 157
157static int perf_event__inject_buildid(struct perf_event_ops *ops, 158static int perf_event__inject_buildid(struct perf_tool *tool,
158 union perf_event *event, 159 union perf_event *event,
159 struct perf_sample *sample, 160 struct perf_sample *sample,
160 struct perf_evsel *evsel __used, 161 struct perf_evsel *evsel __used,
@@ -180,7 +181,7 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops,
180 if (!al.map->dso->hit) { 181 if (!al.map->dso->hit) {
181 al.map->dso->hit = 1; 182 al.map->dso->hit = 1;
182 if (map__load(al.map, NULL) >= 0) { 183 if (map__load(al.map, NULL) >= 0) {
183 dso__inject_build_id(al.map->dso, ops, machine); 184 dso__inject_build_id(al.map->dso, tool, machine);
184 /* 185 /*
185 * If this fails, too bad, let the other side 186 * If this fails, too bad, let the other side
186 * account this as unresolved. 187 * account this as unresolved.
@@ -193,11 +194,11 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops,
193 } 194 }
194 195
195repipe: 196repipe:
196 perf_event__repipe(ops, event, sample, machine); 197 perf_event__repipe(tool, event, sample, machine);
197 return 0; 198 return 0;
198} 199}
199 200
200struct perf_event_ops inject_ops = { 201struct perf_tool perf_inject = {
201 .sample = perf_event__repipe_sample, 202 .sample = perf_event__repipe_sample,
202 .mmap = perf_event__repipe, 203 .mmap = perf_event__repipe,
203 .comm = perf_event__repipe, 204 .comm = perf_event__repipe,
@@ -228,17 +229,17 @@ static int __cmd_inject(void)
228 signal(SIGINT, sig_handler); 229 signal(SIGINT, sig_handler);
229 230
230 if (inject_build_ids) { 231 if (inject_build_ids) {
231 inject_ops.sample = perf_event__inject_buildid; 232 perf_inject.sample = perf_event__inject_buildid;
232 inject_ops.mmap = perf_event__repipe_mmap; 233 perf_inject.mmap = perf_event__repipe_mmap;
233 inject_ops.fork = perf_event__repipe_task; 234 perf_inject.fork = perf_event__repipe_task;
234 inject_ops.tracing_data = perf_event__repipe_tracing_data; 235 perf_inject.tracing_data = perf_event__repipe_tracing_data;
235 } 236 }
236 237
237 session = perf_session__new(input_name, O_RDONLY, false, true, &inject_ops); 238 session = perf_session__new(input_name, O_RDONLY, false, true, &perf_inject);
238 if (session == NULL) 239 if (session == NULL)
239 return -ENOMEM; 240 return -ENOMEM;
240 241
241 ret = perf_session__process_events(session, &inject_ops); 242 ret = perf_session__process_events(session, &perf_inject);
242 243
243 perf_session__delete(session); 244 perf_session__delete(session);
244 245
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 27b2a15dc7b2..886174e9525b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -7,6 +7,7 @@
7#include "util/thread.h" 7#include "util/thread.h"
8#include "util/header.h" 8#include "util/header.h"
9#include "util/session.h" 9#include "util/session.h"
10#include "util/tool.h"
10 11
11#include "util/parse-options.h" 12#include "util/parse-options.h"
12#include "util/trace-event.h" 13#include "util/trace-event.h"
@@ -303,7 +304,7 @@ static void process_raw_event(union perf_event *raw_event __used, void *data,
303 } 304 }
304} 305}
305 306
306static int process_sample_event(struct perf_event_ops *ops __used, 307static int process_sample_event(struct perf_tool *tool __used,
307 union perf_event *event, 308 union perf_event *event,
308 struct perf_sample *sample, 309 struct perf_sample *sample,
309 struct perf_evsel *evsel __used, 310 struct perf_evsel *evsel __used,
@@ -325,7 +326,7 @@ static int process_sample_event(struct perf_event_ops *ops __used,
325 return 0; 326 return 0;
326} 327}
327 328
328static struct perf_event_ops event_ops = { 329static struct perf_tool perf_kmem = {
329 .sample = process_sample_event, 330 .sample = process_sample_event,
330 .comm = perf_event__process_comm, 331 .comm = perf_event__process_comm,
331 .ordered_samples = true, 332 .ordered_samples = true,
@@ -484,7 +485,7 @@ static int __cmd_kmem(void)
484{ 485{
485 int err = -EINVAL; 486 int err = -EINVAL;
486 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 487 struct perf_session *session = perf_session__new(input_name, O_RDONLY,
487 0, false, &event_ops); 488 0, false, &perf_kmem);
488 if (session == NULL) 489 if (session == NULL)
489 return -ENOMEM; 490 return -ENOMEM;
490 491
@@ -495,7 +496,7 @@ static int __cmd_kmem(void)
495 goto out_delete; 496 goto out_delete;
496 497
497 setup_pager(); 498 setup_pager();
498 err = perf_session__process_events(session, &event_ops); 499 err = perf_session__process_events(session, &perf_kmem);
499 if (err != 0) 500 if (err != 0)
500 goto out_delete; 501 goto out_delete;
501 sort_result(); 502 sort_result();
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 99b032adb83e..4db5e5293067 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -12,6 +12,7 @@
12 12
13#include "util/debug.h" 13#include "util/debug.h"
14#include "util/session.h" 14#include "util/session.h"
15#include "util/tool.h"
15 16
16#include <sys/types.h> 17#include <sys/types.h>
17#include <sys/prctl.h> 18#include <sys/prctl.h>
@@ -845,7 +846,7 @@ static void dump_info(void)
845 die("Unknown type of information\n"); 846 die("Unknown type of information\n");
846} 847}
847 848
848static int process_sample_event(struct perf_event_ops *ops __used, 849static int process_sample_event(struct perf_tool *tool __used,
849 union perf_event *event, 850 union perf_event *event,
850 struct perf_sample *sample, 851 struct perf_sample *sample,
851 struct perf_evsel *evsel __used, 852 struct perf_evsel *evsel __used,
@@ -864,7 +865,7 @@ static int process_sample_event(struct perf_event_ops *ops __used,
864 return 0; 865 return 0;
865} 866}
866 867
867static struct perf_event_ops eops = { 868static struct perf_tool eops = {
868 .sample = process_sample_event, 869 .sample = process_sample_event,
869 .comm = perf_event__process_comm, 870 .comm = perf_event__process_comm,
870 .ordered_samples = true, 871 .ordered_samples = true,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 0af598a1059f..7d4fdaacc8ba 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -22,6 +22,7 @@
22#include "util/evsel.h" 22#include "util/evsel.h"
23#include "util/debug.h" 23#include "util/debug.h"
24#include "util/session.h" 24#include "util/session.h"
25#include "util/tool.h"
25#include "util/symbol.h" 26#include "util/symbol.h"
26#include "util/cpumap.h" 27#include "util/cpumap.h"
27#include "util/thread_map.h" 28#include "util/thread_map.h"
@@ -36,7 +37,7 @@ enum write_mode_t {
36}; 37};
37 38
38struct perf_record { 39struct perf_record {
39 struct perf_event_ops ops; 40 struct perf_tool tool;
40 struct perf_record_opts opts; 41 struct perf_record_opts opts;
41 u64 bytes_written; 42 u64 bytes_written;
42 const char *output_name; 43 const char *output_name;
@@ -76,12 +77,12 @@ static void write_output(struct perf_record *rec, void *buf, size_t size)
76 } 77 }
77} 78}
78 79
79static int process_synthesized_event(struct perf_event_ops *ops, 80static int process_synthesized_event(struct perf_tool *tool,
80 union perf_event *event, 81 union perf_event *event,
81 struct perf_sample *sample __used, 82 struct perf_sample *sample __used,
82 struct machine *machine __used) 83 struct machine *machine __used)
83{ 84{
84 struct perf_record *rec = container_of(ops, struct perf_record, ops); 85 struct perf_record *rec = container_of(tool, struct perf_record, tool);
85 write_output(rec, event, event->header.size); 86 write_output(rec, event, event->header.size);
86 return 0; 87 return 0;
87} 88}
@@ -319,7 +320,7 @@ static void perf_record__exit(int status __used, void *arg)
319static void perf_event__synthesize_guest_os(struct machine *machine, void *data) 320static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
320{ 321{
321 int err; 322 int err;
322 struct perf_event_ops *ops = data; 323 struct perf_tool *tool = data;
323 324
324 if (machine__is_host(machine)) 325 if (machine__is_host(machine))
325 return; 326 return;
@@ -332,7 +333,7 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
332 *method is used to avoid symbol missing when the first addr is 333 *method is used to avoid symbol missing when the first addr is
333 *in module instead of in guest kernel. 334 *in module instead of in guest kernel.
334 */ 335 */
335 err = perf_event__synthesize_modules(ops, process_synthesized_event, 336 err = perf_event__synthesize_modules(tool, process_synthesized_event,
336 machine); 337 machine);
337 if (err < 0) 338 if (err < 0)
338 pr_err("Couldn't record guest kernel [%d]'s reference" 339 pr_err("Couldn't record guest kernel [%d]'s reference"
@@ -342,10 +343,10 @@ static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
342 * We use _stext for guest kernel because guest kernel's /proc/kallsyms 343 * We use _stext for guest kernel because guest kernel's /proc/kallsyms
343 * have no _text sometimes. 344 * have no _text sometimes.
344 */ 345 */
345 err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event, 346 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
346 machine, "_text"); 347 machine, "_text");
347 if (err < 0) 348 if (err < 0)
348 err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event, 349 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
349 machine, "_stext"); 350 machine, "_stext");
350 if (err < 0) 351 if (err < 0)
351 pr_err("Couldn't record guest kernel [%d]'s reference" 352 pr_err("Couldn't record guest kernel [%d]'s reference"
@@ -378,7 +379,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
378 unsigned long waking = 0; 379 unsigned long waking = 0;
379 const bool forks = argc > 0; 380 const bool forks = argc > 0;
380 struct machine *machine; 381 struct machine *machine;
381 struct perf_event_ops *ops = &rec->ops; 382 struct perf_tool *tool = &rec->tool;
382 struct perf_record_opts *opts = &rec->opts; 383 struct perf_record_opts *opts = &rec->opts;
383 struct perf_evlist *evsel_list = rec->evlist; 384 struct perf_evlist *evsel_list = rec->evlist;
384 const char *output_name = rec->output_name; 385 const char *output_name = rec->output_name;
@@ -501,14 +502,14 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
501 } 502 }
502 503
503 if (opts->pipe_output) { 504 if (opts->pipe_output) {
504 err = perf_event__synthesize_attrs(ops, session, 505 err = perf_event__synthesize_attrs(tool, session,
505 process_synthesized_event); 506 process_synthesized_event);
506 if (err < 0) { 507 if (err < 0) {
507 pr_err("Couldn't synthesize attrs.\n"); 508 pr_err("Couldn't synthesize attrs.\n");
508 return err; 509 return err;
509 } 510 }
510 511
511 err = perf_event__synthesize_event_types(ops, process_synthesized_event, 512 err = perf_event__synthesize_event_types(tool, process_synthesized_event,
512 machine); 513 machine);
513 if (err < 0) { 514 if (err < 0) {
514 pr_err("Couldn't synthesize event_types.\n"); 515 pr_err("Couldn't synthesize event_types.\n");
@@ -524,7 +525,7 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
524 * return this more properly and also 525 * return this more properly and also
525 * propagate errors that now are calling die() 526 * propagate errors that now are calling die()
526 */ 527 */
527 err = perf_event__synthesize_tracing_data(ops, output, evsel_list, 528 err = perf_event__synthesize_tracing_data(tool, output, evsel_list,
528 process_synthesized_event); 529 process_synthesized_event);
529 if (err <= 0) { 530 if (err <= 0) {
530 pr_err("Couldn't record tracing data.\n"); 531 pr_err("Couldn't record tracing data.\n");
@@ -534,17 +535,17 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
534 } 535 }
535 } 536 }
536 537
537 err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event, 538 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
538 machine, "_text"); 539 machine, "_text");
539 if (err < 0) 540 if (err < 0)
540 err = perf_event__synthesize_kernel_mmap(ops, process_synthesized_event, 541 err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
541 machine, "_stext"); 542 machine, "_stext");
542 if (err < 0) 543 if (err < 0)
543 pr_err("Couldn't record kernel reference relocation symbol\n" 544 pr_err("Couldn't record kernel reference relocation symbol\n"
544 "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n" 545 "Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
545 "Check /proc/kallsyms permission or run as root.\n"); 546 "Check /proc/kallsyms permission or run as root.\n");
546 547
547 err = perf_event__synthesize_modules(ops, process_synthesized_event, 548 err = perf_event__synthesize_modules(tool, process_synthesized_event,
548 machine); 549 machine);
549 if (err < 0) 550 if (err < 0)
550 pr_err("Couldn't record kernel module information.\n" 551 pr_err("Couldn't record kernel module information.\n"
@@ -552,15 +553,15 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
552 "Check /proc/modules permission or run as root.\n"); 553 "Check /proc/modules permission or run as root.\n");
553 554
554 if (perf_guest) 555 if (perf_guest)
555 perf_session__process_machines(session, ops, 556 perf_session__process_machines(session, tool,
556 perf_event__synthesize_guest_os); 557 perf_event__synthesize_guest_os);
557 558
558 if (!opts->system_wide) 559 if (!opts->system_wide)
559 perf_event__synthesize_thread_map(ops, evsel_list->threads, 560 perf_event__synthesize_thread_map(tool, evsel_list->threads,
560 process_synthesized_event, 561 process_synthesized_event,
561 machine); 562 machine);
562 else 563 else
563 perf_event__synthesize_threads(ops, process_synthesized_event, 564 perf_event__synthesize_threads(tool, process_synthesized_event,
564 machine); 565 machine);
565 566
566 if (rec->realtime_prio) { 567 if (rec->realtime_prio) {
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index ea64fbbdff43..eef8e423deb0 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -25,6 +25,7 @@
25#include "util/evsel.h" 25#include "util/evsel.h"
26#include "util/header.h" 26#include "util/header.h"
27#include "util/session.h" 27#include "util/session.h"
28#include "util/tool.h"
28 29
29#include "util/parse-options.h" 30#include "util/parse-options.h"
30#include "util/parse-events.h" 31#include "util/parse-events.h"
@@ -36,7 +37,7 @@
36#include <linux/bitmap.h> 37#include <linux/bitmap.h>
37 38
38struct perf_report { 39struct perf_report {
39 struct perf_event_ops ops; 40 struct perf_tool tool;
40 struct perf_session *session; 41 struct perf_session *session;
41 char const *input_name; 42 char const *input_name;
42 bool force, use_tui, use_stdio; 43 bool force, use_tui, use_stdio;
@@ -103,13 +104,13 @@ out:
103} 104}
104 105
105 106
106static int process_sample_event(struct perf_event_ops *ops, 107static int process_sample_event(struct perf_tool *tool,
107 union perf_event *event, 108 union perf_event *event,
108 struct perf_sample *sample, 109 struct perf_sample *sample,
109 struct perf_evsel *evsel, 110 struct perf_evsel *evsel,
110 struct machine *machine) 111 struct machine *machine)
111{ 112{
112 struct perf_report *rep = container_of(ops, struct perf_report, ops); 113 struct perf_report *rep = container_of(tool, struct perf_report, tool);
113 struct addr_location al; 114 struct addr_location al;
114 115
115 if (perf_event__preprocess_sample(event, machine, &al, sample, 116 if (perf_event__preprocess_sample(event, machine, &al, sample,
@@ -136,13 +137,13 @@ static int process_sample_event(struct perf_event_ops *ops,
136 return 0; 137 return 0;
137} 138}
138 139
139static int process_read_event(struct perf_event_ops *ops, 140static int process_read_event(struct perf_tool *tool,
140 union perf_event *event, 141 union perf_event *event,
141 struct perf_sample *sample __used, 142 struct perf_sample *sample __used,
142 struct perf_evsel *evsel, 143 struct perf_evsel *evsel,
143 struct machine *machine __used) 144 struct machine *machine __used)
144{ 145{
145 struct perf_report *rep = container_of(ops, struct perf_report, ops); 146 struct perf_report *rep = container_of(tool, struct perf_report, tool);
146 147
147 if (rep->show_threads) { 148 if (rep->show_threads) {
148 const char *name = evsel ? event_name(evsel) : "unknown"; 149 const char *name = evsel ? event_name(evsel) : "unknown";
@@ -254,7 +255,7 @@ static int __cmd_report(struct perf_report *rep)
254 signal(SIGINT, sig_handler); 255 signal(SIGINT, sig_handler);
255 256
256 session = perf_session__new(rep->input_name, O_RDONLY, 257 session = perf_session__new(rep->input_name, O_RDONLY,
257 rep->force, false, &rep->ops); 258 rep->force, false, &rep->tool);
258 if (session == NULL) 259 if (session == NULL)
259 return -ENOMEM; 260 return -ENOMEM;
260 261
@@ -277,7 +278,7 @@ static int __cmd_report(struct perf_report *rep)
277 if (ret) 278 if (ret)
278 goto out_delete; 279 goto out_delete;
279 280
280 ret = perf_session__process_events(session, &rep->ops); 281 ret = perf_session__process_events(session, &rep->tool);
281 if (ret) 282 if (ret)
282 goto out_delete; 283 goto out_delete;
283 284
@@ -435,7 +436,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
435 NULL 436 NULL
436 }; 437 };
437 struct perf_report report = { 438 struct perf_report report = {
438 .ops = { 439 .tool = {
439 .sample = process_sample_event, 440 .sample = process_sample_event,
440 .mmap = perf_event__process_mmap, 441 .mmap = perf_event__process_mmap,
441 .comm = perf_event__process_comm, 442 .comm = perf_event__process_comm,
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 6a771f822e5d..0ee868e6f63b 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -8,6 +8,7 @@
8#include "util/thread.h" 8#include "util/thread.h"
9#include "util/header.h" 9#include "util/header.h"
10#include "util/session.h" 10#include "util/session.h"
11#include "util/tool.h"
11 12
12#include "util/parse-options.h" 13#include "util/parse-options.h"
13#include "util/trace-event.h" 14#include "util/trace-event.h"
@@ -1602,7 +1603,7 @@ static void process_raw_event(union perf_event *raw_event __used,
1602 process_sched_migrate_task_event(data, machine, event, cpu, timestamp, thread); 1603 process_sched_migrate_task_event(data, machine, event, cpu, timestamp, thread);
1603} 1604}
1604 1605
1605static int process_sample_event(struct perf_event_ops *ops __used, 1606static int process_sample_event(struct perf_tool *tool __used,
1606 union perf_event *event, 1607 union perf_event *event,
1607 struct perf_sample *sample, 1608 struct perf_sample *sample,
1608 struct perf_evsel *evsel, 1609 struct perf_evsel *evsel,
@@ -1631,7 +1632,7 @@ static int process_sample_event(struct perf_event_ops *ops __used,
1631 return 0; 1632 return 0;
1632} 1633}
1633 1634
1634static struct perf_event_ops event_ops = { 1635static struct perf_tool perf_sched = {
1635 .sample = process_sample_event, 1636 .sample = process_sample_event,
1636 .comm = perf_event__process_comm, 1637 .comm = perf_event__process_comm,
1637 .lost = perf_event__process_lost, 1638 .lost = perf_event__process_lost,
@@ -1643,12 +1644,12 @@ static void read_events(bool destroy, struct perf_session **psession)
1643{ 1644{
1644 int err = -EINVAL; 1645 int err = -EINVAL;
1645 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 1646 struct perf_session *session = perf_session__new(input_name, O_RDONLY,
1646 0, false, &event_ops); 1647 0, false, &perf_sched);
1647 if (session == NULL) 1648 if (session == NULL)
1648 die("No Memory"); 1649 die("No Memory");
1649 1650
1650 if (perf_session__has_traces(session, "record -R")) { 1651 if (perf_session__has_traces(session, "record -R")) {
1651 err = perf_session__process_events(session, &event_ops); 1652 err = perf_session__process_events(session, &perf_sched);
1652 if (err) 1653 if (err)
1653 die("Failed to process events, error %d", err); 1654 die("Failed to process events, error %d", err);
1654 1655
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 31a8d14e5fb7..5f8afc65d5f3 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -7,6 +7,7 @@
7#include "util/header.h" 7#include "util/header.h"
8#include "util/parse-options.h" 8#include "util/parse-options.h"
9#include "util/session.h" 9#include "util/session.h"
10#include "util/tool.h"
10#include "util/symbol.h" 11#include "util/symbol.h"
11#include "util/thread.h" 12#include "util/thread.h"
12#include "util/trace-event.h" 13#include "util/trace-event.h"
@@ -434,7 +435,7 @@ static int cleanup_scripting(void)
434 435
435static char const *input_name = "perf.data"; 436static char const *input_name = "perf.data";
436 437
437static int process_sample_event(struct perf_event_ops *ops __used, 438static int process_sample_event(struct perf_tool *tool __used,
438 union perf_event *event, 439 union perf_event *event,
439 struct perf_sample *sample, 440 struct perf_sample *sample,
440 struct perf_evsel *evsel, 441 struct perf_evsel *evsel,
@@ -468,7 +469,7 @@ static int process_sample_event(struct perf_event_ops *ops __used,
468 return 0; 469 return 0;
469} 470}
470 471
471static struct perf_event_ops event_ops = { 472static struct perf_tool perf_script = {
472 .sample = process_sample_event, 473 .sample = process_sample_event,
473 .mmap = perf_event__process_mmap, 474 .mmap = perf_event__process_mmap,
474 .comm = perf_event__process_comm, 475 .comm = perf_event__process_comm,
@@ -495,7 +496,7 @@ static int __cmd_script(struct perf_session *session)
495 496
496 signal(SIGINT, sig_handler); 497 signal(SIGINT, sig_handler);
497 498
498 ret = perf_session__process_events(session, &event_ops); 499 ret = perf_session__process_events(session, &perf_script);
499 500
500 if (debug_mode) 501 if (debug_mode)
501 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); 502 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
@@ -1262,7 +1263,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
1262 if (!script_name) 1263 if (!script_name)
1263 setup_pager(); 1264 setup_pager();
1264 1265
1265 session = perf_session__new(input_name, O_RDONLY, 0, false, &event_ops); 1266 session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_script);
1266 if (session == NULL) 1267 if (session == NULL)
1267 return -ENOMEM; 1268 return -ENOMEM;
1268 1269
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 8e6539625bc1..135376a37f97 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -32,6 +32,7 @@
32#include "util/event.h" 32#include "util/event.h"
33#include "util/session.h" 33#include "util/session.h"
34#include "util/svghelper.h" 34#include "util/svghelper.h"
35#include "util/tool.h"
35 36
36#define SUPPORT_OLD_POWER_EVENTS 1 37#define SUPPORT_OLD_POWER_EVENTS 1
37#define PWR_EVENT_EXIT -1 38#define PWR_EVENT_EXIT -1
@@ -274,7 +275,7 @@ static int cpus_cstate_state[MAX_CPUS];
274static u64 cpus_pstate_start_times[MAX_CPUS]; 275static u64 cpus_pstate_start_times[MAX_CPUS];
275static u64 cpus_pstate_state[MAX_CPUS]; 276static u64 cpus_pstate_state[MAX_CPUS];
276 277
277static int process_comm_event(struct perf_event_ops *ops __used, 278static int process_comm_event(struct perf_tool *tool __used,
278 union perf_event *event, 279 union perf_event *event,
279 struct perf_sample *sample __used, 280 struct perf_sample *sample __used,
280 struct machine *machine __used) 281 struct machine *machine __used)
@@ -283,7 +284,7 @@ static int process_comm_event(struct perf_event_ops *ops __used,
283 return 0; 284 return 0;
284} 285}
285 286
286static int process_fork_event(struct perf_event_ops *ops __used, 287static int process_fork_event(struct perf_tool *tool __used,
287 union perf_event *event, 288 union perf_event *event,
288 struct perf_sample *sample __used, 289 struct perf_sample *sample __used,
289 struct machine *machine __used) 290 struct machine *machine __used)
@@ -292,7 +293,7 @@ static int process_fork_event(struct perf_event_ops *ops __used,
292 return 0; 293 return 0;
293} 294}
294 295
295static int process_exit_event(struct perf_event_ops *ops __used, 296static int process_exit_event(struct perf_tool *tool __used,
296 union perf_event *event, 297 union perf_event *event,
297 struct perf_sample *sample __used, 298 struct perf_sample *sample __used,
298 struct machine *machine __used) 299 struct machine *machine __used)
@@ -490,7 +491,7 @@ static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te)
490} 491}
491 492
492 493
493static int process_sample_event(struct perf_event_ops *ops __used, 494static int process_sample_event(struct perf_tool *tool __used,
494 union perf_event *event __used, 495 union perf_event *event __used,
495 struct perf_sample *sample, 496 struct perf_sample *sample,
496 struct perf_evsel *evsel, 497 struct perf_evsel *evsel,
@@ -979,7 +980,7 @@ static void write_svg_file(const char *filename)
979 svg_close(); 980 svg_close();
980} 981}
981 982
982static struct perf_event_ops event_ops = { 983static struct perf_tool perf_timechart = {
983 .comm = process_comm_event, 984 .comm = process_comm_event,
984 .fork = process_fork_event, 985 .fork = process_fork_event,
985 .exit = process_exit_event, 986 .exit = process_exit_event,
@@ -990,7 +991,7 @@ static struct perf_event_ops event_ops = {
990static int __cmd_timechart(void) 991static int __cmd_timechart(void)
991{ 992{
992 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 993 struct perf_session *session = perf_session__new(input_name, O_RDONLY,
993 0, false, &event_ops); 994 0, false, &perf_timechart);
994 int ret = -EINVAL; 995 int ret = -EINVAL;
995 996
996 if (session == NULL) 997 if (session == NULL)
@@ -999,7 +1000,7 @@ static int __cmd_timechart(void)
999 if (!perf_session__has_traces(session, "timechart record")) 1000 if (!perf_session__has_traces(session, "timechart record"))
1000 goto out_delete; 1001 goto out_delete;
1001 1002
1002 ret = perf_session__process_events(session, &event_ops); 1003 ret = perf_session__process_events(session, &perf_timechart);
1003 if (ret) 1004 if (ret)
1004 goto out_delete; 1005 goto out_delete;
1005 1006
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 31d497368ccf..42a7d96b4dbe 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -826,7 +826,7 @@ static void perf_session__mmap_read_idx(struct perf_session *self, int idx)
826 perf_event__process_sample(event, evsel, &sample, machine); 826 perf_event__process_sample(event, evsel, &sample, machine);
827 else if (event->header.type < PERF_RECORD_MAX) { 827 else if (event->header.type < PERF_RECORD_MAX) {
828 hists__inc_nr_events(&evsel->hists, event->header.type); 828 hists__inc_nr_events(&evsel->hists, event->header.type);
829 perf_event__process(&top.ops, event, &sample, machine); 829 perf_event__process(&top.tool, event, &sample, machine);
830 } else 830 } else
831 ++self->hists.stats.nr_unknown_events; 831 ++self->hists.stats.nr_unknown_events;
832 } 832 }
@@ -968,11 +968,11 @@ static int __cmd_top(void)
968 goto out_delete; 968 goto out_delete;
969 969
970 if (top.target_tid != -1) 970 if (top.target_tid != -1)
971 perf_event__synthesize_thread_map(&top.ops, top.evlist->threads, 971 perf_event__synthesize_thread_map(&top.tool, top.evlist->threads,
972 perf_event__process, 972 perf_event__process,
973 &top.session->host_machine); 973 &top.session->host_machine);
974 else 974 else
975 perf_event__synthesize_threads(&top.ops, perf_event__process, 975 perf_event__synthesize_threads(&top.tool, perf_event__process,
976 &top.session->host_machine); 976 &top.session->host_machine);
977 start_counters(top.evlist); 977 start_counters(top.evlist);
978 top.session->evlist = top.evlist; 978 top.session->evlist = top.evlist;
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 2f84c4802aca..dff9c7a725f4 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -14,8 +14,9 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include "debug.h" 15#include "debug.h"
16#include "session.h" 16#include "session.h"
17#include "tool.h"
17 18
18static int build_id__mark_dso_hit(struct perf_event_ops *ops __used, 19static int build_id__mark_dso_hit(struct perf_tool *tool __used,
19 union perf_event *event, 20 union perf_event *event,
20 struct perf_sample *sample __used, 21 struct perf_sample *sample __used,
21 struct perf_evsel *evsel __used, 22 struct perf_evsel *evsel __used,
@@ -40,7 +41,7 @@ static int build_id__mark_dso_hit(struct perf_event_ops *ops __used,
40 return 0; 41 return 0;
41} 42}
42 43
43static int perf_event__exit_del_thread(struct perf_event_ops *ops __used, 44static int perf_event__exit_del_thread(struct perf_tool *tool __used,
44 union perf_event *event, 45 union perf_event *event,
45 struct perf_sample *sample __used, 46 struct perf_sample *sample __used,
46 struct machine *machine) 47 struct machine *machine)
@@ -59,7 +60,7 @@ static int perf_event__exit_del_thread(struct perf_event_ops *ops __used,
59 return 0; 60 return 0;
60} 61}
61 62
62struct perf_event_ops build_id__mark_dso_hit_ops = { 63struct perf_tool build_id__mark_dso_hit_ops = {
63 .sample = build_id__mark_dso_hit, 64 .sample = build_id__mark_dso_hit,
64 .mmap = perf_event__process_mmap, 65 .mmap = perf_event__process_mmap,
65 .fork = perf_event__process_task, 66 .fork = perf_event__process_task,
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 5dafb00eaa06..a993ba87d996 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -3,7 +3,7 @@
3 3
4#include "session.h" 4#include "session.h"
5 5
6extern struct perf_event_ops build_id__mark_dso_hit_ops; 6extern struct perf_tool build_id__mark_dso_hit_ops;
7 7
8char *dso__build_id_filename(struct dso *self, char *bf, size_t size); 8char *dso__build_id_filename(struct dso *self, char *bf, size_t size);
9 9
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 0cdc811c48e2..0ebbe7641335 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -43,7 +43,7 @@ static struct perf_sample synth_sample = {
43 .period = 1, 43 .period = 1,
44}; 44};
45 45
46static pid_t perf_event__synthesize_comm(struct perf_event_ops *ops, 46static pid_t perf_event__synthesize_comm(struct perf_tool *tool,
47 union perf_event *event, pid_t pid, 47 union perf_event *event, pid_t pid,
48 int full, perf_event__handler_t process, 48 int full, perf_event__handler_t process,
49 struct machine *machine) 49 struct machine *machine)
@@ -99,7 +99,7 @@ out_race:
99 if (!full) { 99 if (!full) {
100 event->comm.tid = pid; 100 event->comm.tid = pid;
101 101
102 process(ops, event, &synth_sample, machine); 102 process(tool, event, &synth_sample, machine);
103 goto out; 103 goto out;
104 } 104 }
105 105
@@ -117,7 +117,7 @@ out_race:
117 117
118 event->comm.tid = pid; 118 event->comm.tid = pid;
119 119
120 process(ops, event, &synth_sample, machine); 120 process(tool, event, &synth_sample, machine);
121 } 121 }
122 122
123 closedir(tasks); 123 closedir(tasks);
@@ -127,7 +127,7 @@ out:
127 return tgid; 127 return tgid;
128} 128}
129 129
130static int perf_event__synthesize_mmap_events(struct perf_event_ops *ops, 130static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
131 union perf_event *event, 131 union perf_event *event,
132 pid_t pid, pid_t tgid, 132 pid_t pid, pid_t tgid,
133 perf_event__handler_t process, 133 perf_event__handler_t process,
@@ -199,7 +199,7 @@ static int perf_event__synthesize_mmap_events(struct perf_event_ops *ops,
199 event->mmap.pid = tgid; 199 event->mmap.pid = tgid;
200 event->mmap.tid = pid; 200 event->mmap.tid = pid;
201 201
202 process(ops, event, &synth_sample, machine); 202 process(tool, event, &synth_sample, machine);
203 } 203 }
204 } 204 }
205 205
@@ -207,7 +207,7 @@ static int perf_event__synthesize_mmap_events(struct perf_event_ops *ops,
207 return 0; 207 return 0;
208} 208}
209 209
210int perf_event__synthesize_modules(struct perf_event_ops *ops, 210int perf_event__synthesize_modules(struct perf_tool *tool,
211 perf_event__handler_t process, 211 perf_event__handler_t process,
212 struct machine *machine) 212 struct machine *machine)
213{ 213{
@@ -252,7 +252,7 @@ int perf_event__synthesize_modules(struct perf_event_ops *ops,
252 252
253 memcpy(event->mmap.filename, pos->dso->long_name, 253 memcpy(event->mmap.filename, pos->dso->long_name,
254 pos->dso->long_name_len + 1); 254 pos->dso->long_name_len + 1);
255 process(ops, event, &synth_sample, machine); 255 process(tool, event, &synth_sample, machine);
256 } 256 }
257 257
258 free(event); 258 free(event);
@@ -262,18 +262,18 @@ int perf_event__synthesize_modules(struct perf_event_ops *ops,
262static int __event__synthesize_thread(union perf_event *comm_event, 262static int __event__synthesize_thread(union perf_event *comm_event,
263 union perf_event *mmap_event, 263 union perf_event *mmap_event,
264 pid_t pid, perf_event__handler_t process, 264 pid_t pid, perf_event__handler_t process,
265 struct perf_event_ops *ops, 265 struct perf_tool *tool,
266 struct machine *machine) 266 struct machine *machine)
267{ 267{
268 pid_t tgid = perf_event__synthesize_comm(ops, comm_event, pid, 1, 268 pid_t tgid = perf_event__synthesize_comm(tool, comm_event, pid, 1,
269 process, machine); 269 process, machine);
270 if (tgid == -1) 270 if (tgid == -1)
271 return -1; 271 return -1;
272 return perf_event__synthesize_mmap_events(ops, mmap_event, pid, tgid, 272 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
273 process, machine); 273 process, machine);
274} 274}
275 275
276int perf_event__synthesize_thread_map(struct perf_event_ops *ops, 276int perf_event__synthesize_thread_map(struct perf_tool *tool,
277 struct thread_map *threads, 277 struct thread_map *threads,
278 perf_event__handler_t process, 278 perf_event__handler_t process,
279 struct machine *machine) 279 struct machine *machine)
@@ -293,7 +293,7 @@ int perf_event__synthesize_thread_map(struct perf_event_ops *ops,
293 for (thread = 0; thread < threads->nr; ++thread) { 293 for (thread = 0; thread < threads->nr; ++thread) {
294 if (__event__synthesize_thread(comm_event, mmap_event, 294 if (__event__synthesize_thread(comm_event, mmap_event,
295 threads->map[thread], 295 threads->map[thread],
296 process, ops, machine)) { 296 process, tool, machine)) {
297 err = -1; 297 err = -1;
298 break; 298 break;
299 } 299 }
@@ -305,7 +305,7 @@ out:
305 return err; 305 return err;
306} 306}
307 307
308int perf_event__synthesize_threads(struct perf_event_ops *ops, 308int perf_event__synthesize_threads(struct perf_tool *tool,
309 perf_event__handler_t process, 309 perf_event__handler_t process,
310 struct machine *machine) 310 struct machine *machine)
311{ 311{
@@ -334,7 +334,7 @@ int perf_event__synthesize_threads(struct perf_event_ops *ops,
334 continue; 334 continue;
335 335
336 __event__synthesize_thread(comm_event, mmap_event, pid, 336 __event__synthesize_thread(comm_event, mmap_event, pid,
337 process, ops, machine); 337 process, tool, machine);
338 } 338 }
339 339
340 closedir(proc); 340 closedir(proc);
@@ -369,7 +369,7 @@ static int find_symbol_cb(void *arg, const char *name, char type,
369 return 1; 369 return 1;
370} 370}
371 371
372int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops, 372int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
373 perf_event__handler_t process, 373 perf_event__handler_t process,
374 struct machine *machine, 374 struct machine *machine,
375 const char *symbol_name) 375 const char *symbol_name)
@@ -427,13 +427,13 @@ int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops,
427 event->mmap.len = map->end - event->mmap.start; 427 event->mmap.len = map->end - event->mmap.start;
428 event->mmap.pid = machine->pid; 428 event->mmap.pid = machine->pid;
429 429
430 err = process(ops, event, &synth_sample, machine); 430 err = process(tool, event, &synth_sample, machine);
431 free(event); 431 free(event);
432 432
433 return err; 433 return err;
434} 434}
435 435
436int perf_event__process_comm(struct perf_event_ops *ops __used, 436int perf_event__process_comm(struct perf_tool *tool __used,
437 union perf_event *event, 437 union perf_event *event,
438 struct perf_sample *sample __used, 438 struct perf_sample *sample __used,
439 struct machine *machine) 439 struct machine *machine)
@@ -450,7 +450,7 @@ int perf_event__process_comm(struct perf_event_ops *ops __used,
450 return 0; 450 return 0;
451} 451}
452 452
453int perf_event__process_lost(struct perf_event_ops *ops __used, 453int perf_event__process_lost(struct perf_tool *tool __used,
454 union perf_event *event, 454 union perf_event *event,
455 struct perf_sample *sample __used, 455 struct perf_sample *sample __used,
456 struct machine *machine __used) 456 struct machine *machine __used)
@@ -473,7 +473,7 @@ static void perf_event__set_kernel_mmap_len(union perf_event *event,
473 maps[MAP__FUNCTION]->end = ~0ULL; 473 maps[MAP__FUNCTION]->end = ~0ULL;
474} 474}
475 475
476static int perf_event__process_kernel_mmap(struct perf_event_ops *ops __used, 476static int perf_event__process_kernel_mmap(struct perf_tool *tool __used,
477 union perf_event *event, 477 union perf_event *event,
478 struct machine *machine) 478 struct machine *machine)
479{ 479{
@@ -566,7 +566,7 @@ out_problem:
566 return -1; 566 return -1;
567} 567}
568 568
569int perf_event__process_mmap(struct perf_event_ops *ops, 569int perf_event__process_mmap(struct perf_tool *tool,
570 union perf_event *event, 570 union perf_event *event,
571 struct perf_sample *sample __used, 571 struct perf_sample *sample __used,
572 struct machine *machine) 572 struct machine *machine)
@@ -582,7 +582,7 @@ int perf_event__process_mmap(struct perf_event_ops *ops,
582 582
583 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 583 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
584 cpumode == PERF_RECORD_MISC_KERNEL) { 584 cpumode == PERF_RECORD_MISC_KERNEL) {
585 ret = perf_event__process_kernel_mmap(ops, event, machine); 585 ret = perf_event__process_kernel_mmap(tool, event, machine);
586 if (ret < 0) 586 if (ret < 0)
587 goto out_problem; 587 goto out_problem;
588 return 0; 588 return 0;
@@ -606,7 +606,7 @@ out_problem:
606 return 0; 606 return 0;
607} 607}
608 608
609int perf_event__process_task(struct perf_event_ops *ops __used, 609int perf_event__process_task(struct perf_tool *tool __used,
610 union perf_event *event, 610 union perf_event *event,
611 struct perf_sample *sample __used, 611 struct perf_sample *sample __used,
612 struct machine *machine) 612 struct machine *machine)
@@ -631,22 +631,22 @@ int perf_event__process_task(struct perf_event_ops *ops __used,
631 return 0; 631 return 0;
632} 632}
633 633
634int perf_event__process(struct perf_event_ops *ops, union perf_event *event, 634int perf_event__process(struct perf_tool *tool, union perf_event *event,
635 struct perf_sample *sample, struct machine *machine) 635 struct perf_sample *sample, struct machine *machine)
636{ 636{
637 switch (event->header.type) { 637 switch (event->header.type) {
638 case PERF_RECORD_COMM: 638 case PERF_RECORD_COMM:
639 perf_event__process_comm(ops, event, sample, machine); 639 perf_event__process_comm(tool, event, sample, machine);
640 break; 640 break;
641 case PERF_RECORD_MMAP: 641 case PERF_RECORD_MMAP:
642 perf_event__process_mmap(ops, event, sample, machine); 642 perf_event__process_mmap(tool, event, sample, machine);
643 break; 643 break;
644 case PERF_RECORD_FORK: 644 case PERF_RECORD_FORK:
645 case PERF_RECORD_EXIT: 645 case PERF_RECORD_EXIT:
646 perf_event__process_task(ops, event, sample, machine); 646 perf_event__process_task(tool, event, sample, machine);
647 break; 647 break;
648 case PERF_RECORD_LOST: 648 case PERF_RECORD_LOST:
649 perf_event__process_lost(ops, event, sample, machine); 649 perf_event__process_lost(tool, event, sample, machine);
650 default: 650 default:
651 break; 651 break;
652 } 652 }
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1564877e8703..d8499e7cf641 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -141,47 +141,47 @@ union perf_event {
141 141
142void perf_event__print_totals(void); 142void perf_event__print_totals(void);
143 143
144struct perf_event_ops; 144struct perf_tool;
145struct thread_map; 145struct thread_map;
146 146
147typedef int (*perf_event__handler_t)(struct perf_event_ops *ops, 147typedef int (*perf_event__handler_t)(struct perf_tool *tool,
148 union perf_event *event, 148 union perf_event *event,
149 struct perf_sample *sample, 149 struct perf_sample *sample,
150 struct machine *machine); 150 struct machine *machine);
151 151
152int perf_event__synthesize_thread_map(struct perf_event_ops *ops, 152int perf_event__synthesize_thread_map(struct perf_tool *tool,
153 struct thread_map *threads, 153 struct thread_map *threads,
154 perf_event__handler_t process, 154 perf_event__handler_t process,
155 struct machine *machine); 155 struct machine *machine);
156int perf_event__synthesize_threads(struct perf_event_ops *ops, 156int perf_event__synthesize_threads(struct perf_tool *tool,
157 perf_event__handler_t process, 157 perf_event__handler_t process,
158 struct machine *machine); 158 struct machine *machine);
159int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops, 159int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
160 perf_event__handler_t process, 160 perf_event__handler_t process,
161 struct machine *machine, 161 struct machine *machine,
162 const char *symbol_name); 162 const char *symbol_name);
163 163
164int perf_event__synthesize_modules(struct perf_event_ops *ops, 164int perf_event__synthesize_modules(struct perf_tool *tool,
165 perf_event__handler_t process, 165 perf_event__handler_t process,
166 struct machine *machine); 166 struct machine *machine);
167 167
168int perf_event__process_comm(struct perf_event_ops *ops, 168int perf_event__process_comm(struct perf_tool *tool,
169 union perf_event *event, 169 union perf_event *event,
170 struct perf_sample *sample, 170 struct perf_sample *sample,
171 struct machine *machine); 171 struct machine *machine);
172int perf_event__process_lost(struct perf_event_ops *ops, 172int perf_event__process_lost(struct perf_tool *tool,
173 union perf_event *event, 173 union perf_event *event,
174 struct perf_sample *sample, 174 struct perf_sample *sample,
175 struct machine *machine); 175 struct machine *machine);
176int perf_event__process_mmap(struct perf_event_ops *ops, 176int perf_event__process_mmap(struct perf_tool *tool,
177 union perf_event *event, 177 union perf_event *event,
178 struct perf_sample *sample, 178 struct perf_sample *sample,
179 struct machine *machine); 179 struct machine *machine);
180int perf_event__process_task(struct perf_event_ops *ops, 180int perf_event__process_task(struct perf_tool *tool,
181 union perf_event *event, 181 union perf_event *event,
182 struct perf_sample *sample, 182 struct perf_sample *sample,
183 struct machine *machine); 183 struct machine *machine);
184int perf_event__process(struct perf_event_ops *ops, 184int perf_event__process(struct perf_tool *tool,
185 union perf_event *event, 185 union perf_event *event,
186 struct perf_sample *sample, 186 struct perf_sample *sample,
187 struct machine *machine); 187 struct machine *machine);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index db280d6ca898..9272f3a20cac 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2070,7 +2070,7 @@ out_delete_evlist:
2070 return -ENOMEM; 2070 return -ENOMEM;
2071} 2071}
2072 2072
2073int perf_event__synthesize_attr(struct perf_event_ops *ops, 2073int perf_event__synthesize_attr(struct perf_tool *tool,
2074 struct perf_event_attr *attr, u16 ids, u64 *id, 2074 struct perf_event_attr *attr, u16 ids, u64 *id,
2075 perf_event__handler_t process) 2075 perf_event__handler_t process)
2076{ 2076{
@@ -2094,14 +2094,14 @@ int perf_event__synthesize_attr(struct perf_event_ops *ops,
2094 ev->attr.header.type = PERF_RECORD_HEADER_ATTR; 2094 ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
2095 ev->attr.header.size = size; 2095 ev->attr.header.size = size;
2096 2096
2097 err = process(ops, ev, NULL, NULL); 2097 err = process(tool, ev, NULL, NULL);
2098 2098
2099 free(ev); 2099 free(ev);
2100 2100
2101 return err; 2101 return err;
2102} 2102}
2103 2103
2104int perf_event__synthesize_attrs(struct perf_event_ops *ops, 2104int perf_event__synthesize_attrs(struct perf_tool *tool,
2105 struct perf_session *session, 2105 struct perf_session *session,
2106 perf_event__handler_t process) 2106 perf_event__handler_t process)
2107{ 2107{
@@ -2109,7 +2109,7 @@ int perf_event__synthesize_attrs(struct perf_event_ops *ops,
2109 int err = 0; 2109 int err = 0;
2110 2110
2111 list_for_each_entry(attr, &session->evlist->entries, node) { 2111 list_for_each_entry(attr, &session->evlist->entries, node) {
2112 err = perf_event__synthesize_attr(ops, &attr->attr, attr->ids, 2112 err = perf_event__synthesize_attr(tool, &attr->attr, attr->ids,
2113 attr->id, process); 2113 attr->id, process);
2114 if (err) { 2114 if (err) {
2115 pr_debug("failed to create perf header attribute\n"); 2115 pr_debug("failed to create perf header attribute\n");
@@ -2157,7 +2157,7 @@ int perf_event__process_attr(union perf_event *event,
2157 return 0; 2157 return 0;
2158} 2158}
2159 2159
2160int perf_event__synthesize_event_type(struct perf_event_ops *ops, 2160int perf_event__synthesize_event_type(struct perf_tool *tool,
2161 u64 event_id, char *name, 2161 u64 event_id, char *name,
2162 perf_event__handler_t process, 2162 perf_event__handler_t process,
2163 struct machine *machine) 2163 struct machine *machine)
@@ -2178,12 +2178,12 @@ int perf_event__synthesize_event_type(struct perf_event_ops *ops,
2178 ev.event_type.header.size = sizeof(ev.event_type) - 2178 ev.event_type.header.size = sizeof(ev.event_type) -
2179 (sizeof(ev.event_type.event_type.name) - size); 2179 (sizeof(ev.event_type.event_type.name) - size);
2180 2180
2181 err = process(ops, &ev, NULL, machine); 2181 err = process(tool, &ev, NULL, machine);
2182 2182
2183 return err; 2183 return err;
2184} 2184}
2185 2185
2186int perf_event__synthesize_event_types(struct perf_event_ops *ops, 2186int perf_event__synthesize_event_types(struct perf_tool *tool,
2187 perf_event__handler_t process, 2187 perf_event__handler_t process,
2188 struct machine *machine) 2188 struct machine *machine)
2189{ 2189{
@@ -2193,7 +2193,7 @@ int perf_event__synthesize_event_types(struct perf_event_ops *ops,
2193 for (i = 0; i < event_count; i++) { 2193 for (i = 0; i < event_count; i++) {
2194 type = &events[i]; 2194 type = &events[i];
2195 2195
2196 err = perf_event__synthesize_event_type(ops, type->event_id, 2196 err = perf_event__synthesize_event_type(tool, type->event_id,
2197 type->name, process, 2197 type->name, process,
2198 machine); 2198 machine);
2199 if (err) { 2199 if (err) {
@@ -2205,7 +2205,7 @@ int perf_event__synthesize_event_types(struct perf_event_ops *ops,
2205 return err; 2205 return err;
2206} 2206}
2207 2207
2208int perf_event__process_event_type(struct perf_event_ops *ops __unused, 2208int perf_event__process_event_type(struct perf_tool *tool __unused,
2209 union perf_event *event) 2209 union perf_event *event)
2210{ 2210{
2211 if (perf_header__push_event(event->event_type.event_type.event_id, 2211 if (perf_header__push_event(event->event_type.event_type.event_id,
@@ -2215,7 +2215,7 @@ int perf_event__process_event_type(struct perf_event_ops *ops __unused,
2215 return 0; 2215 return 0;
2216} 2216}
2217 2217
2218int perf_event__synthesize_tracing_data(struct perf_event_ops *ops, int fd, 2218int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd,
2219 struct perf_evlist *evlist, 2219 struct perf_evlist *evlist,
2220 perf_event__handler_t process) 2220 perf_event__handler_t process)
2221{ 2221{
@@ -2248,7 +2248,7 @@ int perf_event__synthesize_tracing_data(struct perf_event_ops *ops, int fd,
2248 ev.tracing_data.header.size = sizeof(ev.tracing_data); 2248 ev.tracing_data.header.size = sizeof(ev.tracing_data);
2249 ev.tracing_data.size = aligned_size; 2249 ev.tracing_data.size = aligned_size;
2250 2250
2251 process(ops, &ev, NULL, NULL); 2251 process(tool, &ev, NULL, NULL);
2252 2252
2253 /* 2253 /*
2254 * The put function will copy all the tracing data 2254 * The put function will copy all the tracing data
@@ -2290,7 +2290,7 @@ int perf_event__process_tracing_data(union perf_event *event,
2290 return size_read + padding; 2290 return size_read + padding;
2291} 2291}
2292 2292
2293int perf_event__synthesize_build_id(struct perf_event_ops *ops, 2293int perf_event__synthesize_build_id(struct perf_tool *tool,
2294 struct dso *pos, u16 misc, 2294 struct dso *pos, u16 misc,
2295 perf_event__handler_t process, 2295 perf_event__handler_t process,
2296 struct machine *machine) 2296 struct machine *machine)
@@ -2313,12 +2313,12 @@ int perf_event__synthesize_build_id(struct perf_event_ops *ops,
2313 ev.build_id.header.size = sizeof(ev.build_id) + len; 2313 ev.build_id.header.size = sizeof(ev.build_id) + len;
2314 memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); 2314 memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
2315 2315
2316 err = process(ops, &ev, NULL, machine); 2316 err = process(tool, &ev, NULL, machine);
2317 2317
2318 return err; 2318 return err;
2319} 2319}
2320 2320
2321int perf_event__process_build_id(struct perf_event_ops *ops __used, 2321int perf_event__process_build_id(struct perf_tool *tool __used,
2322 union perf_event *event, 2322 union perf_event *event,
2323 struct perf_session *session) 2323 struct perf_session *session)
2324{ 2324{
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index a604962fc431..09365b32098e 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -97,35 +97,35 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
97 const char *name, bool is_kallsyms); 97 const char *name, bool is_kallsyms);
98int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir); 98int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
99 99
100int perf_event__synthesize_attr(struct perf_event_ops *ops, 100int perf_event__synthesize_attr(struct perf_tool *tool,
101 struct perf_event_attr *attr, u16 ids, u64 *id, 101 struct perf_event_attr *attr, u16 ids, u64 *id,
102 perf_event__handler_t process); 102 perf_event__handler_t process);
103int perf_event__synthesize_attrs(struct perf_event_ops *ops, 103int perf_event__synthesize_attrs(struct perf_tool *tool,
104 struct perf_session *session, 104 struct perf_session *session,
105 perf_event__handler_t process); 105 perf_event__handler_t process);
106int perf_event__process_attr(union perf_event *event, struct perf_evlist **pevlist); 106int perf_event__process_attr(union perf_event *event, struct perf_evlist **pevlist);
107 107
108int perf_event__synthesize_event_type(struct perf_event_ops *ops, 108int perf_event__synthesize_event_type(struct perf_tool *tool,
109 u64 event_id, char *name, 109 u64 event_id, char *name,
110 perf_event__handler_t process, 110 perf_event__handler_t process,
111 struct machine *machine); 111 struct machine *machine);
112int perf_event__synthesize_event_types(struct perf_event_ops *ops, 112int perf_event__synthesize_event_types(struct perf_tool *tool,
113 perf_event__handler_t process, 113 perf_event__handler_t process,
114 struct machine *machine); 114 struct machine *machine);
115int perf_event__process_event_type(struct perf_event_ops *ops, 115int perf_event__process_event_type(struct perf_tool *tool,
116 union perf_event *event); 116 union perf_event *event);
117 117
118int perf_event__synthesize_tracing_data(struct perf_event_ops *ops, 118int perf_event__synthesize_tracing_data(struct perf_tool *tool,
119 int fd, struct perf_evlist *evlist, 119 int fd, struct perf_evlist *evlist,
120 perf_event__handler_t process); 120 perf_event__handler_t process);
121int perf_event__process_tracing_data(union perf_event *event, 121int perf_event__process_tracing_data(union perf_event *event,
122 struct perf_session *session); 122 struct perf_session *session);
123 123
124int perf_event__synthesize_build_id(struct perf_event_ops *ops, 124int perf_event__synthesize_build_id(struct perf_tool *tool,
125 struct dso *pos, u16 misc, 125 struct dso *pos, u16 misc,
126 perf_event__handler_t process, 126 perf_event__handler_t process,
127 struct machine *machine); 127 struct machine *machine);
128int perf_event__process_build_id(struct perf_event_ops *ops, 128int perf_event__process_build_id(struct perf_tool *tool,
129 union perf_event *event, 129 union perf_event *event,
130 struct perf_session *session); 130 struct perf_session *session);
131 131
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index be33606386bf..7d159088c4ac 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -10,6 +10,7 @@
10#include "evlist.h" 10#include "evlist.h"
11#include "evsel.h" 11#include "evsel.h"
12#include "session.h" 12#include "session.h"
13#include "tool.h"
13#include "sort.h" 14#include "sort.h"
14#include "util.h" 15#include "util.h"
15#include "cpumap.h" 16#include "cpumap.h"
@@ -104,7 +105,7 @@ static void perf_session__destroy_kernel_maps(struct perf_session *self)
104 105
105struct perf_session *perf_session__new(const char *filename, int mode, 106struct perf_session *perf_session__new(const char *filename, int mode,
106 bool force, bool repipe, 107 bool force, bool repipe,
107 struct perf_event_ops *ops) 108 struct perf_tool *tool)
108{ 109{
109 size_t len = filename ? strlen(filename) + 1 : 0; 110 size_t len = filename ? strlen(filename) + 1 : 0;
110 struct perf_session *self = zalloc(sizeof(*self) + len); 111 struct perf_session *self = zalloc(sizeof(*self) + len);
@@ -142,10 +143,10 @@ struct perf_session *perf_session__new(const char *filename, int mode,
142 goto out_delete; 143 goto out_delete;
143 } 144 }
144 145
145 if (ops && ops->ordering_requires_timestamps && 146 if (tool && tool->ordering_requires_timestamps &&
146 ops->ordered_samples && !self->sample_id_all) { 147 tool->ordered_samples && !self->sample_id_all) {
147 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); 148 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
148 ops->ordered_samples = false; 149 tool->ordered_samples = false;
149 } 150 }
150 151
151out: 152out:
@@ -285,7 +286,7 @@ static int process_event_synth_attr_stub(union perf_event *event __used,
285 return 0; 286 return 0;
286} 287}
287 288
288static int process_event_sample_stub(struct perf_event_ops *ops __used, 289static int process_event_sample_stub(struct perf_tool *tool __used,
289 union perf_event *event __used, 290 union perf_event *event __used,
290 struct perf_sample *sample __used, 291 struct perf_sample *sample __used,
291 struct perf_evsel *evsel __used, 292 struct perf_evsel *evsel __used,
@@ -295,7 +296,7 @@ static int process_event_sample_stub(struct perf_event_ops *ops __used,
295 return 0; 296 return 0;
296} 297}
297 298
298static int process_event_stub(struct perf_event_ops *ops __used, 299static int process_event_stub(struct perf_tool *tool __used,
299 union perf_event *event __used, 300 union perf_event *event __used,
300 struct perf_sample *sample __used, 301 struct perf_sample *sample __used,
301 struct machine *machine __used) 302 struct machine *machine __used)
@@ -304,7 +305,7 @@ static int process_event_stub(struct perf_event_ops *ops __used,
304 return 0; 305 return 0;
305} 306}
306 307
307static int process_finished_round_stub(struct perf_event_ops *ops __used, 308static int process_finished_round_stub(struct perf_tool *tool __used,
308 union perf_event *event __used, 309 union perf_event *event __used,
309 struct perf_session *perf_session __used) 310 struct perf_session *perf_session __used)
310{ 311{
@@ -312,50 +313,50 @@ static int process_finished_round_stub(struct perf_event_ops *ops __used,
312 return 0; 313 return 0;
313} 314}
314 315
315static int process_event_type_stub(struct perf_event_ops *ops __used, 316static int process_event_type_stub(struct perf_tool *tool __used,
316 union perf_event *event __used) 317 union perf_event *event __used)
317{ 318{
318 dump_printf(": unhandled!\n"); 319 dump_printf(": unhandled!\n");
319 return 0; 320 return 0;
320} 321}
321 322
322static int process_finished_round(struct perf_event_ops *ops, 323static int process_finished_round(struct perf_tool *tool,
323 union perf_event *event, 324 union perf_event *event,
324 struct perf_session *session); 325 struct perf_session *session);
325 326
326static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) 327static void perf_tool__fill_defaults(struct perf_tool *tool)
327{ 328{
328 if (handler->sample == NULL) 329 if (tool->sample == NULL)
329 handler->sample = process_event_sample_stub; 330 tool->sample = process_event_sample_stub;
330 if (handler->mmap == NULL) 331 if (tool->mmap == NULL)
331 handler->mmap = process_event_stub; 332 tool->mmap = process_event_stub;
332 if (handler->comm == NULL) 333 if (tool->comm == NULL)
333 handler->comm = process_event_stub; 334 tool->comm = process_event_stub;
334 if (handler->fork == NULL) 335 if (tool->fork == NULL)
335 handler->fork = process_event_stub; 336 tool->fork = process_event_stub;
336 if (handler->exit == NULL) 337 if (tool->exit == NULL)
337 handler->exit = process_event_stub; 338 tool->exit = process_event_stub;
338 if (handler->lost == NULL) 339 if (tool->lost == NULL)
339 handler->lost = perf_event__process_lost; 340 tool->lost = perf_event__process_lost;
340 if (handler->read == NULL) 341 if (tool->read == NULL)
341 handler->read = process_event_sample_stub; 342 tool->read = process_event_sample_stub;
342 if (handler->throttle == NULL) 343 if (tool->throttle == NULL)
343 handler->throttle = process_event_stub; 344 tool->throttle = process_event_stub;
344 if (handler->unthrottle == NULL) 345 if (tool->unthrottle == NULL)
345 handler->unthrottle = process_event_stub; 346 tool->unthrottle = process_event_stub;
346 if (handler->attr == NULL) 347 if (tool->attr == NULL)
347 handler->attr = process_event_synth_attr_stub; 348 tool->attr = process_event_synth_attr_stub;
348 if (handler->event_type == NULL) 349 if (tool->event_type == NULL)
349 handler->event_type = process_event_type_stub; 350 tool->event_type = process_event_type_stub;
350 if (handler->tracing_data == NULL) 351 if (tool->tracing_data == NULL)
351 handler->tracing_data = process_event_synth_tracing_data_stub; 352 tool->tracing_data = process_event_synth_tracing_data_stub;
352 if (handler->build_id == NULL) 353 if (tool->build_id == NULL)
353 handler->build_id = process_finished_round_stub; 354 tool->build_id = process_finished_round_stub;
354 if (handler->finished_round == NULL) { 355 if (tool->finished_round == NULL) {
355 if (handler->ordered_samples) 356 if (tool->ordered_samples)
356 handler->finished_round = process_finished_round; 357 tool->finished_round = process_finished_round;
357 else 358 else
358 handler->finished_round = process_finished_round_stub; 359 tool->finished_round = process_finished_round_stub;
359 } 360 }
360} 361}
361 362
@@ -487,11 +488,11 @@ static void perf_session_free_sample_buffers(struct perf_session *session)
487static int perf_session_deliver_event(struct perf_session *session, 488static int perf_session_deliver_event(struct perf_session *session,
488 union perf_event *event, 489 union perf_event *event,
489 struct perf_sample *sample, 490 struct perf_sample *sample,
490 struct perf_event_ops *ops, 491 struct perf_tool *tool,
491 u64 file_offset); 492 u64 file_offset);
492 493
493static void flush_sample_queue(struct perf_session *s, 494static void flush_sample_queue(struct perf_session *s,
494 struct perf_event_ops *ops) 495 struct perf_tool *tool)
495{ 496{
496 struct ordered_samples *os = &s->ordered_samples; 497 struct ordered_samples *os = &s->ordered_samples;
497 struct list_head *head = &os->samples; 498 struct list_head *head = &os->samples;
@@ -502,7 +503,7 @@ static void flush_sample_queue(struct perf_session *s,
502 unsigned idx = 0, progress_next = os->nr_samples / 16; 503 unsigned idx = 0, progress_next = os->nr_samples / 16;
503 int ret; 504 int ret;
504 505
505 if (!ops->ordered_samples || !limit) 506 if (!tool->ordered_samples || !limit)
506 return; 507 return;
507 508
508 list_for_each_entry_safe(iter, tmp, head, list) { 509 list_for_each_entry_safe(iter, tmp, head, list) {
@@ -513,7 +514,7 @@ static void flush_sample_queue(struct perf_session *s,
513 if (ret) 514 if (ret)
514 pr_err("Can't parse sample, err = %d\n", ret); 515 pr_err("Can't parse sample, err = %d\n", ret);
515 else 516 else
516 perf_session_deliver_event(s, iter->event, &sample, ops, 517 perf_session_deliver_event(s, iter->event, &sample, tool,
517 iter->file_offset); 518 iter->file_offset);
518 519
519 os->last_flush = iter->timestamp; 520 os->last_flush = iter->timestamp;
@@ -575,11 +576,11 @@ static void flush_sample_queue(struct perf_session *s,
575 * Flush every events below timestamp 7 576 * Flush every events below timestamp 7
576 * etc... 577 * etc...
577 */ 578 */
578static int process_finished_round(struct perf_event_ops *ops, 579static int process_finished_round(struct perf_tool *tool,
579 union perf_event *event __used, 580 union perf_event *event __used,
580 struct perf_session *session) 581 struct perf_session *session)
581{ 582{
582 flush_sample_queue(session, ops); 583 flush_sample_queue(session, tool);
583 session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; 584 session->ordered_samples.next_flush = session->ordered_samples.max_timestamp;
584 585
585 return 0; 586 return 0;
@@ -749,7 +750,7 @@ static struct machine *
749static int perf_session_deliver_event(struct perf_session *session, 750static int perf_session_deliver_event(struct perf_session *session,
750 union perf_event *event, 751 union perf_event *event,
751 struct perf_sample *sample, 752 struct perf_sample *sample,
752 struct perf_event_ops *ops, 753 struct perf_tool *tool,
753 u64 file_offset) 754 u64 file_offset)
754{ 755{
755 struct perf_evsel *evsel; 756 struct perf_evsel *evsel;
@@ -784,25 +785,25 @@ static int perf_session_deliver_event(struct perf_session *session,
784 ++session->hists.stats.nr_unknown_id; 785 ++session->hists.stats.nr_unknown_id;
785 return -1; 786 return -1;
786 } 787 }
787 return ops->sample(ops, event, sample, evsel, machine); 788 return tool->sample(tool, event, sample, evsel, machine);
788 case PERF_RECORD_MMAP: 789 case PERF_RECORD_MMAP:
789 return ops->mmap(ops, event, sample, machine); 790 return tool->mmap(tool, event, sample, machine);
790 case PERF_RECORD_COMM: 791 case PERF_RECORD_COMM:
791 return ops->comm(ops, event, sample, machine); 792 return tool->comm(tool, event, sample, machine);
792 case PERF_RECORD_FORK: 793 case PERF_RECORD_FORK:
793 return ops->fork(ops, event, sample, machine); 794 return tool->fork(tool, event, sample, machine);
794 case PERF_RECORD_EXIT: 795 case PERF_RECORD_EXIT:
795 return ops->exit(ops, event, sample, machine); 796 return tool->exit(tool, event, sample, machine);
796 case PERF_RECORD_LOST: 797 case PERF_RECORD_LOST:
797 if (ops->lost == perf_event__process_lost) 798 if (tool->lost == perf_event__process_lost)
798 session->hists.stats.total_lost += event->lost.lost; 799 session->hists.stats.total_lost += event->lost.lost;
799 return ops->lost(ops, event, sample, machine); 800 return tool->lost(tool, event, sample, machine);
800 case PERF_RECORD_READ: 801 case PERF_RECORD_READ:
801 return ops->read(ops, event, sample, evsel, machine); 802 return tool->read(tool, event, sample, evsel, machine);
802 case PERF_RECORD_THROTTLE: 803 case PERF_RECORD_THROTTLE:
803 return ops->throttle(ops, event, sample, machine); 804 return tool->throttle(tool, event, sample, machine);
804 case PERF_RECORD_UNTHROTTLE: 805 case PERF_RECORD_UNTHROTTLE:
805 return ops->unthrottle(ops, event, sample, machine); 806 return tool->unthrottle(tool, event, sample, machine);
806 default: 807 default:
807 ++session->hists.stats.nr_unknown_events; 808 ++session->hists.stats.nr_unknown_events;
808 return -1; 809 return -1;
@@ -826,7 +827,7 @@ static int perf_session__preprocess_sample(struct perf_session *session,
826} 827}
827 828
828static int perf_session__process_user_event(struct perf_session *session, union perf_event *event, 829static int perf_session__process_user_event(struct perf_session *session, union perf_event *event,
829 struct perf_event_ops *ops, u64 file_offset) 830 struct perf_tool *tool, u64 file_offset)
830{ 831{
831 int err; 832 int err;
832 833
@@ -835,20 +836,20 @@ static int perf_session__process_user_event(struct perf_session *session, union
835 /* These events are processed right away */ 836 /* These events are processed right away */
836 switch (event->header.type) { 837 switch (event->header.type) {
837 case PERF_RECORD_HEADER_ATTR: 838 case PERF_RECORD_HEADER_ATTR:
838 err = ops->attr(event, &session->evlist); 839 err = tool->attr(event, &session->evlist);
839 if (err == 0) 840 if (err == 0)
840 perf_session__update_sample_type(session); 841 perf_session__update_sample_type(session);
841 return err; 842 return err;
842 case PERF_RECORD_HEADER_EVENT_TYPE: 843 case PERF_RECORD_HEADER_EVENT_TYPE:
843 return ops->event_type(ops, event); 844 return tool->event_type(tool, event);
844 case PERF_RECORD_HEADER_TRACING_DATA: 845 case PERF_RECORD_HEADER_TRACING_DATA:
845 /* setup for reading amidst mmap */ 846 /* setup for reading amidst mmap */
846 lseek(session->fd, file_offset, SEEK_SET); 847 lseek(session->fd, file_offset, SEEK_SET);
847 return ops->tracing_data(event, session); 848 return tool->tracing_data(event, session);
848 case PERF_RECORD_HEADER_BUILD_ID: 849 case PERF_RECORD_HEADER_BUILD_ID:
849 return ops->build_id(ops, event, session); 850 return tool->build_id(tool, event, session);
850 case PERF_RECORD_FINISHED_ROUND: 851 case PERF_RECORD_FINISHED_ROUND:
851 return ops->finished_round(ops, event, session); 852 return tool->finished_round(tool, event, session);
852 default: 853 default:
853 return -EINVAL; 854 return -EINVAL;
854 } 855 }
@@ -856,7 +857,7 @@ static int perf_session__process_user_event(struct perf_session *session, union
856 857
857static int perf_session__process_event(struct perf_session *session, 858static int perf_session__process_event(struct perf_session *session,
858 union perf_event *event, 859 union perf_event *event,
859 struct perf_event_ops *ops, 860 struct perf_tool *tool,
860 u64 file_offset) 861 u64 file_offset)
861{ 862{
862 struct perf_sample sample; 863 struct perf_sample sample;
@@ -872,7 +873,7 @@ static int perf_session__process_event(struct perf_session *session,
872 hists__inc_nr_events(&session->hists, event->header.type); 873 hists__inc_nr_events(&session->hists, event->header.type);
873 874
874 if (event->header.type >= PERF_RECORD_USER_TYPE_START) 875 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
875 return perf_session__process_user_event(session, event, ops, file_offset); 876 return perf_session__process_user_event(session, event, tool, file_offset);
876 877
877 /* 878 /*
878 * For all kernel events we get the sample data 879 * For all kernel events we get the sample data
@@ -885,14 +886,14 @@ static int perf_session__process_event(struct perf_session *session,
885 if (perf_session__preprocess_sample(session, event, &sample)) 886 if (perf_session__preprocess_sample(session, event, &sample))
886 return 0; 887 return 0;
887 888
888 if (ops->ordered_samples) { 889 if (tool->ordered_samples) {
889 ret = perf_session_queue_event(session, event, &sample, 890 ret = perf_session_queue_event(session, event, &sample,
890 file_offset); 891 file_offset);
891 if (ret != -ETIME) 892 if (ret != -ETIME)
892 return ret; 893 return ret;
893 } 894 }
894 895
895 return perf_session_deliver_event(session, event, &sample, ops, 896 return perf_session_deliver_event(session, event, &sample, tool,
896 file_offset); 897 file_offset);
897} 898}
898 899
@@ -921,9 +922,9 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se
921} 922}
922 923
923static void perf_session__warn_about_errors(const struct perf_session *session, 924static void perf_session__warn_about_errors(const struct perf_session *session,
924 const struct perf_event_ops *ops) 925 const struct perf_tool *tool)
925{ 926{
926 if (ops->lost == perf_event__process_lost && 927 if (tool->lost == perf_event__process_lost &&
927 session->hists.stats.nr_events[PERF_RECORD_LOST] != 0) { 928 session->hists.stats.nr_events[PERF_RECORD_LOST] != 0) {
928 ui__warning("Processed %d events and lost %d chunks!\n\n" 929 ui__warning("Processed %d events and lost %d chunks!\n\n"
929 "Check IO/CPU overload!\n\n", 930 "Check IO/CPU overload!\n\n",
@@ -958,7 +959,7 @@ static void perf_session__warn_about_errors(const struct perf_session *session,
958volatile int session_done; 959volatile int session_done;
959 960
960static int __perf_session__process_pipe_events(struct perf_session *self, 961static int __perf_session__process_pipe_events(struct perf_session *self,
961 struct perf_event_ops *ops) 962 struct perf_tool *tool)
962{ 963{
963 union perf_event event; 964 union perf_event event;
964 uint32_t size; 965 uint32_t size;
@@ -967,7 +968,7 @@ static int __perf_session__process_pipe_events(struct perf_session *self,
967 int err; 968 int err;
968 void *p; 969 void *p;
969 970
970 perf_event_ops__fill_defaults(ops); 971 perf_tool__fill_defaults(tool);
971 972
972 head = 0; 973 head = 0;
973more: 974more:
@@ -1004,7 +1005,7 @@ more:
1004 } 1005 }
1005 1006
1006 if (size == 0 || 1007 if (size == 0 ||
1007 (skip = perf_session__process_event(self, &event, ops, head)) < 0) { 1008 (skip = perf_session__process_event(self, &event, tool, head)) < 0) {
1008 dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n", 1009 dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n",
1009 head, event.header.size, event.header.type); 1010 head, event.header.size, event.header.type);
1010 /* 1011 /*
@@ -1027,7 +1028,7 @@ more:
1027done: 1028done:
1028 err = 0; 1029 err = 0;
1029out_err: 1030out_err:
1030 perf_session__warn_about_errors(self, ops); 1031 perf_session__warn_about_errors(self, tool);
1031 perf_session_free_sample_buffers(self); 1032 perf_session_free_sample_buffers(self);
1032 return err; 1033 return err;
1033} 1034}
@@ -1058,7 +1059,7 @@ fetch_mmaped_event(struct perf_session *session,
1058 1059
1059int __perf_session__process_events(struct perf_session *session, 1060int __perf_session__process_events(struct perf_session *session,
1060 u64 data_offset, u64 data_size, 1061 u64 data_offset, u64 data_size,
1061 u64 file_size, struct perf_event_ops *ops) 1062 u64 file_size, struct perf_tool *tool)
1062{ 1063{
1063 u64 head, page_offset, file_offset, file_pos, progress_next; 1064 u64 head, page_offset, file_offset, file_pos, progress_next;
1064 int err, mmap_prot, mmap_flags, map_idx = 0; 1065 int err, mmap_prot, mmap_flags, map_idx = 0;
@@ -1067,7 +1068,7 @@ int __perf_session__process_events(struct perf_session *session,
1067 union perf_event *event; 1068 union perf_event *event;
1068 uint32_t size; 1069 uint32_t size;
1069 1070
1070 perf_event_ops__fill_defaults(ops); 1071 perf_tool__fill_defaults(tool);
1071 1072
1072 page_size = sysconf(_SC_PAGESIZE); 1073 page_size = sysconf(_SC_PAGESIZE);
1073 1074
@@ -1122,7 +1123,7 @@ more:
1122 size = event->header.size; 1123 size = event->header.size;
1123 1124
1124 if (size == 0 || 1125 if (size == 0 ||
1125 perf_session__process_event(session, event, ops, file_pos) < 0) { 1126 perf_session__process_event(session, event, tool, file_pos) < 0) {
1126 dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n", 1127 dump_printf("%#" PRIx64 " [%#x]: skipping unknown header type: %d\n",
1127 file_offset + head, event->header.size, 1128 file_offset + head, event->header.size,
1128 event->header.type); 1129 event->header.type);
@@ -1151,15 +1152,15 @@ more:
1151 err = 0; 1152 err = 0;
1152 /* do the final flush for ordered samples */ 1153 /* do the final flush for ordered samples */
1153 session->ordered_samples.next_flush = ULLONG_MAX; 1154 session->ordered_samples.next_flush = ULLONG_MAX;
1154 flush_sample_queue(session, ops); 1155 flush_sample_queue(session, tool);
1155out_err: 1156out_err:
1156 perf_session__warn_about_errors(session, ops); 1157 perf_session__warn_about_errors(session, tool);
1157 perf_session_free_sample_buffers(session); 1158 perf_session_free_sample_buffers(session);
1158 return err; 1159 return err;
1159} 1160}
1160 1161
1161int perf_session__process_events(struct perf_session *self, 1162int perf_session__process_events(struct perf_session *self,
1162 struct perf_event_ops *ops) 1163 struct perf_tool *tool)
1163{ 1164{
1164 int err; 1165 int err;
1165 1166
@@ -1170,9 +1171,9 @@ int perf_session__process_events(struct perf_session *self,
1170 err = __perf_session__process_events(self, 1171 err = __perf_session__process_events(self,
1171 self->header.data_offset, 1172 self->header.data_offset,
1172 self->header.data_size, 1173 self->header.data_size,
1173 self->size, ops); 1174 self->size, tool);
1174 else 1175 else
1175 err = __perf_session__process_pipe_events(self, ops); 1176 err = __perf_session__process_pipe_events(self, tool);
1176 1177
1177 return err; 1178 return err;
1178} 1179}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 1c5823c7d6dc..30e9c6b6fc3c 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -53,55 +53,20 @@ struct perf_session {
53 char filename[0]; 53 char filename[0];
54}; 54};
55 55
56struct perf_evsel; 56struct perf_tool;
57struct perf_event_ops;
58
59typedef int (*event_sample)(struct perf_event_ops *ops,
60 union perf_event *event, struct perf_sample *sample,
61 struct perf_evsel *evsel, struct machine *machine);
62typedef int (*event_op)(struct perf_event_ops *ops, union perf_event *event,
63 struct perf_sample *sample,
64 struct machine *machine);
65typedef int (*event_synth_op)(union perf_event *self,
66 struct perf_session *session);
67typedef int (*event_attr_op)(union perf_event *event,
68 struct perf_evlist **pevlist);
69typedef int (*event_simple_op)(struct perf_event_ops *ops,
70 union perf_event *event);
71typedef int (*event_op2)(struct perf_event_ops *ops, union perf_event *event,
72 struct perf_session *session);
73
74struct perf_event_ops {
75 event_sample sample,
76 read;
77 event_op mmap,
78 comm,
79 fork,
80 exit,
81 lost,
82 throttle,
83 unthrottle;
84 event_attr_op attr;
85 event_synth_op tracing_data;
86 event_simple_op event_type;
87 event_op2 finished_round,
88 build_id;
89 bool ordered_samples;
90 bool ordering_requires_timestamps;
91};
92 57
93struct perf_session *perf_session__new(const char *filename, int mode, 58struct perf_session *perf_session__new(const char *filename, int mode,
94 bool force, bool repipe, 59 bool force, bool repipe,
95 struct perf_event_ops *ops); 60 struct perf_tool *tool);
96void perf_session__delete(struct perf_session *self); 61void perf_session__delete(struct perf_session *self);
97 62
98void perf_event_header__bswap(struct perf_event_header *self); 63void perf_event_header__bswap(struct perf_event_header *self);
99 64
100int __perf_session__process_events(struct perf_session *self, 65int __perf_session__process_events(struct perf_session *self,
101 u64 data_offset, u64 data_size, u64 size, 66 u64 data_offset, u64 data_size, u64 size,
102 struct perf_event_ops *ops); 67 struct perf_tool *tool);
103int perf_session__process_events(struct perf_session *self, 68int perf_session__process_events(struct perf_session *self,
104 struct perf_event_ops *event_ops); 69 struct perf_tool *tool);
105 70
106int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel *evsel, 71int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel *evsel,
107 struct thread *thread, 72 struct thread *thread,
@@ -142,11 +107,11 @@ struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t p
142 107
143static inline 108static inline
144void perf_session__process_machines(struct perf_session *self, 109void perf_session__process_machines(struct perf_session *self,
145 struct perf_event_ops *ops, 110 struct perf_tool *tool,
146 machine__process_t process) 111 machine__process_t process)
147{ 112{
148 process(&self->host_machine, ops); 113 process(&self->host_machine, tool);
149 return machines__process(&self->machines, process, ops); 114 return machines__process(&self->machines, process, tool);
150} 115}
151 116
152struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); 117struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
new file mode 100644
index 000000000000..89ff1b551a74
--- /dev/null
+++ b/tools/perf/util/tool.h
@@ -0,0 +1,45 @@
1#ifndef __PERF_TOOL_H
2#define __PERF_TOOL_H
3
4struct perf_session;
5struct perf_evsel;
6struct perf_tool;
7struct machine;
8
9typedef int (*event_sample)(struct perf_tool *tool, union perf_event *event,
10 struct perf_sample *sample,
11 struct perf_evsel *evsel, struct machine *machine);
12
13typedef int (*event_op)(struct perf_tool *tool, union perf_event *event,
14 struct perf_sample *sample, struct machine *machine);
15
16typedef int (*event_attr_op)(union perf_event *event,
17 struct perf_evlist **pevlist);
18typedef int (*event_simple_op)(struct perf_tool *tool, union perf_event *event);
19
20typedef int (*event_synth_op)(union perf_event *event,
21 struct perf_session *session);
22
23typedef int (*event_op2)(struct perf_tool *tool, union perf_event *event,
24 struct perf_session *session);
25
26struct perf_tool {
27 event_sample sample,
28 read;
29 event_op mmap,
30 comm,
31 fork,
32 exit,
33 lost,
34 throttle,
35 unthrottle;
36 event_attr_op attr;
37 event_synth_op tracing_data;
38 event_simple_op event_type;
39 event_op2 finished_round,
40 build_id;
41 bool ordered_samples;
42 bool ordering_requires_timestamps;
43};
44
45#endif /* __PERF_TOOL_H */
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index 44eda6fc6b33..40430ec5c267 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -1,16 +1,17 @@
1#ifndef __PERF_TOP_H 1#ifndef __PERF_TOP_H
2#define __PERF_TOP_H 1 2#define __PERF_TOP_H 1
3 3
4#include "tool.h"
4#include "types.h" 5#include "types.h"
5#include "session.h"
6#include "../perf.h"
7#include <stddef.h> 6#include <stddef.h>
7#include <stdbool.h>
8 8
9struct perf_evlist; 9struct perf_evlist;
10struct perf_evsel; 10struct perf_evsel;
11struct perf_session;
11 12
12struct perf_top { 13struct perf_top {
13 struct perf_event_ops ops; 14 struct perf_tool tool;
14 struct perf_evlist *evlist; 15 struct perf_evlist *evlist;
15 /* 16 /*
16 * Symbols will be added here in perf_event__process_sample and will 17 * Symbols will be added here in perf_event__process_sample and will