aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-11-25 05:19:45 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 07:38:56 -0500
commitd20deb64e0490ee9442b5181bc08a62d2cadcb90 (patch)
treeafdb3f6fc9abbce9d0a96b7049d1f8121178a356 /tools/perf/util
parent7009cc34b964939815160d7de64cf0215cdbf8bb (diff)
perf tools: Pass tool context in the the perf_event_ops functions
So that we don't need to have that many globals. Next steps will remove the 'session' pointer, that in most cases is not needed. Then we can rename perf_event_ops to 'perf_tool' that better describes this class hierarchy. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-wp4djox7x6w1i2bab1pt4xxp@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/build-id.c7
-rw-r--r--tools/perf/util/callchain.h3
-rw-r--r--tools/perf/util/event.c66
-rw-r--r--tools/perf/util/event.h38
-rw-r--r--tools/perf/util/header.c36
-rw-r--r--tools/perf/util/header.h27
-rw-r--r--tools/perf/util/session.c60
-rw-r--r--tools/perf/util/session.h23
-rw-r--r--tools/perf/util/top.h3
9 files changed, 163 insertions, 100 deletions
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index f2fe6ec08945..0e4de1865013 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -13,8 +13,10 @@
13#include "symbol.h" 13#include "symbol.h"
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include "debug.h" 15#include "debug.h"
16#include "session.h"
16 17
17static int build_id__mark_dso_hit(union perf_event *event, 18static int build_id__mark_dso_hit(struct perf_event_ops *ops __used,
19 union perf_event *event,
18 struct perf_sample *sample __used, 20 struct perf_sample *sample __used,
19 struct perf_evsel *evsel __used, 21 struct perf_evsel *evsel __used,
20 struct perf_session *session) 22 struct perf_session *session)
@@ -38,7 +40,8 @@ static int build_id__mark_dso_hit(union perf_event *event,
38 return 0; 40 return 0;
39} 41}
40 42
41static int perf_event__exit_del_thread(union perf_event *event, 43static int perf_event__exit_del_thread(struct perf_event_ops *ops __used,
44 union perf_event *event,
42 struct perf_sample *sample __used, 45 struct perf_sample *sample __used,
43 struct perf_session *session) 46 struct perf_session *session)
44{ 47{
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 9b4ff16cac96..7f9c0f1ae3a9 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -101,6 +101,9 @@ int callchain_append(struct callchain_root *root,
101int callchain_merge(struct callchain_cursor *cursor, 101int callchain_merge(struct callchain_cursor *cursor,
102 struct callchain_root *dst, struct callchain_root *src); 102 struct callchain_root *dst, struct callchain_root *src);
103 103
104struct ip_callchain;
105union perf_event;
106
104bool ip_callchain__valid(struct ip_callchain *chain, 107bool ip_callchain__valid(struct ip_callchain *chain,
105 const union perf_event *event); 108 const union perf_event *event);
106/* 109/*
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 437f8ca679a0..4800f38c7277 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -44,7 +44,8 @@ static struct perf_sample synth_sample = {
44 .period = 1, 44 .period = 1,
45}; 45};
46 46
47static pid_t perf_event__synthesize_comm(union perf_event *event, pid_t pid, 47static pid_t perf_event__synthesize_comm(struct perf_event_ops *ops,
48 union perf_event *event, pid_t pid,
48 int full, perf_event__handler_t process, 49 int full, perf_event__handler_t process,
49 struct perf_session *session) 50 struct perf_session *session)
50{ 51{
@@ -99,7 +100,7 @@ out_race:
99 if (!full) { 100 if (!full) {
100 event->comm.tid = pid; 101 event->comm.tid = pid;
101 102
102 process(event, &synth_sample, session); 103 process(ops, event, &synth_sample, session);
103 goto out; 104 goto out;
104 } 105 }
105 106
@@ -117,7 +118,7 @@ out_race:
117 118
118 event->comm.tid = pid; 119 event->comm.tid = pid;
119 120
120 process(event, &synth_sample, session); 121 process(ops, event, &synth_sample, session);
121 } 122 }
122 123
123 closedir(tasks); 124 closedir(tasks);
@@ -127,7 +128,8 @@ out:
127 return tgid; 128 return tgid;
128} 129}
129 130
130static int perf_event__synthesize_mmap_events(union perf_event *event, 131static int perf_event__synthesize_mmap_events(struct perf_event_ops *ops,
132 union perf_event *event,
131 pid_t pid, pid_t tgid, 133 pid_t pid, pid_t tgid,
132 perf_event__handler_t process, 134 perf_event__handler_t process,
133 struct perf_session *session) 135 struct perf_session *session)
@@ -198,7 +200,7 @@ static int perf_event__synthesize_mmap_events(union perf_event *event,
198 event->mmap.pid = tgid; 200 event->mmap.pid = tgid;
199 event->mmap.tid = pid; 201 event->mmap.tid = pid;
200 202
201 process(event, &synth_sample, session); 203 process(ops, event, &synth_sample, session);
202 } 204 }
203 } 205 }
204 206
@@ -206,7 +208,8 @@ static int perf_event__synthesize_mmap_events(union perf_event *event,
206 return 0; 208 return 0;
207} 209}
208 210
209int perf_event__synthesize_modules(perf_event__handler_t process, 211int perf_event__synthesize_modules(struct perf_event_ops *ops,
212 perf_event__handler_t process,
210 struct perf_session *session, 213 struct perf_session *session,
211 struct machine *machine) 214 struct machine *machine)
212{ 215{
@@ -251,7 +254,7 @@ int perf_event__synthesize_modules(perf_event__handler_t process,
251 254
252 memcpy(event->mmap.filename, pos->dso->long_name, 255 memcpy(event->mmap.filename, pos->dso->long_name,
253 pos->dso->long_name_len + 1); 256 pos->dso->long_name_len + 1);
254 process(event, &synth_sample, session); 257 process(ops, event, &synth_sample, session);
255 } 258 }
256 259
257 free(event); 260 free(event);
@@ -261,17 +264,19 @@ int perf_event__synthesize_modules(perf_event__handler_t process,
261static int __event__synthesize_thread(union perf_event *comm_event, 264static int __event__synthesize_thread(union perf_event *comm_event,
262 union perf_event *mmap_event, 265 union perf_event *mmap_event,
263 pid_t pid, perf_event__handler_t process, 266 pid_t pid, perf_event__handler_t process,
267 struct perf_event_ops *ops,
264 struct perf_session *session) 268 struct perf_session *session)
265{ 269{
266 pid_t tgid = perf_event__synthesize_comm(comm_event, pid, 1, process, 270 pid_t tgid = perf_event__synthesize_comm(ops, comm_event, pid, 1, process,
267 session); 271 session);
268 if (tgid == -1) 272 if (tgid == -1)
269 return -1; 273 return -1;
270 return perf_event__synthesize_mmap_events(mmap_event, pid, tgid, 274 return perf_event__synthesize_mmap_events(ops, mmap_event, pid, tgid,
271 process, session); 275 process, session);
272} 276}
273 277
274int perf_event__synthesize_thread_map(struct thread_map *threads, 278int perf_event__synthesize_thread_map(struct perf_event_ops *ops,
279 struct thread_map *threads,
275 perf_event__handler_t process, 280 perf_event__handler_t process,
276 struct perf_session *session) 281 struct perf_session *session)
277{ 282{
@@ -290,7 +295,7 @@ int perf_event__synthesize_thread_map(struct thread_map *threads,
290 for (thread = 0; thread < threads->nr; ++thread) { 295 for (thread = 0; thread < threads->nr; ++thread) {
291 if (__event__synthesize_thread(comm_event, mmap_event, 296 if (__event__synthesize_thread(comm_event, mmap_event,
292 threads->map[thread], 297 threads->map[thread],
293 process, session)) { 298 process, ops, session)) {
294 err = -1; 299 err = -1;
295 break; 300 break;
296 } 301 }
@@ -302,7 +307,8 @@ out:
302 return err; 307 return err;
303} 308}
304 309
305int perf_event__synthesize_threads(perf_event__handler_t process, 310int perf_event__synthesize_threads(struct perf_event_ops *ops,
311 perf_event__handler_t process,
306 struct perf_session *session) 312 struct perf_session *session)
307{ 313{
308 DIR *proc; 314 DIR *proc;
@@ -330,7 +336,7 @@ int perf_event__synthesize_threads(perf_event__handler_t process,
330 continue; 336 continue;
331 337
332 __event__synthesize_thread(comm_event, mmap_event, pid, 338 __event__synthesize_thread(comm_event, mmap_event, pid,
333 process, session); 339 process, ops, session);
334 } 340 }
335 341
336 closedir(proc); 342 closedir(proc);
@@ -365,7 +371,8 @@ static int find_symbol_cb(void *arg, const char *name, char type,
365 return 1; 371 return 1;
366} 372}
367 373
368int perf_event__synthesize_kernel_mmap(perf_event__handler_t process, 374int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops,
375 perf_event__handler_t process,
369 struct perf_session *session, 376 struct perf_session *session,
370 struct machine *machine, 377 struct machine *machine,
371 const char *symbol_name) 378 const char *symbol_name)
@@ -423,13 +430,14 @@ int perf_event__synthesize_kernel_mmap(perf_event__handler_t process,
423 event->mmap.len = map->end - event->mmap.start; 430 event->mmap.len = map->end - event->mmap.start;
424 event->mmap.pid = machine->pid; 431 event->mmap.pid = machine->pid;
425 432
426 err = process(event, &synth_sample, session); 433 err = process(ops, event, &synth_sample, session);
427 free(event); 434 free(event);
428 435
429 return err; 436 return err;
430} 437}
431 438
432int perf_event__process_comm(union perf_event *event, 439int perf_event__process_comm(struct perf_event_ops *ops __used,
440 union perf_event *event,
433 struct perf_sample *sample __used, 441 struct perf_sample *sample __used,
434 struct perf_session *session) 442 struct perf_session *session)
435{ 443{
@@ -445,7 +453,8 @@ int perf_event__process_comm(union perf_event *event,
445 return 0; 453 return 0;
446} 454}
447 455
448int perf_event__process_lost(union perf_event *event, 456int perf_event__process_lost(struct perf_event_ops *ops __used,
457 union perf_event *event,
449 struct perf_sample *sample __used, 458 struct perf_sample *sample __used,
450 struct perf_session *session) 459 struct perf_session *session)
451{ 460{
@@ -468,7 +477,8 @@ static void perf_event__set_kernel_mmap_len(union perf_event *event,
468 maps[MAP__FUNCTION]->end = ~0ULL; 477 maps[MAP__FUNCTION]->end = ~0ULL;
469} 478}
470 479
471static int perf_event__process_kernel_mmap(union perf_event *event, 480static int perf_event__process_kernel_mmap(struct perf_event_ops *ops __used,
481 union perf_event *event,
472 struct perf_session *session) 482 struct perf_session *session)
473{ 483{
474 struct map *map; 484 struct map *map;
@@ -567,7 +577,8 @@ out_problem:
567 return -1; 577 return -1;
568} 578}
569 579
570int perf_event__process_mmap(union perf_event *event, 580int perf_event__process_mmap(struct perf_event_ops *ops,
581 union perf_event *event,
571 struct perf_sample *sample __used, 582 struct perf_sample *sample __used,
572 struct perf_session *session) 583 struct perf_session *session)
573{ 584{
@@ -583,7 +594,7 @@ int perf_event__process_mmap(union perf_event *event,
583 594
584 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 595 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
585 cpumode == PERF_RECORD_MISC_KERNEL) { 596 cpumode == PERF_RECORD_MISC_KERNEL) {
586 ret = perf_event__process_kernel_mmap(event, session); 597 ret = perf_event__process_kernel_mmap(ops, event, session);
587 if (ret < 0) 598 if (ret < 0)
588 goto out_problem; 599 goto out_problem;
589 return 0; 600 return 0;
@@ -610,7 +621,8 @@ out_problem:
610 return 0; 621 return 0;
611} 622}
612 623
613int perf_event__process_task(union perf_event *event, 624int perf_event__process_task(struct perf_event_ops *ops __used,
625 union perf_event *event,
614 struct perf_sample *sample __used, 626 struct perf_sample *sample __used,
615 struct perf_session *session) 627 struct perf_session *session)
616{ 628{
@@ -634,22 +646,22 @@ int perf_event__process_task(union perf_event *event,
634 return 0; 646 return 0;
635} 647}
636 648
637int perf_event__process(union perf_event *event, struct perf_sample *sample, 649int perf_event__process(struct perf_event_ops *ops, union perf_event *event,
638 struct perf_session *session) 650 struct perf_sample *sample, struct perf_session *session)
639{ 651{
640 switch (event->header.type) { 652 switch (event->header.type) {
641 case PERF_RECORD_COMM: 653 case PERF_RECORD_COMM:
642 perf_event__process_comm(event, sample, session); 654 perf_event__process_comm(ops, event, sample, session);
643 break; 655 break;
644 case PERF_RECORD_MMAP: 656 case PERF_RECORD_MMAP:
645 perf_event__process_mmap(event, sample, session); 657 perf_event__process_mmap(ops, event, sample, session);
646 break; 658 break;
647 case PERF_RECORD_FORK: 659 case PERF_RECORD_FORK:
648 case PERF_RECORD_EXIT: 660 case PERF_RECORD_EXIT:
649 perf_event__process_task(event, sample, session); 661 perf_event__process_task(ops, event, sample, session);
650 break; 662 break;
651 case PERF_RECORD_LOST: 663 case PERF_RECORD_LOST:
652 perf_event__process_lost(event, sample, session); 664 perf_event__process_lost(ops, event, sample, session);
653 default: 665 default:
654 break; 666 break;
655 } 667 }
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 357a85b85248..669409d35710 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -141,38 +141,52 @@ 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_session; 145struct perf_session;
145struct thread_map; 146struct thread_map;
146 147
147typedef int (*perf_event__handler_synth_t)(union perf_event *event, 148typedef int (*perf_event__handler_t)(struct perf_event_ops *ops,
148 struct perf_session *session); 149 union perf_event *event,
149typedef int (*perf_event__handler_t)(union perf_event *event,
150 struct perf_sample *sample, 150 struct perf_sample *sample,
151 struct perf_session *session); 151 struct perf_session *session);
152 152
153int perf_event__synthesize_thread_map(struct thread_map *threads, 153int perf_event__synthesize_thread_map(struct perf_event_ops *ops,
154 struct thread_map *threads,
154 perf_event__handler_t process, 155 perf_event__handler_t process,
155 struct perf_session *session); 156 struct perf_session *session);
156int perf_event__synthesize_threads(perf_event__handler_t process, 157int perf_event__synthesize_threads(struct perf_event_ops *ops,
158 perf_event__handler_t process,
157 struct perf_session *session); 159 struct perf_session *session);
158int perf_event__synthesize_kernel_mmap(perf_event__handler_t process, 160int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops,
161 perf_event__handler_t process,
159 struct perf_session *session, 162 struct perf_session *session,
160 struct machine *machine, 163 struct machine *machine,
161 const char *symbol_name); 164 const char *symbol_name);
162 165
163int perf_event__synthesize_modules(perf_event__handler_t process, 166int perf_event__synthesize_modules(struct perf_event_ops *ops,
167 perf_event__handler_t process,
164 struct perf_session *session, 168 struct perf_session *session,
165 struct machine *machine); 169 struct machine *machine);
166 170
167int perf_event__process_comm(union perf_event *event, struct perf_sample *sample, 171int perf_event__process_comm(struct perf_event_ops *ops,
172 union perf_event *event,
173 struct perf_sample *sample,
168 struct perf_session *session); 174 struct perf_session *session);
169int perf_event__process_lost(union perf_event *event, struct perf_sample *sample, 175int perf_event__process_lost(struct perf_event_ops *ops,
176 union perf_event *event,
177 struct perf_sample *sample,
170 struct perf_session *session); 178 struct perf_session *session);
171int perf_event__process_mmap(union perf_event *event, struct perf_sample *sample, 179int perf_event__process_mmap(struct perf_event_ops *ops,
180 union perf_event *event,
181 struct perf_sample *sample,
172 struct perf_session *session); 182 struct perf_session *session);
173int perf_event__process_task(union perf_event *event, struct perf_sample *sample, 183int perf_event__process_task(struct perf_event_ops *ops,
184 union perf_event *event,
185 struct perf_sample *sample,
174 struct perf_session *session); 186 struct perf_session *session);
175int perf_event__process(union perf_event *event, struct perf_sample *sample, 187int perf_event__process(struct perf_event_ops *ops,
188 union perf_event *event,
189 struct perf_sample *sample,
176 struct perf_session *session); 190 struct perf_session *session);
177 191
178struct addr_location; 192struct addr_location;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 1fa97dd21200..ab3a2b0e8f06 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2070,7 +2070,8 @@ out_delete_evlist:
2070 return -ENOMEM; 2070 return -ENOMEM;
2071} 2071}
2072 2072
2073int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, 2073int perf_event__synthesize_attr(struct perf_event_ops *ops,
2074 struct perf_event_attr *attr, u16 ids, u64 *id,
2074 perf_event__handler_t process, 2075 perf_event__handler_t process,
2075 struct perf_session *session) 2076 struct perf_session *session)
2076{ 2077{
@@ -2094,21 +2095,22 @@ int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
2094 ev->attr.header.type = PERF_RECORD_HEADER_ATTR; 2095 ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
2095 ev->attr.header.size = size; 2096 ev->attr.header.size = size;
2096 2097
2097 err = process(ev, NULL, session); 2098 err = process(ops, ev, NULL, session);
2098 2099
2099 free(ev); 2100 free(ev);
2100 2101
2101 return err; 2102 return err;
2102} 2103}
2103 2104
2104int perf_session__synthesize_attrs(struct perf_session *session, 2105int perf_event__synthesize_attrs(struct perf_event_ops *ops,
2106 struct perf_session *session,
2105 perf_event__handler_t process) 2107 perf_event__handler_t process)
2106{ 2108{
2107 struct perf_evsel *attr; 2109 struct perf_evsel *attr;
2108 int err = 0; 2110 int err = 0;
2109 2111
2110 list_for_each_entry(attr, &session->evlist->entries, node) { 2112 list_for_each_entry(attr, &session->evlist->entries, node) {
2111 err = perf_event__synthesize_attr(&attr->attr, attr->ids, 2113 err = perf_event__synthesize_attr(ops, &attr->attr, attr->ids,
2112 attr->id, process, session); 2114 attr->id, process, session);
2113 if (err) { 2115 if (err) {
2114 pr_debug("failed to create perf header attribute\n"); 2116 pr_debug("failed to create perf header attribute\n");
@@ -2156,7 +2158,8 @@ int perf_event__process_attr(union perf_event *event,
2156 return 0; 2158 return 0;
2157} 2159}
2158 2160
2159int perf_event__synthesize_event_type(u64 event_id, char *name, 2161int perf_event__synthesize_event_type(struct perf_event_ops *ops,
2162 u64 event_id, char *name,
2160 perf_event__handler_t process, 2163 perf_event__handler_t process,
2161 struct perf_session *session) 2164 struct perf_session *session)
2162{ 2165{
@@ -2176,12 +2179,13 @@ int perf_event__synthesize_event_type(u64 event_id, char *name,
2176 ev.event_type.header.size = sizeof(ev.event_type) - 2179 ev.event_type.header.size = sizeof(ev.event_type) -
2177 (sizeof(ev.event_type.event_type.name) - size); 2180 (sizeof(ev.event_type.event_type.name) - size);
2178 2181
2179 err = process(&ev, NULL, session); 2182 err = process(ops, &ev, NULL, session);
2180 2183
2181 return err; 2184 return err;
2182} 2185}
2183 2186
2184int perf_event__synthesize_event_types(perf_event__handler_t process, 2187int perf_event__synthesize_event_types(struct perf_event_ops *ops,
2188 perf_event__handler_t process,
2185 struct perf_session *session) 2189 struct perf_session *session)
2186{ 2190{
2187 struct perf_trace_event_type *type; 2191 struct perf_trace_event_type *type;
@@ -2190,7 +2194,7 @@ int perf_event__synthesize_event_types(perf_event__handler_t process,
2190 for (i = 0; i < event_count; i++) { 2194 for (i = 0; i < event_count; i++) {
2191 type = &events[i]; 2195 type = &events[i];
2192 2196
2193 err = perf_event__synthesize_event_type(type->event_id, 2197 err = perf_event__synthesize_event_type(ops, type->event_id,
2194 type->name, process, 2198 type->name, process,
2195 session); 2199 session);
2196 if (err) { 2200 if (err) {
@@ -2202,7 +2206,8 @@ int perf_event__synthesize_event_types(perf_event__handler_t process,
2202 return err; 2206 return err;
2203} 2207}
2204 2208
2205int perf_event__process_event_type(union perf_event *event, 2209int perf_event__process_event_type(struct perf_event_ops *ops __unused,
2210 union perf_event *event,
2206 struct perf_session *session __unused) 2211 struct perf_session *session __unused)
2207{ 2212{
2208 if (perf_header__push_event(event->event_type.event_type.event_id, 2213 if (perf_header__push_event(event->event_type.event_type.event_id,
@@ -2212,7 +2217,8 @@ int perf_event__process_event_type(union perf_event *event,
2212 return 0; 2217 return 0;
2213} 2218}
2214 2219
2215int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist, 2220int perf_event__synthesize_tracing_data(struct perf_event_ops *ops, int fd,
2221 struct perf_evlist *evlist,
2216 perf_event__handler_t process, 2222 perf_event__handler_t process,
2217 struct perf_session *session __unused) 2223 struct perf_session *session __unused)
2218{ 2224{
@@ -2245,7 +2251,7 @@ int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist,
2245 ev.tracing_data.header.size = sizeof(ev.tracing_data); 2251 ev.tracing_data.header.size = sizeof(ev.tracing_data);
2246 ev.tracing_data.size = aligned_size; 2252 ev.tracing_data.size = aligned_size;
2247 2253
2248 process(&ev, NULL, session); 2254 process(ops, &ev, NULL, session);
2249 2255
2250 /* 2256 /*
2251 * The put function will copy all the tracing data 2257 * The put function will copy all the tracing data
@@ -2287,7 +2293,8 @@ int perf_event__process_tracing_data(union perf_event *event,
2287 return size_read + padding; 2293 return size_read + padding;
2288} 2294}
2289 2295
2290int perf_event__synthesize_build_id(struct dso *pos, u16 misc, 2296int perf_event__synthesize_build_id(struct perf_event_ops *ops,
2297 struct dso *pos, u16 misc,
2291 perf_event__handler_t process, 2298 perf_event__handler_t process,
2292 struct machine *machine, 2299 struct machine *machine,
2293 struct perf_session *session) 2300 struct perf_session *session)
@@ -2310,12 +2317,13 @@ int perf_event__synthesize_build_id(struct dso *pos, u16 misc,
2310 ev.build_id.header.size = sizeof(ev.build_id) + len; 2317 ev.build_id.header.size = sizeof(ev.build_id) + len;
2311 memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); 2318 memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
2312 2319
2313 err = process(&ev, NULL, session); 2320 err = process(ops, &ev, NULL, session);
2314 2321
2315 return err; 2322 return err;
2316} 2323}
2317 2324
2318int perf_event__process_build_id(union perf_event *event, 2325int perf_event__process_build_id(struct perf_event_ops *ops __used,
2326 union perf_event *event,
2319 struct perf_session *session) 2327 struct perf_session *session)
2320{ 2328{
2321 __event_process_build_id(&event->build_id, 2329 __event_process_build_id(&event->build_id,
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 0a88982bc392..54dae5f09556 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -68,6 +68,7 @@ struct perf_header {
68}; 68};
69 69
70struct perf_evlist; 70struct perf_evlist;
71struct perf_session;
71 72
72int perf_session__read_header(struct perf_session *session, int fd); 73int perf_session__read_header(struct perf_session *session, int fd);
73int perf_session__write_header(struct perf_session *session, 74int perf_session__write_header(struct perf_session *session,
@@ -96,32 +97,40 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
96 const char *name, bool is_kallsyms); 97 const char *name, bool is_kallsyms);
97int 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);
98 99
99int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, 100int perf_event__synthesize_attr(struct perf_event_ops *ops,
101 struct perf_event_attr *attr, u16 ids, u64 *id,
100 perf_event__handler_t process, 102 perf_event__handler_t process,
101 struct perf_session *session); 103 struct perf_session *session);
102int perf_session__synthesize_attrs(struct perf_session *session, 104int perf_event__synthesize_attrs(struct perf_event_ops *ops,
103 perf_event__handler_t process); 105 struct perf_session *session,
106 perf_event__handler_t process);
104int perf_event__process_attr(union perf_event *event, struct perf_evlist **pevlist); 107int perf_event__process_attr(union perf_event *event, struct perf_evlist **pevlist);
105 108
106int perf_event__synthesize_event_type(u64 event_id, char *name, 109int perf_event__synthesize_event_type(struct perf_event_ops *ops,
110 u64 event_id, char *name,
107 perf_event__handler_t process, 111 perf_event__handler_t process,
108 struct perf_session *session); 112 struct perf_session *session);
109int perf_event__synthesize_event_types(perf_event__handler_t process, 113int perf_event__synthesize_event_types(struct perf_event_ops *ops,
114 perf_event__handler_t process,
110 struct perf_session *session); 115 struct perf_session *session);
111int perf_event__process_event_type(union perf_event *event, 116int perf_event__process_event_type(struct perf_event_ops *ops,
117 union perf_event *event,
112 struct perf_session *session); 118 struct perf_session *session);
113 119
114int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist, 120int perf_event__synthesize_tracing_data(struct perf_event_ops *ops,
121 int fd, struct perf_evlist *evlist,
115 perf_event__handler_t process, 122 perf_event__handler_t process,
116 struct perf_session *session); 123 struct perf_session *session);
117int perf_event__process_tracing_data(union perf_event *event, 124int perf_event__process_tracing_data(union perf_event *event,
118 struct perf_session *session); 125 struct perf_session *session);
119 126
120int perf_event__synthesize_build_id(struct dso *pos, u16 misc, 127int perf_event__synthesize_build_id(struct perf_event_ops *ops,
128 struct dso *pos, u16 misc,
121 perf_event__handler_t process, 129 perf_event__handler_t process,
122 struct machine *machine, 130 struct machine *machine,
123 struct perf_session *session); 131 struct perf_session *session);
124int perf_event__process_build_id(union perf_event *event, 132int perf_event__process_build_id(struct perf_event_ops *ops,
133 union perf_event *event,
125 struct perf_session *session); 134 struct perf_session *session);
126 135
127/* 136/*
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 734358b51ed1..a36023a66779 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -270,13 +270,21 @@ int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel
270 return 0; 270 return 0;
271} 271}
272 272
273static int process_event_synth_stub(union perf_event *event __used, 273static int process_event_synth_stub(struct perf_event_ops *ops __used,
274 union perf_event *event __used,
274 struct perf_session *session __used) 275 struct perf_session *session __used)
275{ 276{
276 dump_printf(": unhandled!\n"); 277 dump_printf(": unhandled!\n");
277 return 0; 278 return 0;
278} 279}
279 280
281static int process_event_synth_tracing_data_stub(union perf_event *event __used,
282 struct perf_session *session __used)
283{
284 dump_printf(": unhandled!\n");
285 return 0;
286}
287
280static int process_event_synth_attr_stub(union perf_event *event __used, 288static int process_event_synth_attr_stub(union perf_event *event __used,
281 struct perf_evlist **pevlist __used) 289 struct perf_evlist **pevlist __used)
282{ 290{
@@ -284,7 +292,8 @@ static int process_event_synth_attr_stub(union perf_event *event __used,
284 return 0; 292 return 0;
285} 293}
286 294
287static int process_event_sample_stub(union perf_event *event __used, 295static int process_event_sample_stub(struct perf_event_ops *ops __used,
296 union perf_event *event __used,
288 struct perf_sample *sample __used, 297 struct perf_sample *sample __used,
289 struct perf_evsel *evsel __used, 298 struct perf_evsel *evsel __used,
290 struct perf_session *session __used) 299 struct perf_session *session __used)
@@ -293,7 +302,8 @@ static int process_event_sample_stub(union perf_event *event __used,
293 return 0; 302 return 0;
294} 303}
295 304
296static int process_event_stub(union perf_event *event __used, 305static int process_event_stub(struct perf_event_ops *ops __used,
306 union perf_event *event __used,
297 struct perf_sample *sample __used, 307 struct perf_sample *sample __used,
298 struct perf_session *session __used) 308 struct perf_session *session __used)
299{ 309{
@@ -301,17 +311,17 @@ static int process_event_stub(union perf_event *event __used,
301 return 0; 311 return 0;
302} 312}
303 313
304static int process_finished_round_stub(union perf_event *event __used, 314static int process_finished_round_stub(struct perf_event_ops *ops __used,
305 struct perf_session *session __used, 315 union perf_event *event __used,
306 struct perf_event_ops *ops __used) 316 struct perf_session *session __used)
307{ 317{
308 dump_printf(": unhandled!\n"); 318 dump_printf(": unhandled!\n");
309 return 0; 319 return 0;
310} 320}
311 321
312static int process_finished_round(union perf_event *event, 322static int process_finished_round(struct perf_event_ops *ops,
313 struct perf_session *session, 323 union perf_event *event,
314 struct perf_event_ops *ops); 324 struct perf_session *session);
315 325
316static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) 326static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
317{ 327{
@@ -338,7 +348,7 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
338 if (handler->event_type == NULL) 348 if (handler->event_type == NULL)
339 handler->event_type = process_event_synth_stub; 349 handler->event_type = process_event_synth_stub;
340 if (handler->tracing_data == NULL) 350 if (handler->tracing_data == NULL)
341 handler->tracing_data = process_event_synth_stub; 351 handler->tracing_data = process_event_synth_tracing_data_stub;
342 if (handler->build_id == NULL) 352 if (handler->build_id == NULL)
343 handler->build_id = process_event_synth_stub; 353 handler->build_id = process_event_synth_stub;
344 if (handler->finished_round == NULL) { 354 if (handler->finished_round == NULL) {
@@ -565,9 +575,9 @@ static void flush_sample_queue(struct perf_session *s,
565 * Flush every events below timestamp 7 575 * Flush every events below timestamp 7
566 * etc... 576 * etc...
567 */ 577 */
568static int process_finished_round(union perf_event *event __used, 578static int process_finished_round(struct perf_event_ops *ops,
569 struct perf_session *session, 579 union perf_event *event __used,
570 struct perf_event_ops *ops) 580 struct perf_session *session)
571{ 581{
572 flush_sample_queue(session, ops); 582 flush_sample_queue(session, ops);
573 session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; 583 session->ordered_samples.next_flush = session->ordered_samples.max_timestamp;
@@ -759,23 +769,23 @@ static int perf_session_deliver_event(struct perf_session *session,
759 ++session->hists.stats.nr_unknown_id; 769 ++session->hists.stats.nr_unknown_id;
760 return -1; 770 return -1;
761 } 771 }
762 return ops->sample(event, sample, evsel, session); 772 return ops->sample(ops, event, sample, evsel, session);
763 case PERF_RECORD_MMAP: 773 case PERF_RECORD_MMAP:
764 return ops->mmap(event, sample, session); 774 return ops->mmap(ops, event, sample, session);
765 case PERF_RECORD_COMM: 775 case PERF_RECORD_COMM:
766 return ops->comm(event, sample, session); 776 return ops->comm(ops, event, sample, session);
767 case PERF_RECORD_FORK: 777 case PERF_RECORD_FORK:
768 return ops->fork(event, sample, session); 778 return ops->fork(ops, event, sample, session);
769 case PERF_RECORD_EXIT: 779 case PERF_RECORD_EXIT:
770 return ops->exit(event, sample, session); 780 return ops->exit(ops, event, sample, session);
771 case PERF_RECORD_LOST: 781 case PERF_RECORD_LOST:
772 return ops->lost(event, sample, session); 782 return ops->lost(ops, event, sample, session);
773 case PERF_RECORD_READ: 783 case PERF_RECORD_READ:
774 return ops->read(event, sample, session); 784 return ops->read(ops, event, sample, session);
775 case PERF_RECORD_THROTTLE: 785 case PERF_RECORD_THROTTLE:
776 return ops->throttle(event, sample, session); 786 return ops->throttle(ops, event, sample, session);
777 case PERF_RECORD_UNTHROTTLE: 787 case PERF_RECORD_UNTHROTTLE:
778 return ops->unthrottle(event, sample, session); 788 return ops->unthrottle(ops, event, sample, session);
779 default: 789 default:
780 ++session->hists.stats.nr_unknown_events; 790 ++session->hists.stats.nr_unknown_events;
781 return -1; 791 return -1;
@@ -813,15 +823,15 @@ static int perf_session__process_user_event(struct perf_session *session, union
813 perf_session__update_sample_type(session); 823 perf_session__update_sample_type(session);
814 return err; 824 return err;
815 case PERF_RECORD_HEADER_EVENT_TYPE: 825 case PERF_RECORD_HEADER_EVENT_TYPE:
816 return ops->event_type(event, session); 826 return ops->event_type(ops, event, session);
817 case PERF_RECORD_HEADER_TRACING_DATA: 827 case PERF_RECORD_HEADER_TRACING_DATA:
818 /* setup for reading amidst mmap */ 828 /* setup for reading amidst mmap */
819 lseek(session->fd, file_offset, SEEK_SET); 829 lseek(session->fd, file_offset, SEEK_SET);
820 return ops->tracing_data(event, session); 830 return ops->tracing_data(event, session);
821 case PERF_RECORD_HEADER_BUILD_ID: 831 case PERF_RECORD_HEADER_BUILD_ID:
822 return ops->build_id(event, session); 832 return ops->build_id(ops, event, session);
823 case PERF_RECORD_FINISHED_ROUND: 833 case PERF_RECORD_FINISHED_ROUND:
824 return ops->finished_round(event, session, ops); 834 return ops->finished_round(ops, event, session);
825 default: 835 default:
826 return -EINVAL; 836 return -EINVAL;
827 } 837 }
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index d2f430367713..6de3d1368900 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -56,16 +56,18 @@ struct perf_session {
56struct perf_evsel; 56struct perf_evsel;
57struct perf_event_ops; 57struct perf_event_ops;
58 58
59typedef int (*event_sample)(union perf_event *event, struct perf_sample *sample, 59typedef int (*event_sample)(struct perf_event_ops *ops,
60 union perf_event *event, struct perf_sample *sample,
60 struct perf_evsel *evsel, struct perf_session *session); 61 struct perf_evsel *evsel, struct perf_session *session);
61typedef int (*event_op)(union perf_event *self, struct perf_sample *sample, 62typedef int (*event_op)(struct perf_event_ops *ops, union perf_event *event,
63 struct perf_sample *sample,
62 struct perf_session *session); 64 struct perf_session *session);
63typedef int (*event_synth_op)(union perf_event *self, 65typedef int (*event_synth_op)(union perf_event *self,
64 struct perf_session *session); 66 struct perf_session *session);
65typedef int (*event_attr_op)(union perf_event *event, 67typedef int (*event_attr_op)(union perf_event *event,
66 struct perf_evlist **pevlist); 68 struct perf_evlist **pevlist);
67typedef int (*event_op2)(union perf_event *self, struct perf_session *session, 69typedef int (*event_op2)(struct perf_event_ops *ops, union perf_event *event,
68 struct perf_event_ops *ops); 70 struct perf_session *session);
69 71
70struct perf_event_ops { 72struct perf_event_ops {
71 event_sample sample; 73 event_sample sample;
@@ -78,10 +80,10 @@ struct perf_event_ops {
78 throttle, 80 throttle,
79 unthrottle; 81 unthrottle;
80 event_attr_op attr; 82 event_attr_op attr;
81 event_synth_op event_type, 83 event_synth_op tracing_data;
82 tracing_data, 84 event_op2 event_type,
83 build_id; 85 build_id,
84 event_op2 finished_round; 86 finished_round;
85 bool ordered_samples; 87 bool ordered_samples;
86 bool ordering_requires_timestamps; 88 bool ordering_requires_timestamps;
87}; 89};
@@ -142,10 +144,11 @@ struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t p
142 144
143static inline 145static inline
144void perf_session__process_machines(struct perf_session *self, 146void perf_session__process_machines(struct perf_session *self,
147 struct perf_event_ops *ops,
145 machine__process_t process) 148 machine__process_t process)
146{ 149{
147 process(&self->host_machine, self); 150 process(&self->host_machine, ops);
148 return machines__process(&self->machines, process, self); 151 return machines__process(&self->machines, process, ops);
149} 152}
150 153
151size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); 154size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index 399650967958..44eda6fc6b33 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -2,14 +2,15 @@
2#define __PERF_TOP_H 1 2#define __PERF_TOP_H 1
3 3
4#include "types.h" 4#include "types.h"
5#include "session.h"
5#include "../perf.h" 6#include "../perf.h"
6#include <stddef.h> 7#include <stddef.h>
7 8
8struct perf_evlist; 9struct perf_evlist;
9struct perf_evsel; 10struct perf_evsel;
10struct perf_session;
11 11
12struct perf_top { 12struct perf_top {
13 struct perf_event_ops ops;
13 struct perf_evlist *evlist; 14 struct perf_evlist *evlist;
14 /* 15 /*
15 * Symbols will be added here in perf_event__process_sample and will 16 * Symbols will be added here in perf_event__process_sample and will