diff options
author | Jiri Olsa <jolsa@redhat.com> | 2013-12-03 08:09:23 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-12-04 13:20:52 -0500 |
commit | 29f5ffd3d3ff9abdfc98928f7c4cb4097cefe434 (patch) | |
tree | 92d0e87f316562c7e641473798d46165e6681688 | |
parent | cef82c9f5a3deab94c1f1f02cfc25213844852ed (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.perf | 1 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 2 | ||||
-rw-r--r-- | tools/perf/util/header.c | 8 | ||||
-rw-r--r-- | tools/perf/util/python-ext-sources | 1 | ||||
-rw-r--r-- | tools/perf/util/session.h | 3 | ||||
-rw-r--r-- | tools/perf/util/trace-event-parse.c | 13 | ||||
-rw-r--r-- | tools/perf/util/trace-event-read.c | 20 | ||||
-rw-r--r-- | tools/perf/util/trace-event.c | 21 | ||||
-rw-r--r-- | tools/perf/util/trace-event.h | 13 |
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 | |||
353 | LIB_OBJS += $(OUTPUT)util/trace-event-read.o | 353 | LIB_OBJS += $(OUTPUT)util/trace-event-read.o |
354 | LIB_OBJS += $(OUTPUT)util/trace-event-info.o | 354 | LIB_OBJS += $(OUTPUT)util/trace-event-info.o |
355 | LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o | 355 | LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o |
356 | LIB_OBJS += $(OUTPUT)util/trace-event.o | ||
356 | LIB_OBJS += $(OUTPUT)util/svghelper.o | 357 | LIB_OBJS += $(OUTPUT)util/svghelper.o |
357 | LIB_OBJS += $(OUTPUT)util/sort.o | 358 | LIB_OBJS += $(OUTPUT)util/sort.o |
358 | LIB_OBJS += $(OUTPUT)util/hist.o | 359 | LIB_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 | |||
18 | util/rblist.c | 18 | util/rblist.c |
19 | util/strlist.c | 19 | util/strlist.c |
20 | util/fs.c | 20 | util/fs.c |
21 | util/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 | ||
31 | struct 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 | |||
44 | static int get_common_field(struct scripting_context *context, | 31 | static 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 | ||
346 | ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) | 346 | ssize_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 | ||
438 | out: | 440 | out: |
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 | |||
5 | int 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 | |||
17 | void 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 | ||
8 | struct machine; | 7 | struct machine; |
9 | struct perf_sample; | 8 | struct perf_sample; |
10 | union perf_event; | 9 | union perf_event; |
11 | struct perf_tool; | 10 | struct perf_tool; |
12 | struct thread; | 11 | struct thread; |
12 | struct plugin_list; | ||
13 | |||
14 | struct trace_event { | ||
15 | struct pevent *pevent; | ||
16 | struct plugin_list *plugin_list; | ||
17 | }; | ||
18 | |||
19 | int trace_event__init(struct trace_event *t); | ||
20 | void trace_event__cleanup(struct trace_event *t); | ||
13 | 21 | ||
14 | int bigendian(void); | 22 | int bigendian(void); |
15 | 23 | ||
16 | struct pevent *read_trace_init(int file_bigendian, int host_bigendian); | ||
17 | void event_format__print(struct event_format *event, | 24 | void 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); | |||
27 | void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size); | 34 | void parse_proc_kallsyms(struct pevent *pevent, char *file, unsigned int size); |
28 | void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size); | 35 | void parse_ftrace_printk(struct pevent *pevent, char *file, unsigned int size); |
29 | 36 | ||
30 | ssize_t trace_report(int fd, struct pevent **pevent, bool repipe); | 37 | ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe); |
31 | 38 | ||
32 | struct event_format *trace_find_next_event(struct pevent *pevent, | 39 | struct event_format *trace_find_next_event(struct pevent *pevent, |
33 | struct event_format *event); | 40 | struct event_format *event); |