aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-12-13 16:50:25 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-14 10:57:15 -0500
commit301a0b020210360c6e441c7765521248bc87d58e (patch)
tree5321a8ab67584d0aac0e3df9a749df1b4206460b /tools
parentd8f66248d6f25f7c935cc5307c43bf394db07272 (diff)
perf session: Ditch register_perf_file_handler
Pass the event_ops to perf_session__process_events instead. Also move the event_ops definition to session.h, starting to move things around to their right place, trimming the many unneeded headers we have. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1260741029-4430-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/builtin-annotate.c10
-rw-r--r--tools/perf/builtin-buildid-list.c1
-rw-r--r--tools/perf/builtin-kmem.c8
-rw-r--r--tools/perf/builtin-report.c7
-rw-r--r--tools/perf/builtin-sched.c7
-rw-r--r--tools/perf/builtin-timechart.c9
-rw-r--r--tools/perf/builtin-trace.c8
-rw-r--r--tools/perf/util/data_map.c41
-rw-r--r--tools/perf/util/data_map.h32
-rw-r--r--tools/perf/util/header.c2
-rw-r--r--tools/perf/util/session.c3
-rw-r--r--tools/perf/util/session.h26
13 files changed, 66 insertions, 89 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 406999668cab..a4cb79255383 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -370,7 +370,6 @@ LIB_H += util/values.h
370LIB_H += util/sort.h 370LIB_H += util/sort.h
371LIB_H += util/hist.h 371LIB_H += util/hist.h
372LIB_H += util/thread.h 372LIB_H += util/thread.h
373LIB_H += util/data_map.h
374LIB_H += util/probe-finder.h 373LIB_H += util/probe-finder.h
375LIB_H += util/probe-event.h 374LIB_H += util/probe-event.h
376 375
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 2e418b9fc1c4..43e3bb354442 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -26,7 +26,6 @@
26#include "util/sort.h" 26#include "util/sort.h"
27#include "util/hist.h" 27#include "util/hist.h"
28#include "util/session.h" 28#include "util/session.h"
29#include "util/data_map.h"
30 29
31static char const *input_name = "perf.data"; 30static char const *input_name = "perf.data";
32 31
@@ -454,7 +453,7 @@ static void find_annotations(void)
454 } 453 }
455} 454}
456 455
457static struct perf_file_handler file_handler = { 456static struct perf_event_ops event_ops = {
458 .process_sample_event = process_sample_event, 457 .process_sample_event = process_sample_event,
459 .process_mmap_event = event__process_mmap, 458 .process_mmap_event = event__process_mmap,
460 .process_comm_event = event__process_comm, 459 .process_comm_event = event__process_comm,
@@ -463,7 +462,8 @@ static struct perf_file_handler file_handler = {
463 462
464static int __cmd_annotate(void) 463static int __cmd_annotate(void)
465{ 464{
466 struct perf_session *session = perf_session__new(input_name, O_RDONLY, force); 465 struct perf_session *session = perf_session__new(input_name, O_RDONLY,
466 force);
467 struct thread *idle; 467 struct thread *idle;
468 int ret; 468 int ret;
469 469
@@ -471,9 +471,9 @@ static int __cmd_annotate(void)
471 return -ENOMEM; 471 return -ENOMEM;
472 472
473 idle = register_idle_thread(); 473 idle = register_idle_thread();
474 register_perf_file_handler(&file_handler);
475 474
476 ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd); 475 ret = perf_session__process_events(session, &event_ops, 0,
476 &event__cwdlen, &event__cwd);
477 if (ret) 477 if (ret)
478 goto out_delete; 478 goto out_delete;
479 479
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index bfd16a1594e4..2629f76d95fe 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -9,7 +9,6 @@
9#include "builtin.h" 9#include "builtin.h"
10#include "perf.h" 10#include "perf.h"
11#include "util/cache.h" 11#include "util/cache.h"
12#include "util/data_map.h"
13#include "util/debug.h" 12#include "util/debug.h"
14#include "util/parse-options.h" 13#include "util/parse-options.h"
15#include "util/session.h" 14#include "util/session.h"
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 101b2682b4df..6f74bd8d20e6 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -12,7 +12,6 @@
12#include "util/trace-event.h" 12#include "util/trace-event.h"
13 13
14#include "util/debug.h" 14#include "util/debug.h"
15#include "util/data_map.h"
16 15
17#include <linux/rbtree.h> 16#include <linux/rbtree.h>
18 17
@@ -359,7 +358,7 @@ static int sample_type_check(u64 type)
359 return 0; 358 return 0;
360} 359}
361 360
362static struct perf_file_handler file_handler = { 361static struct perf_event_ops event_ops = {
363 .process_sample_event = process_sample_event, 362 .process_sample_event = process_sample_event,
364 .process_comm_event = event__process_comm, 363 .process_comm_event = event__process_comm,
365 .sample_type_check = sample_type_check, 364 .sample_type_check = sample_type_check,
@@ -374,9 +373,8 @@ static int read_events(void)
374 return -ENOMEM; 373 return -ENOMEM;
375 374
376 register_idle_thread(); 375 register_idle_thread();
377 register_perf_file_handler(&file_handler); 376 err = perf_session__process_events(session, &event_ops, 0,
378 377 &event__cwdlen, &event__cwd);
379 err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
380 perf_session__delete(session); 378 perf_session__delete(session);
381 return err; 379 return err;
382} 380}
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index dcd8fedc298c..c203eaf73a2f 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -27,7 +27,6 @@
27#include "util/parse-options.h" 27#include "util/parse-options.h"
28#include "util/parse-events.h" 28#include "util/parse-events.h"
29 29
30#include "util/data_map.h"
31#include "util/thread.h" 30#include "util/thread.h"
32#include "util/sort.h" 31#include "util/sort.h"
33#include "util/hist.h" 32#include "util/hist.h"
@@ -748,7 +747,7 @@ static int sample_type_check(u64 type)
748 return 0; 747 return 0;
749} 748}
750 749
751static struct perf_file_handler file_handler = { 750static struct perf_event_ops event_ops = {
752 .process_sample_event = process_sample_event, 751 .process_sample_event = process_sample_event,
753 .process_mmap_event = event__process_mmap, 752 .process_mmap_event = event__process_mmap,
754 .process_comm_event = process_comm_event, 753 .process_comm_event = process_comm_event,
@@ -776,9 +775,7 @@ static int __cmd_report(void)
776 if (show_threads) 775 if (show_threads)
777 perf_read_values_init(&show_threads_values); 776 perf_read_values_init(&show_threads_values);
778 777
779 register_perf_file_handler(&file_handler); 778 ret = perf_session__process_events(session, &event_ops, full_paths,
780
781 ret = perf_session__process_events(session, full_paths,
782 &event__cwdlen, &event__cwd); 779 &event__cwdlen, &event__cwd);
783 if (ret) 780 if (ret)
784 goto out_delete; 781 goto out_delete;
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 48ab283ed86b..b5b447236261 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -12,7 +12,6 @@
12#include "util/trace-event.h" 12#include "util/trace-event.h"
13 13
14#include "util/debug.h" 14#include "util/debug.h"
15#include "util/data_map.h"
16 15
17#include <sys/prctl.h> 16#include <sys/prctl.h>
18 17
@@ -1656,7 +1655,7 @@ static int sample_type_check(u64 type)
1656 return 0; 1655 return 0;
1657} 1656}
1658 1657
1659static struct perf_file_handler file_handler = { 1658static struct perf_event_ops event_ops = {
1660 .process_sample_event = process_sample_event, 1659 .process_sample_event = process_sample_event,
1661 .process_comm_event = event__process_comm, 1660 .process_comm_event = event__process_comm,
1662 .process_lost_event = process_lost_event, 1661 .process_lost_event = process_lost_event,
@@ -1672,9 +1671,9 @@ static int read_events(void)
1672 return -ENOMEM; 1671 return -ENOMEM;
1673 1672
1674 register_idle_thread(); 1673 register_idle_thread();
1675 register_perf_file_handler(&file_handler);
1676 1674
1677 err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd); 1675 err = perf_session__process_events(session, &event_ops, 0,
1676 &event__cwdlen, &event__cwd);
1678 perf_session__delete(session); 1677 perf_session__delete(session);
1679 return err; 1678 return err;
1680} 1679}
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index db6caae1a404..4b95cec6b4c5 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -30,7 +30,7 @@
30#include "util/parse-options.h" 30#include "util/parse-options.h"
31#include "util/parse-events.h" 31#include "util/parse-events.h"
32#include "util/event.h" 32#include "util/event.h"
33#include "util/data_map.h" 33#include "util/session.h"
34#include "util/svghelper.h" 34#include "util/svghelper.h"
35 35
36static char const *input_name = "perf.data"; 36static char const *input_name = "perf.data";
@@ -1046,7 +1046,7 @@ static int sample_type_check(u64 type)
1046 return 0; 1046 return 0;
1047} 1047}
1048 1048
1049static struct perf_file_handler file_handler = { 1049static struct perf_event_ops event_ops = {
1050 .process_comm_event = process_comm_event, 1050 .process_comm_event = process_comm_event,
1051 .process_fork_event = process_fork_event, 1051 .process_fork_event = process_fork_event,
1052 .process_exit_event = process_exit_event, 1052 .process_exit_event = process_exit_event,
@@ -1062,9 +1062,8 @@ static int __cmd_timechart(void)
1062 if (session == NULL) 1062 if (session == NULL)
1063 return -ENOMEM; 1063 return -ENOMEM;
1064 1064
1065 register_perf_file_handler(&file_handler); 1065 ret = perf_session__process_events(session, &event_ops, 0,
1066 1066 &event__cwdlen, &event__cwd);
1067 ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
1068 if (ret) 1067 if (ret)
1069 goto out_delete; 1068 goto out_delete;
1070 1069
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 3057e1d387b9..c404dece950d 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -57,7 +57,6 @@ static int cleanup_scripting(void)
57#include "util/debug.h" 57#include "util/debug.h"
58 58
59#include "util/trace-event.h" 59#include "util/trace-event.h"
60#include "util/data_map.h"
61#include "util/exec_cmd.h" 60#include "util/exec_cmd.h"
62 61
63static char const *input_name = "perf.data"; 62static char const *input_name = "perf.data";
@@ -118,7 +117,7 @@ static int sample_type_check(u64 type)
118 return 0; 117 return 0;
119} 118}
120 119
121static struct perf_file_handler file_handler = { 120static struct perf_event_ops event_ops = {
122 .process_sample_event = process_sample_event, 121 .process_sample_event = process_sample_event,
123 .process_comm_event = event__process_comm, 122 .process_comm_event = event__process_comm,
124 .sample_type_check = sample_type_check, 123 .sample_type_check = sample_type_check,
@@ -127,9 +126,8 @@ static struct perf_file_handler file_handler = {
127static int __cmd_trace(struct perf_session *session) 126static int __cmd_trace(struct perf_session *session)
128{ 127{
129 register_idle_thread(); 128 register_idle_thread();
130 register_perf_file_handler(&file_handler); 129 return perf_session__process_events(session, &event_ops, 0,
131 130 &event__cwdlen, &event__cwd);
132 return perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
133} 131}
134 132
135struct script_spec { 133struct script_spec {
diff --git a/tools/perf/util/data_map.c b/tools/perf/util/data_map.c
index 22bcdfeff55c..ba5bcfa1f908 100644
--- a/tools/perf/util/data_map.c
+++ b/tools/perf/util/data_map.c
@@ -1,10 +1,8 @@
1#include "data_map.h"
2#include "symbol.h" 1#include "symbol.h"
3#include "util.h" 2#include "util.h"
4#include "debug.h" 3#include "debug.h"
4#include "session.h"
5 5
6
7static struct perf_file_handler *curr_handler;
8static unsigned long mmap_window = 32; 6static unsigned long mmap_window = 32;
9static char __cwd[PATH_MAX]; 7static char __cwd[PATH_MAX];
10 8
@@ -15,7 +13,7 @@ static int process_event_stub(event_t *event __used,
15 return 0; 13 return 0;
16} 14}
17 15
18void register_perf_file_handler(struct perf_file_handler *handler) 16static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
19{ 17{
20 if (!handler->process_sample_event) 18 if (!handler->process_sample_event)
21 handler->process_sample_event = process_event_stub; 19 handler->process_sample_event = process_event_stub;
@@ -35,8 +33,6 @@ void register_perf_file_handler(struct perf_file_handler *handler)
35 handler->process_throttle_event = process_event_stub; 33 handler->process_throttle_event = process_event_stub;
36 if (!handler->process_unthrottle_event) 34 if (!handler->process_unthrottle_event)
37 handler->process_unthrottle_event = process_event_stub; 35 handler->process_unthrottle_event = process_event_stub;
38
39 curr_handler = handler;
40} 36}
41 37
42static const char *event__name[] = { 38static const char *event__name[] = {
@@ -63,6 +59,7 @@ void event__print_totals(void)
63} 59}
64 60
65static int process_event(event_t *event, struct perf_session *session, 61static int process_event(event_t *event, struct perf_session *session,
62 struct perf_event_ops *ops,
66 unsigned long offset, unsigned long head) 63 unsigned long offset, unsigned long head)
67{ 64{
68 trace_event(event); 65 trace_event(event);
@@ -78,25 +75,25 @@ static int process_event(event_t *event, struct perf_session *session,
78 75
79 switch (event->header.type) { 76 switch (event->header.type) {
80 case PERF_RECORD_SAMPLE: 77 case PERF_RECORD_SAMPLE:
81 return curr_handler->process_sample_event(event, session); 78 return ops->process_sample_event(event, session);
82 case PERF_RECORD_MMAP: 79 case PERF_RECORD_MMAP:
83 return curr_handler->process_mmap_event(event, session); 80 return ops->process_mmap_event(event, session);
84 case PERF_RECORD_COMM: 81 case PERF_RECORD_COMM:
85 return curr_handler->process_comm_event(event, session); 82 return ops->process_comm_event(event, session);
86 case PERF_RECORD_FORK: 83 case PERF_RECORD_FORK:
87 return curr_handler->process_fork_event(event, session); 84 return ops->process_fork_event(event, session);
88 case PERF_RECORD_EXIT: 85 case PERF_RECORD_EXIT:
89 return curr_handler->process_exit_event(event, session); 86 return ops->process_exit_event(event, session);
90 case PERF_RECORD_LOST: 87 case PERF_RECORD_LOST:
91 return curr_handler->process_lost_event(event, session); 88 return ops->process_lost_event(event, session);
92 case PERF_RECORD_READ: 89 case PERF_RECORD_READ:
93 return curr_handler->process_read_event(event, session); 90 return ops->process_read_event(event, session);
94 case PERF_RECORD_THROTTLE: 91 case PERF_RECORD_THROTTLE:
95 return curr_handler->process_throttle_event(event, session); 92 return ops->process_throttle_event(event, session);
96 case PERF_RECORD_UNTHROTTLE: 93 case PERF_RECORD_UNTHROTTLE:
97 return curr_handler->process_unthrottle_event(event, session); 94 return ops->process_unthrottle_event(event, session);
98 default: 95 default:
99 curr_handler->total_unknown++; 96 ops->total_unknown++;
100 return -1; 97 return -1;
101 } 98 }
102} 99}
@@ -131,6 +128,7 @@ out:
131} 128}
132 129
133int perf_session__process_events(struct perf_session *self, 130int perf_session__process_events(struct perf_session *self,
131 struct perf_event_ops *ops,
134 int full_paths, int *cwdlen, char **cwd) 132 int full_paths, int *cwdlen, char **cwd)
135{ 133{
136 int err; 134 int err;
@@ -142,10 +140,7 @@ int perf_session__process_events(struct perf_session *self,
142 uint32_t size; 140 uint32_t size;
143 char *buf; 141 char *buf;
144 142
145 if (curr_handler == NULL) { 143 perf_event_ops__fill_defaults(ops);
146 pr_debug("Forgot to register perf file handler\n");
147 return -EINVAL;
148 }
149 144
150 page_size = getpagesize(); 145 page_size = getpagesize();
151 146
@@ -153,8 +148,8 @@ int perf_session__process_events(struct perf_session *self,
153 sample_type = perf_header__sample_type(&self->header); 148 sample_type = perf_header__sample_type(&self->header);
154 149
155 err = -EINVAL; 150 err = -EINVAL;
156 if (curr_handler->sample_type_check && 151 if (ops->sample_type_check &&
157 curr_handler->sample_type_check(sample_type) < 0) 152 ops->sample_type_check(sample_type) < 0)
158 goto out_err; 153 goto out_err;
159 154
160 if (!full_paths) { 155 if (!full_paths) {
@@ -210,7 +205,7 @@ more:
210 (void *)(long)event->header.size, 205 (void *)(long)event->header.size,
211 event->header.type); 206 event->header.type);
212 207
213 if (!size || process_event(event, self, offset, head) < 0) { 208 if (!size || process_event(event, self, ops, offset, head) < 0) {
214 209
215 dump_printf("%p [%p]: skipping unknown header type: %d\n", 210 dump_printf("%p [%p]: skipping unknown header type: %d\n",
216 (void *)(offset + head), 211 (void *)(offset + head),
diff --git a/tools/perf/util/data_map.h b/tools/perf/util/data_map.h
deleted file mode 100644
index 6d4ae52bc07b..000000000000
--- a/tools/perf/util/data_map.h
+++ /dev/null
@@ -1,32 +0,0 @@
1#ifndef __PERF_DATAMAP_H
2#define __PERF_DATAMAP_H
3
4#include "event.h"
5#include "header.h"
6#include "session.h"
7
8struct perf_session;
9
10typedef int (*event_type_handler_t)(event_t *self,
11 struct perf_session *session);
12
13struct perf_file_handler {
14 event_type_handler_t process_sample_event;
15 event_type_handler_t process_mmap_event;
16 event_type_handler_t process_comm_event;
17 event_type_handler_t process_fork_event;
18 event_type_handler_t process_exit_event;
19 event_type_handler_t process_lost_event;
20 event_type_handler_t process_read_event;
21 event_type_handler_t process_throttle_event;
22 event_type_handler_t process_unthrottle_event;
23 int (*sample_type_check)(u64 sample_type);
24 unsigned long total_unknown;
25};
26
27void register_perf_file_handler(struct perf_file_handler *handler);
28int perf_session__process_events(struct perf_session *self,
29 int full_paths, int *cwdlen, char **cwd);
30int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
31
32#endif
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index f2e8d8715111..8a0bca55106f 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -8,8 +8,8 @@
8#include "header.h" 8#include "header.h"
9#include "../perf.h" 9#include "../perf.h"
10#include "trace-event.h" 10#include "trace-event.h"
11#include "session.h"
11#include "symbol.h" 12#include "symbol.h"
12#include "data_map.h"
13#include "debug.h" 13#include "debug.h"
14 14
15/* 15/*
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 707ce1cb1621..39766868d43a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -48,7 +48,8 @@ out_close:
48 return -1; 48 return -1;
49} 49}
50 50
51struct perf_session *perf_session__new(const char *filename, int mode, bool force) 51struct perf_session *perf_session__new(const char *filename, int mode,
52 bool force)
52{ 53{
53 size_t len = strlen(filename) + 1; 54 size_t len = strlen(filename) + 1;
54 struct perf_session *self = zalloc(sizeof(*self) + len); 55 struct perf_session *self = zalloc(sizeof(*self) + len);
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index f3699c8c8ed4..7a4c32c545f4 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -1,6 +1,7 @@
1#ifndef __PERF_SESSION_H 1#ifndef __PERF_SESSION_H
2#define __PERF_SESSION_H 2#define __PERF_SESSION_H
3 3
4#include "event.h"
4#include "header.h" 5#include "header.h"
5 6
6struct perf_session { 7struct perf_session {
@@ -10,7 +11,30 @@ struct perf_session {
10 char filename[0]; 11 char filename[0];
11}; 12};
12 13
13struct perf_session *perf_session__new(const char *filename, int mode, bool force); 14typedef int (*event_op)(event_t *self, struct perf_session *session);
15
16struct perf_event_ops {
17 event_op process_sample_event;
18 event_op process_mmap_event;
19 event_op process_comm_event;
20 event_op process_fork_event;
21 event_op process_exit_event;
22 event_op process_lost_event;
23 event_op process_read_event;
24 event_op process_throttle_event;
25 event_op process_unthrottle_event;
26 int (*sample_type_check)(u64 sample_type);
27 unsigned long total_unknown;
28};
29
30struct perf_session *perf_session__new(const char *filename, int mode,
31 bool force);
14void perf_session__delete(struct perf_session *self); 32void perf_session__delete(struct perf_session *self);
15 33
34int perf_session__process_events(struct perf_session *self,
35 struct perf_event_ops *event_ops,
36 int full_paths, int *cwdlen, char **cwd);
37
38int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
39
16#endif /* __PERF_SESSION_H */ 40#endif /* __PERF_SESSION_H */