perf session: Ditch register_perf_file_handler
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 13 Dec 2009 21:50:25 +0000 (19:50 -0200)
committerIngo Molnar <mingo@elte.hu>
Mon, 14 Dec 2009 15:57:15 +0000 (16:57 +0100)
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>
13 files changed:
tools/perf/Makefile
tools/perf/builtin-annotate.c
tools/perf/builtin-buildid-list.c
tools/perf/builtin-kmem.c
tools/perf/builtin-report.c
tools/perf/builtin-sched.c
tools/perf/builtin-timechart.c
tools/perf/builtin-trace.c
tools/perf/util/data_map.c
tools/perf/util/data_map.h [deleted file]
tools/perf/util/header.c
tools/perf/util/session.c
tools/perf/util/session.h

index 406999668cab5b4538317898cd5ebf1c21718109..a4cb79255383039dab29993fef2f0d020e4d825a 100644 (file)
@@ -370,7 +370,6 @@ LIB_H += util/values.h
 LIB_H += util/sort.h
 LIB_H += util/hist.h
 LIB_H += util/thread.h
-LIB_H += util/data_map.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
 
index 2e418b9fc1c49cd35bc1919f192c6352cf2b29e6..43e3bb3544422ef1f53979d85477f3789d61454d 100644 (file)
@@ -26,7 +26,6 @@
 #include "util/sort.h"
 #include "util/hist.h"
 #include "util/session.h"
-#include "util/data_map.h"
 
 static char            const *input_name = "perf.data";
 
@@ -454,7 +453,7 @@ static void find_annotations(void)
        }
 }
 
