aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2013-12-03 08:09:23 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-04 13:20:52 -0500
commit29f5ffd3d3ff9abdfc98928f7c4cb4097cefe434 (patch)
tree92d0e87f316562c7e641473798d46165e6681688
parentcef82c9f5a3deab94c1f1f02cfc25213844852ed (diff)
perf tools: Add trace-event object
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>
-rw-r--r--tools/perf/Makefile.perf1
-rw-r--r--tools/perf/builtin-script.c2
-rw-r--r--tools/perf/util/header.c8
-rw-r--r--tools/perf/util/python-ext-sources1
-rw-r--r--tools/perf/util/session.h3
-rw-r--r--tools/perf/util/trace-event-parse.c13
-rw-r--r--tools/perf/util/trace-event-read.c20
-rw-r--r--tools/perf/util/trace-event.c21
-rw-r--r--tools/perf/util/trace-event.h13
9 files changed, 51 insertions, 31 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index abc7ac3713ad..ca3b87d5389a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -353,6 +353,7 @@ LIB_OBJS += $(OUTPUT)util/pmu-bison.o
353LIB_OBJS += $(OUTPUT)util/trace-event-read.o 353LIB_OBJS += $(OUTPUT)util/trace-event-read.o
354LIB_OBJS += $(OUTPUT)util/trace-event-info.o 354LIB_OBJS += $(OUTPUT)util/trace-event-info.o
355LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o 355LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
356LIB_OBJS += $(OUTPUT)util/trace-event.o
356LIB_OBJS += $(OUTPUT)util/svghelper.o 357LIB_OBJS += $(OUTPUT)util/svghelper.o
357LIB_OBJS += $(OUTPUT)util/sort.o 358LIB_OBJS += $(OUTPUT)util/sort.o
358LIB_OBJS += $(OUTPUT)util/hist.o 359LIB_OBJS += $(OUTPUT)util/hist.o
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c555bddfccd7..4484886dcf08 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1786,7 +1786,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
1786 return -1; 1786 return -1;
1787 } 1787 }
1788 1788
1789 err = scripting_ops->generate_script(session->pevent, 1789 err = scripting_ops->generate_script(session->tevent.pevent,
1790 "perf-script"); 1790 "perf-script");
1791 goto out; 1791 goto out;
1792 } 1792 }
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3e755f2bfe8f..125cdc9250ee 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2834,11 +2834,11 @@ int perf_session__read_header(struct perf_session *session)
2834 2834
2835 symbol_conf.nr_events = nr_attrs; 2835 symbol_conf.nr_events = nr_attrs;
2836 2836
2837 perf_header__process_sections(header, fd, &session->pevent, 2837 perf_header__process_sections(header, fd, &session->tevent,
2838 perf_file_section__process); 2838 perf_file_section__process);
2839 2839
2840 if (perf_evlist__prepare_tracepoint_events(session->evlist, 2840 if (perf_evlist__prepare_tracepoint_events(session->evlist,
2841 session->pevent)) 2841 session->tevent.pevent))
2842 goto out_delete_evlist; 2842 goto out_delete_evlist;
2843 2843
2844 return 0; 2844 return 0;
@@ -3003,7 +3003,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused,
3003 lseek(fd, offset + sizeof(struct tracing_data_event), 3003 lseek(fd, offset + sizeof(struct tracing_data_event),
3004 SEEK_SET); 3004 SEEK_SET);
3005 3005
3006 size_read = trace_report(fd, &session->pevent, 3006 size_read = trace_report(fd, &session->tevent,
3007 session->repipe); 3007 session->repipe);
3008 padding = PERF_ALIGN(size_read, sizeof(u64)) - size_read; 3008 padding = PERF_ALIGN(size_read, sizeof(u64)) - size_read;
3009 3009
@@ -3025,7 +3025,7 @@ int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused,
3025 } 3025 }
3026 3026
3027 perf_evlist__prepare_tracepoint_events(session->evlist, 3027 perf_evlist__prepare_tracepoint_events(session->evlist,
3028 session->pevent); 3028 session->tevent.pevent);
3029 3029
3030 return size_read + padding; 3030 return size_read + padding;
3031} 3031}
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 239036fb2b2c..595bfc73d2ed 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -18,4 +18,5 @@ util/cgroup.c
18util/rblist.c 18util/rblist.c
19util/strlist.c 19util/strlist.c
20util/fs.c 20util/fs.c
21util/trace-event.c
21../../lib/rbtree.c 22../../lib/rbtree.c
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 7e5d43986474..004d3e8116aa 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 "trace-event.h"
4#include "hist.h" 5#include "hist.h"
5#include "event.h" 6#include "event.h"
6#include "header.h" 7#include "header.h"
@@ -32,7 +33,7 @@ struct perf_session {
32 struct perf_header header; 33 struct perf_header header;
33 struct machines machines; 34 struct machines machines;
34 struct perf_evlist *evlist; 35 struct perf_evlist *evlist;
35 struct pevent *pevent; 36 struct trace_event tevent;
36 struct events_stats stats; 37 struct events_stats stats;
37 bool repipe; 38 bool repipe;
38 struct ordered_samples ordered_samples; 39 struct ordered_samples ordered_samples;
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 6681f71f2f95..e0d6d07f6848 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -28,19 +28,6 @@
28#include "util.h" 28#include "util.h"
29#include "trace-event.h" 29#include "trace-event.h"
30 30
31struct pevent *read_trace_init(int file_bigendian, int host_bigendian)
32{
33 struct pevent *pevent = pevent_alloc();
34
35 if (pevent != NULL) {
36 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
37 pevent_set_file_bigendian(pevent, file_bigendian);
38 pevent_set_host_bigendian(pevent, host_bigendian);
39 }
40
41 return pevent;
42}
43
44static int get_common_field(struct scripting_context *context, 31static int get_common_field(struct scripting_context *context,
45 int *offset, int *size, const char *type) 32 int *offset, int *size, const char *type)
46{ 33{
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index f2112270c663..e113e180c48f 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -343,7 +343,7 @@ static int read_event_files(struct pevent *pevent)
343 return 0; 343 return 0;
344} 344}
345 345
346ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) 346ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
347{ 347{
348 char buf[BUFSIZ]; 348 char buf[BUFSIZ];
349 char test[] = { 23, 8, 68 }; 349 char test[] = { 23, 8, 68 };
@@ -356,11 +356,9 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
356 int host_bigendian; 356 int host_bigendian;
357 int file_long_size; 357 int file_long_size;
358 int file_page_size; 358 int file_page_size;
359 struct pevent *pevent; 359 struct pevent *pevent = NULL;
360 int err; 360 int err;
361 361
362 *ppevent = NULL;
363
364 repipe = __repipe; 362 repipe = __repipe;
365 input_fd = fd; 363 input_fd = fd;
366 364
@@ -390,12 +388,17 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
390 file_bigendian = buf[0]; 388 file_bigendian = buf[0];
391 host_bigendian = bigendian(); 389 host_bigendian = bigendian();
392 390
393 pevent = read_trace_init(file_bigendian, host_bigendian); 391 if (trace_event__init(tevent)) {
394 if (pevent == NULL) { 392 pr_debug("trace_event__init failed");
395 pr_debug("read_trace_init failed");
396 goto out; 393 goto out;
397 } 394 }
398 395
396 pevent = tevent->pevent;
397
398 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
399 pevent_set_file_bigendian(pevent, file_bigendian);
400 pevent_set_host_bigendian(pevent, host_bigendian);
401
399 if (do_read(buf, 1) < 0) 402 if (do_read(buf, 1) < 0)
400 goto out; 403 goto out;
401 file_long_size = buf[0]; 404 file_long_size = buf[0];
@@ -432,11 +435,10 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
432 pevent_print_printk(pevent); 435 pevent_print_printk(pevent);
433 } 436 }
434 437
435 *ppevent = pevent;
436 pevent = NULL; 438 pevent = NULL;
437 439
438out: 440out:
439 if (pevent) 441 if (pevent)
440 pevent_free(pevent); 442 trace_event__cleanup(tevent);
441 return size; 443 return size;
442} 444}
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
new file mode 100644
index 000000000000..a155a77f3023
--- /dev/null
+++ b/tools/perf/util/trace-event.c
@@ -0,0 +1,21 @@
1
2#include <traceevent/event-parse.h>
3#include "trace-event.h"
4
5int trace_event__init(struct trace_event *t)
6{
7 struct pevent *pevent = pevent_alloc();
8
9 if (pevent) {
10 t->plugin_list = traceevent_load_plugins(pevent);
11 t->pevent = pevent;
12 }
13
14 return pevent ? 0 : -1;
15}
16
17void trace_event__cleanup(struct trace_event *t)
18{
19 pevent_free(t->pevent);
20 traceevent_unload_plugins(t->plugin_list);
21}
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 04df63114109..75dded36a2f1 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -3,17 +3,24 @@
3 3
4#include <traceevent/event-parse.h> 4#include <traceevent/event-parse.h>
5#include "parse-events.h" 5#include "parse-events.h"
6#include "session.h"
7 6
8struct machine; 7struct machine;
9struct perf_sample; 8struct perf_sample;
10union perf_event; 9union perf_event;
11struct perf_tool; 10struct perf_tool;
12struct thread; 11struct thread;
12struct plugin_list;
13
14struct trace_event {
15 struct pevent *pevent;
16 struct plugin_list *plugin_list;
17};
18
19int trace_event__init(struct trace_event *t);
20void trace_event__cleanup(struct trace_event *t);
13 21
14int bigendian(void); 22int bigendian(void);
15 23
16struct pevent *read_trace_init(int file_bigendian, int host_bigendian);
17void event_format__print(struct event_format *event, 24void event_format__print(struct event_format *event,
18 int cpu, void *data, int size); 25 int cpu, void *data, int size);
19 26
@@ -27,7 +34,7 @@ raw_field_value(struct event_format *event, const char *name, void *data);
27void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size); 34void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size);
28void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size); 35void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size);
29 36
30ssize_t trace_report(int fd, struct pevent **pevent, bool repipe); 37ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
31 38
32struct event_format *trace_find_next_event(struct pevent *pevent, 39struct event_format *trace_find_next_event(struct pevent *pevent,
33 struct event_format *event); 40 struct event_format *event);