diff options
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | ctracecmd.i | 17 | ||||
-rw-r--r-- | parse-events.h | 2 | ||||
-rw-r--r-- | trace-cmd.h | 2 | ||||
-rw-r--r-- | tracecmd-test.py | 36 |
5 files changed, 64 insertions, 3 deletions
@@ -83,6 +83,14 @@ plugin_mac80211.o: plugin_mac80211.c parse-events.h | |||
83 | plugin_mac80211.so: plugin_mac80211.o | 83 | plugin_mac80211.so: plugin_mac80211.o |
84 | $(CC) -shared -nostartfiles -o $@ $< | 84 | $(CC) -shared -nostartfiles -o $@ $< |
85 | 85 | ||
86 | |||
87 | .PHONY: python | ||
88 | python: $(TCMD_LIB_OBJS) trace-cmd.o trace-read.o | ||
89 | swig -Wall -python -noproxy ctracecmd.i | ||
90 | gcc -fpic -c -I/usr/include/python2.6/ -I/usr/lib/python2.6/config ctracecmd_wrap.c | ||
91 | $(CC) --shared $^ ctracecmd_wrap.o -o ctracecmd.so | ||
92 | |||
93 | |||
86 | .PHONY: force | 94 | .PHONY: force |
87 | force: | 95 | force: |
88 | 96 | ||
@@ -90,4 +98,4 @@ TAGS: force | |||
90 | find . -name '*.[ch]' | xargs etags | 98 | find . -name '*.[ch]' | xargs etags |
91 | 99 | ||
92 | clean: | 100 | clean: |
93 | $(RM) *.o *~ $(TARGETS) *.a *.so | 101 | $(RM) *.o *~ $(TARGETS) *.a *.so ctracecmd_wrap.c |
diff --git a/ctracecmd.i b/ctracecmd.i new file mode 100644 index 0000000..80fface --- /dev/null +++ b/ctracecmd.i | |||
@@ -0,0 +1,17 @@ | |||
1 | // tracecmd.i | ||
2 | %module ctracecmd | ||
3 | |||
4 | %{ | ||
5 | #include "trace-cmd.h" | ||
6 | %} | ||
7 | |||
8 | %inline %{ | ||
9 | %} | ||
10 | |||
11 | /* SWIG can't grok these, define them to nothing */ | ||
12 | #define __trace | ||
13 | #define __attribute__(x) | ||
14 | #define __thread | ||
15 | |||
16 | %include "trace-cmd.h" | ||
17 | %include "parse-events.h" | ||
diff --git a/parse-events.h b/parse-events.h index e6f5806..9a2c608 100644 --- a/parse-events.h +++ b/parse-events.h | |||
@@ -275,8 +275,6 @@ struct pevent { | |||
275 | struct format_field *bprint_buf_field; | 275 | struct format_field *bprint_buf_field; |
276 | }; | 276 | }; |
277 | 277 | ||
278 | void parse_set_info(struct pevent *pevent, int nr_cpus, int long_sz); | ||
279 | |||
280 | void die(char *fmt, ...); | 278 | void die(char *fmt, ...); |
281 | void *malloc_or_die(unsigned int size); | 279 | void *malloc_or_die(unsigned int size); |
282 | void warning(char *fmt, ...); | 280 | void warning(char *fmt, ...); |
diff --git a/trace-cmd.h b/trace-cmd.h index c5a3163..a5cc217 100644 --- a/trace-cmd.h +++ b/trace-cmd.h | |||
@@ -79,8 +79,10 @@ int tracecmd_set_cpu_to_timestamp(struct tracecmd_input *handle, | |||
79 | int tracecmd_ftrace_overrides(struct tracecmd_input *handle); | 79 | int tracecmd_ftrace_overrides(struct tracecmd_input *handle); |
80 | struct pevent *tracecmd_get_pevent(struct tracecmd_input *handle); | 80 | struct pevent *tracecmd_get_pevent(struct tracecmd_input *handle); |
81 | 81 | ||
82 | #ifndef SWIG | ||
82 | /* hack for function graph work around */ | 83 | /* hack for function graph work around */ |
83 | extern __thread struct tracecmd_input *tracecmd_curr_thread_handle; | 84 | extern __thread struct tracecmd_input *tracecmd_curr_thread_handle; |
85 | #endif | ||
84 | 86 | ||
85 | 87 | ||
86 | /* --- Creating and Writing the trace.dat file --- */ | 88 | /* --- Creating and Writing the trace.dat file --- */ |
diff --git a/tracecmd-test.py b/tracecmd-test.py new file mode 100644 index 0000000..e35523b --- /dev/null +++ b/tracecmd-test.py | |||
@@ -0,0 +1,36 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | from ctracecmd import * | ||
4 | |||
5 | # Let's move the following into a new Trace object constructor | ||
6 | filename = "trace.dat" | ||
7 | trace_file = open(filename) | ||
8 | handle = tracecmd_open(trace_file.fileno()) | ||
9 | tracecmd_read_headers(handle) | ||
10 | tracecmd_init_data(handle) | ||
11 | |||
12 | # These should be members, i.e. Trace.cpus | ||
13 | pe = tracecmd_get_pevent(handle) | ||
14 | cpus = tracecmd_cpus(handle) | ||
15 | print "Trace %s contains data for %d cpus" % (filename, cpus) | ||
16 | |||
17 | # FIXME: this doesn't print anything... | ||
18 | tracecmd_print_events(handle) | ||
19 | |||
20 | print "Cycling through the events for each CPU" | ||
21 | for cpu in range(0,cpus): | ||
22 | print "CPU", cpu | ||
23 | rec = tracecmd_read_data(handle, cpu) | ||
24 | while True: | ||
25 | if rec: | ||
26 | # these should be members of a Record object | ||
27 | pid = pevent_data_pid(pe, rec) | ||
28 | comm = pevent_data_comm_from_pid(pe, pid) | ||
29 | type = pevent_data_type(pe, rec) | ||
30 | event = pevent_data_event_from_type(pe, type) | ||
31 | print "\t%f %s: pid=%d comm=%s type=%d" % \ | ||
32 | (record_ts_get(rec), event_name_get(event), pid, comm, type) | ||
33 | |||
34 | rec = tracecmd_read_data(handle, cpu) | ||
35 | else: | ||
36 | break | ||