-static struct perf_file_handler file_handler = {
+static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_mmap_event     = event__process_mmap,
        .process_comm_event     = event__process_comm,
@@ -463,7 +462,8 @@ static struct perf_file_handler file_handler = {
 
 static int __cmd_annotate(void)
 {
-       struct perf_session *session = perf_session__new(input_name, O_RDONLY, force);
+       struct perf_session *session = perf_session__new(input_name, O_RDONLY,
+                                                        force);
        struct thread *idle;
        int ret;
 
@@ -471,9 +471,9 @@ static int __cmd_annotate(void)
                return -ENOMEM;
 
        idle = register_idle_thread();
-       register_perf_file_handler(&file_handler);
 
-       ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
+       ret = perf_session__process_events(session, &event_ops, 0,
+                                          &event__cwdlen, &event__cwd);
        if (ret)
                goto out_delete;
 
index bfd16a1594e4abbcca6d0970eb6bc14571c75c6b..2629f76d95fe5acfc85f952b1f1961c55aaaeda5 100644 (file)
@@ -9,7 +9,6 @@
 #include "builtin.h"
 #include "perf.h"
 #include "util/cache.h"
-#include "util/data_map.h"
 #include "util/debug.h"
 #include "util/parse-options.h"
 #include "util/session.h"
index 101b2682b4dfc06b225e2f26e95a5dea83804b2e..6f74bd8d20e67d87635f73da755d417a74bda67f 100644 (file)
@@ -12,7 +12,6 @@
 #include "util/trace-event.h"
 
 #include "util/debug.h"
-#include "util/data_map.h"
 
 #include <linux/rbtree.h>
 
@@ -359,7 +358,7 @@ static int sample_type_check(u64 type)
        return 0;
 }
 
-static struct perf_file_handler file_handler = {
+static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_comm_event     = event__process_comm,
        .sample_type_check      = sample_type_check,
@@ -374,9 +373,8 @@ static int read_events(void)
                return -ENOMEM;
 
        register_idle_thread();
-       register_perf_file_handler(&file_handler);
-
-       err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
+       err = perf_session__process_events(session, &event_ops, 0,
+                                          &event__cwdlen, &event__cwd);
        perf_session__delete(session);
        return err;
 }
index dcd8fedc298c9c726eae6bb728ac5ec78ff30455..c203eaf73a2f82959f7b6eba4c1523c05ee4277b 100644 (file)
@@ -27,7 +27,6 @@
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 
-#include "util/data_map.h"
 #include "util/thread.h"
 #include "util/sort.h"
 #include "util/hist.h"
@@ -748,7 +747,7 @@ static int sample_type_check(u64 type)
        return 0;
 }
 
-static struct perf_file_handler file_handler = {
+static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_mmap_event     = event__process_mmap,
        .process_comm_event     = process_comm_event,
@@ -776,9 +775,7 @@ static int __cmd_report(void)
        if (show_threads)
                perf_read_values_init(&show_threads_values);
 
-       register_perf_file_handler(&file_handler);
-
-       ret = perf_session__process_events(session, full_paths,
+       ret = perf_session__process_events(session, &event_ops, full_paths,
                                           &event__cwdlen, &event__cwd);
        if (ret)
                goto out_delete;
index 48ab283ed86b2cc8904a47869e7629fb2dfff38f..b5b44723626185c966c77a1bda54193ba0a170bf 100644 (file)
@@ -12,7 +12,6 @@
 #include "util/trace-event.h"
 
 #include "util/debug.h"
-#include "util/data_map.h"
 
 #include <sys/prctl.h>
 
@@ -1656,7 +1655,7 @@ static int sample_type_check(u64 type)
        return 0;
 }
 
-static struct perf_file_handler file_handler = {
+static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_comm_event     = event__process_comm,
        .process_lost_event     = process_lost_event,
@@ -1672,9 +1671,9 @@ static int read_events(void)
                return -ENOMEM;
 
        register_idle_thread();
-       register_perf_file_handler(&file_handler);
 
-       err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
+       err = perf_session__process_events(session, &event_ops, 0,
+                                          &event__cwdlen, &event__cwd);
        perf_session__delete(session);
        return err;
 }
index db6caae1a404bb7b7ce3d13c466ad5f59f1bdb06..4b95cec6b4c59c34f7c16e1211a8c17d084033bf 100644 (file)
@@ -30,7 +30,7 @@
 #include "util/parse-options.h"
 #include "util/parse-events.h"
 #include "util/event.h"
-#include "util/data_map.h"
+#include "util/session.h"
 #include "util/svghelper.h"
 
 static char            const *input_name = "perf.data";
@@ -1046,7 +1046,7 @@ static int sample_type_check(u64 type)
        return 0;
 }
 
-static struct perf_file_handler file_handler = {
+static struct perf_event_ops event_ops = {
        .process_comm_event     = process_comm_event,
        .process_fork_event     = process_fork_event,
        .process_exit_event     = process_exit_event,
@@ -1062,9 +1062,8 @@ static int __cmd_timechart(void)
        if (session == NULL)
                return -ENOMEM;
 
-       register_perf_file_handler(&file_handler);
-
-       ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
+       ret = perf_session__process_events(session, &event_ops, 0,
+                                          &event__cwdlen, &event__cwd);
        if (ret)
                goto out_delete;
 
index 3057e1d387b9eb956447dbd0b55a32440927827a..c404dece950d378a14efa4ea4bce3cfd95716046 100644 (file)
@@ -57,7 +57,6 @@ static int cleanup_scripting(void)
 #include "util/debug.h"
 
 #include "util/trace-event.h"
-#include "util/data_map.h"
 #include "util/exec_cmd.h"
 
 static char const              *input_name = "perf.data";
@@ -118,7 +117,7 @@ static int sample_type_check(u64 type)
        return 0;
 }
 
-static struct perf_file_handler file_handler = {
+static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_comm_event     = event__process_comm,
        .sample_type_check      = sample_type_check,
@@ -127,9 +126,8 @@ static struct perf_file_handler file_handler = {
 static int __cmd_trace(struct perf_session *session)
 {
        register_idle_thread();
-       register_perf_file_handler(&file_handler);
-
-       return perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
+       return perf_session__process_events(session, &event_ops, 0,
+                                           &event__cwdlen, &event__cwd);
 }
 
 struct script_spec {
index 22bcdfeff55ceb68062a54c39e11427d738bcbc7..ba5bcfa1f9087b9129e640e0343838f918d75130 100644 (file)
@@ -1,10 +1,8 @@
-#include "data_map.h"
 #include "symbol.h"
 #include "util.h"
 #include "debug.h"
+#include "session.h"
 
-
-static struct perf_file_handler *curr_handler;
 static unsigned long   mmap_window = 32;
 static char            __cwd[PATH_MAX];
 
@@ -15,7 +13,7 @@ static int process_event_stub(event_t *event __used,
        return 0;
 }
 
-void register_perf_file_handler(struct perf_file_handler *handler)
+static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
 {
        if (!handler->process_sample_event)
                handler->process_sample_event = process_event_stub;
@@ -35,8 +33,6 @@ void register_perf_file_handler(struct perf_file_handler *handler)
                handler->process_throttle_event = process_event_stub;
        if (!handler->process_unthrottle_event)
                handler->process_unthrottle_event = process_event_stub;
-
-       curr_handler = handler;
 }
 
 static const char *event__name[] = {
@@ -63,6 +59,7 @@ void event__print_totals(void)
 }
 
 static int process_event(event_t *event, struct perf_session *session,
+                        struct perf_event_ops *ops,
                         unsigned long offset, unsigned long head)
 {
        trace_event(event);
@@ -78,25 +75,25 @@ static int process_event(event_t *event, struct perf_session *session,
 
        switch (event->header.type) {
        case PERF_RECORD_SAMPLE:
-               return curr_handler->process_sample_event(event, session);
+               return ops->process_sample_event(event, session);
        case PERF_RECORD_MMAP:
-               return curr_handler->process_mmap_event(event, session);
+               return ops->process_mmap_event(event, session);
        case PERF_RECORD_COMM:
-               return curr_handler->process_comm_event(event, session);
+               return ops->process_comm_event(event, session);
        case PERF_RECORD_FORK:
-               return curr_handler->process_fork_event(event, session);
+               return ops->process_fork_event(event, session);
        case PERF_RECORD_EXIT:
-               return curr_handler->process_exit_event(event, session);
+               return ops->process_exit_event(event, session);
        case PERF_RECORD_LOST:
-               return curr_handler->process_lost_event(event, session);
+               return ops->process_lost_event(event, session);
        case PERF_RECORD_READ:
-               return curr_handler->process_read_event(event, session);
+               return ops->process_read_event(event, session);
        case PERF_RECORD_THROTTLE:
-               return curr_handler->process_throttle_event(event, session);
+               return ops->process_throttle_event(event, session);
        case PERF_RECORD_UNTHROTTLE:
-               return curr_handler->process_unthrottle_event(event, session);
+               return ops->process_unthrottle_event(event, session);
        default:
-               curr_handler->total_unknown++;
+               ops->total_unknown++;
                return -1;
        }
 }
@@ -131,6 +128,7 @@ out:
 }
 
 int perf_session__process_events(struct perf_session *self,
+                                struct perf_event_ops *ops,
                                 int full_paths, int *cwdlen, char **cwd)
 {
        int err;
@@ -142,10 +140,7 @@ int perf_session__process_events(struct perf_session *self,
        uint32_t size;
        char *buf;
 
-       if (curr_handler == NULL) {
-               pr_debug("Forgot to register perf file handler\n");
-               return -EINVAL;
-       }
+       perf_event_ops__fill_defaults(ops);
 
        page_size = getpagesize();
 
@@ -153,8 +148,8 @@ int perf_session__process_events(struct perf_session *self,
        sample_type = perf_header__sample_type(&self->header);
 
        err = -EINVAL;
-       if (curr_handler->sample_type_check &&
-           curr_handler->sample_type_check(sample_type) < 0)
+       if (ops->sample_type_check &&
+           ops->sample_type_check(sample_type) < 0)
                goto out_err;
 
        if (!full_paths) {
@@ -210,7 +205,7 @@ more:
                        (void *)(long)event->header.size,
                        event->header.type);
 
-       if (!size || process_event(event, self, offset, head) < 0) {
+       if (!size || process_event(event, self, ops, offset, head) < 0) {
 
                dump_printf("%p [%p]: skipping unknown header type: %d\n",
                        (void *)(offset + head),
diff --git a/tools/perf/util/data_map.h b/tools/perf/util/data_map.h
deleted file mode 100644 (file)
index 6d4ae52..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef __PERF_DATAMAP_H
-#define __PERF_DATAMAP_H
-
-#include "event.h"
-#include "header.h"
-#include "session.h"
-
-struct perf_session;
-
-typedef int (*event_type_handler_t)(event_t *self,
-                                   struct perf_session *session);
-
-struct perf_file_handler {
-       event_type_handler_t    process_sample_event;
-       event_type_handler_t    process_mmap_event;
-       event_type_handler_t    process_comm_event;
-       event_type_handler_t    process_fork_event;
-       event_type_handler_t    process_exit_event;
-       event_type_handler_t    process_lost_event;
-       event_type_handler_t    process_read_event;
-       event_type_handler_t    process_throttle_event;
-       event_type_handler_t    process_unthrottle_event;
-       int                     (*sample_type_check)(u64 sample_type);
-       unsigned long           total_unknown;
-};
-
-void register_perf_file_handler(struct perf_file_handler *handler);
-int perf_session__process_events(struct perf_session *self,
-                                int full_paths, int *cwdlen, char **cwd);
-int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
-
-#endif
index f2e8d87151116c94a78868ba580e56be24382264..8a0bca55106f8d4ddb15492404367ef5b3f3de88 100644 (file)
@@ -8,8 +8,8 @@
 #include "header.h"
 #include "../perf.h"
 #include "trace-event.h"
+#include "session.h"
 #include "symbol.h"
-#include "data_map.h"
 #include "debug.h"
 
 /*
index 707ce1cb1621b3710ac26c16876479bbb086edab..39766868d43a7a075dd651e03b3d61d042c2bb73 100644 (file)
@@ -48,7 +48,8 @@ out_close:
        return -1;
 }
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force)
+struct perf_session *perf_session__new(const char *filename, int mode,
+                                      bool force)
 {
        size_t len = strlen(filename) + 1;
        struct perf_session *self = zalloc(sizeof(*self) + len);
index f3699c8c8ed4da77e3e1a87a058dcd20049eebe2..7a4c32c545f46cf239b40484fa535f1d53950b6f 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __PERF_SESSION_H
 #define __PERF_SESSION_H
 
+#include "event.h"
 #include "header.h"
 
 struct perf_session {
@@ -10,7 +11,30 @@ struct perf_session {
        char filename[0];
 };
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force);
+typedef int (*event_op)(event_t *self, struct perf_session *session);
+
+struct perf_event_ops {
+       event_op        process_sample_event;
+       event_op        process_mmap_event;
+       event_op        process_comm_event;
+       event_op        process_fork_event;
+       event_op        process_exit_event;
+       event_op        process_lost_event;
+       event_op        process_read_event;
+       event_op        process_throttle_event;
+       event_op        process_unthrottle_event;
+       int             (*sample_type_check)(u64 sample_type);
+       unsigned long   total_unknown;
+};
+
+struct perf_session *perf_session__new(const char *filename, int mode,
+                                      bool force);
 void perf_session__delete(struct perf_session *self);
 
+int perf_session__process_events(struct perf_session *self,
+                                struct perf_event_ops *event_ops,
+                                int full_paths, int *cwdlen, char **cwd);
+
+int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
+
 #endif /* __PERF_SESSION_H */