perf tools: Add trace-event object
authorJiri Olsa <jolsa@redhat.com>
Tue, 3 Dec 2013 13:09:23 +0000 (14:09 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 4 Dec 2013 18:20:52 +0000 (15:20 -0300)
Add trace-event object to keep together 'struct pevent' object with its
loaded plugins with following interface:

int trace_event__init(struct trace_event *t);

  - Initalizes 'struct pevent' object and loads plugins for it

void trace_event__cleanup(struct trace_event *t);

  - Cleanups both 'struct pevent' and plugins

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1386076182-14484-10-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile.perf
tools/perf/builtin-script.c
tools/perf/util/header.c
tools/perf/util/python-ext-sources
tools/perf/util/session.h
tools/perf/util/trace-event-parse.c
tools/perf/util/trace-event-read.c
tools/perf/util/trace-event.c [new file with mode: 0644]
tools/perf/util/trace-event.h

index abc7ac3713adf28a601f6e862a1fd991178fd061..ca3b87d5389a12bc9e00cccbab1168e22a42b5c1 100644 (file)
@@ -353,6 +353,7 @@ LIB_OBJS += $(OUTPUT)util/pmu-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
+LIB_OBJS += $(OUTPUT)util/trace-event.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
index c555bddfccd7de98f4f3a1ab6569ad7ba060f7d3..4484886dcf0866a5fb26488de6c3d14bd0a08040 100644 (file)
@@ -1786,7 +1786,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                        return -1;
                }
 
-               err = scripting_ops->generate_script(session->pevent,
+               err = scripting_ops->generate_script(session->tevent.pevent,
                                                     "perf-script");
                goto out;
        }
index 3e755f2bfe8f19ad0e45c9bb6c080b573eb00a38..125cdc9250ee623bc333735fb067fa2fdf264f07 100644 (file)
@@ -2834,11 +2834,11 @@ int perf_session__read_header(struct perf_session *session)
 
        symbol_conf.nr_events = nr_attrs;
 
-       perf_header__process_sections(header, fd, &session->pevent,
+       perf_header__process_sections(header, fd, &session->tevent,
                                      perf_file_section__process);
 
        if (perf_evlist__prepare_tracepoint_events(session->evlist,
-                                                  session->pevent))
+                                                  session->tevent.pevent))
                goto out_delete_evlist;
 
        return 0;
@@ -3003,7 +3003,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused,
        lseek(fd, offset + sizeof(struct tracing_data_event),
              SEEK_SET);
 
-       size_read = trace_report(fd, &session->pevent,
+       size_read = trace_report(fd, &session->tevent,
                                 session->repipe);
        padding = PERF_ALIGN(size_read, sizeof(u64)) - size_read;
 
@@ -3025,7 +3025,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused,
        }
 
        perf_evlist__prepare_tracepoint_events(session->evlist,
-                                              session->pevent);
+                                              session->tevent.pevent);
 
        return size_read + padding;
 }
index 239036fb2b2c0b08b9352dcbce368904917d2521..595bfc73d2ed28cf14feee7daf73c76d92527223 100644 (file)
@@ -18,4 +18,5 @@ util/cgroup.c
 util/rblist.c
 util/strlist.c
 util/fs.c
+util/trace-event.c
 ../../lib/rbtree.c
index 7e5d439864745e3ecc5aa455d4157014582c9eb7..004d3e8116aaa5eec952f177bced7f045df492db 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __PERF_SESSION_H
 #define __PERF_SESSION_H
 
+#include "trace-event.h"
 #include "hist.h"
 #include "event.h"
 #include "header.h"
