aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/session.c
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/session.c
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/session.c')
-rw-r--r--tools/perf/util/session.c60
1 files changed, 35 insertions, 25 deletions
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 }