@@ -32,7 +33,7 @@ struct perf_session {
        struct perf_header      header;
        struct machines         machines;
        struct perf_evlist      *evlist;
-       struct pevent           *pevent;
+       struct trace_event      tevent;
        struct events_stats     stats;
        bool                    repipe;
        struct ordered_samples  ordered_samples;
index 6681f71f2f95e329ddc5eba636d05ce67d3591ee..e0d6d07f68485167f2b05260fd932a288b42eec9 100644 (file)
 #include "util.h"
 #include "trace-event.h"
 
-struct pevent *read_trace_init(int file_bigendian, int host_bigendian)
-{
-       struct pevent *pevent = pevent_alloc();
-
-       if (pevent != NULL) {
-               pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
-               pevent_set_file_bigendian(pevent, file_bigendian);
-               pevent_set_host_bigendian(pevent, host_bigendian);
-       }
-
-       return pevent;
-}
-
 static int get_common_field(struct scripting_context *context,
                            int *offset, int *size, const char *type)
 {
index f2112270c663d1c09f201272b7d348e5f6cf220d..e113e180c48f77398637a3b04771563412e3c0ee 100644 (file)
@@ -343,7 +343,7 @@ static int read_event_files(struct pevent *pevent)
        return 0;
 }
 
-ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
+ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
 {
        char buf[BUFSIZ];
        char test[] = { 23, 8, 68 };
@@ -356,11 +356,9 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
        int host_bigendian;
        int file_long_size;
        int file_page_size;
-       struct pevent *pevent;
+       struct pevent *pevent = NULL;
        int err;
 
-       *ppevent = NULL;
-
        repipe = __repipe;
        input_fd = fd;
 
@@ -390,12 +388,17 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
        file_bigendian = buf[0];
        host_bigendian = bigendian();
 
-       pevent = read_trace_init(file_bigendian, host_bigendian);
-       if (pevent == NULL) {
-               pr_debug("read_trace_init failed");
+       if (trace_event__init(tevent)) {
+               pr_debug("trace_event__init failed");
                goto out;
        }
 
+       pevent = tevent->pevent;
+
+       pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
+       pevent_set_file_bigendian(pevent, file_bigendian);
+       pevent_set_host_bigendian(pevent, host_bigendian);
+
        if (do_read(buf, 1) < 0)
                goto out;
        file_long_size = buf[0];
@@ -432,11 +435,10 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
                pevent_print_printk(pevent);
        }
 
-       *ppevent = pevent;
        pevent = NULL;
 
 out:
        if (pevent)
-               pevent_free(pevent);
+               trace_event__cleanup(tevent);
        return size;
 }
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
new file mode 100644 (file)
index 0000000..a155a77
--- /dev/null
@@ -0,0 +1,21 @@
+
+#include <traceevent/event-parse.h>
+#include "trace-event.h"
+
+int trace_event__init(struct trace_event *t)
+{
+       struct pevent *pevent = pevent_alloc();
+
+       if (pevent) {
+               t->plugin_list = traceevent_load_plugins(pevent);
+               t->pevent  = pevent;
+       }
+
+       return pevent ? 0 : -1;
+}
+
+void trace_event__cleanup(struct trace_event *t)
+{
+       pevent_free(t->pevent);
+       traceevent_unload_plugins(t->plugin_list);
+}
index 04df63114109604403f2f57a84ed03ec0b765707..75dded36a2f1a649efb22d238dadf07fabd3daab 100644 (file)
@@ -3,17 +3,24 @@
 
 #include <traceevent/event-parse.h>
 #include "parse-events.h"
-#include "session.h"
 
 struct machine;
 struct perf_sample;
 union perf_event;
 struct perf_tool;
 struct thread;
+struct plugin_list;
+
+struct trace_event {
+       struct pevent           *pevent;
+       struct plugin_list      *plugin_list;
+};
+
+int trace_event__init(struct trace_event *t);
+void trace_event__cleanup(struct trace_event *t);
 
 int bigendian(void);
 
-struct pevent *read_trace_init(int file_bigendian, int host_bigendian);
 void event_format__print(struct event_format *event,
                         int cpu, void *data, int size);
 
@@ -27,7 +34,7 @@ raw_field_value(struct event_format *event, const char *name, void *data);
 void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size);
 void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size);
 
-ssize_t trace_report(int fd, struct pevent **pevent, bool repipe);
+ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
 
 struct event_format *trace_find_next_event(struct pevent *pevent,
                                           struct event_format *event);