aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhltc@us.ibm.com>2009-12-16 18:25:30 -0500
committerSteven Rostedt <rostedt@goodmis.org>2009-12-17 14:43:02 -0500
commit7e35a291ee133e918078362c15de62ccdb8087c4 (patch)
tree7a20f35c0d3f17236faf38da50b906baa65ef9e2
parent2c36d9bd41b3d0f4722e322ee4b062d046bf3ec5 (diff)
trace-cmd: Start of a tracecmd swig wrapper for python
Introduce a python ctracecmd module for use in rapidly prototyping tracing applications. The interface description is provided in ctracecmd.i, it identifies which functions are available from within python. A test python script is provided as tracecmd-test.py. These bindings are expected to change significantly. Eventually I would like to wrap this automated binding with more pythonic objects, most likely including Trace and Event objects which merge the functionality of tracecmd-input, pevent, record, and event structures. This will make development of python apps much more accessible to many application developers. For now, this is mostly a proof of concept and is no where near complete. It can however open a trace file and read all the events from it, displaying them by CPU in chronological order. V2: o Simplified interface file with SWIG ifdefs in the header files V3: o Move attribute removal to interface file o Remove proxy classes and rename module to ctracecmd o Use the Makefile with a phony python target instead of swig.sh Signed-off-by: Darren Hart <dvhltc@us.ibm.com> LKML-Reference: <4B2A7878.6060209@us.ibm.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--Makefile10
-rw-r--r--ctracecmd.i17
-rw-r--r--parse-events.h2
-rw-r--r--trace-cmd.h2
-rw-r--r--tracecmd-test.py36
5 files changed, 64 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 42cb7ad..313ff99 100644
--- a/Makefile
+++ b/Makefile
@@ -83,6 +83,14 @@ plugin_mac80211.o: plugin_mac80211.c parse-events.h
83plugin_mac80211.so: plugin_mac80211.o 83plugin_mac80211.so: plugin_mac80211.o
84 $(CC) -shared -nostartfiles -o $@ $< 84 $(CC) -shared -nostartfiles -o $@ $<
85 85
86
87.PHONY: python
88python: $(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
87force: 95force:
88 96
@@ -90,4 +98,4 @@ TAGS: force
90 find . -name '*.[ch]' | xargs etags 98 find . -name '*.[ch]' | xargs etags
91 99
92clean: 100clean:
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
278void parse_set_info(struct pevent *pevent, int nr_cpus, int long_sz);
279
280void die(char *fmt, ...); 278void die(char *fmt, ...);
281void *malloc_or_die(unsigned int size); 279void *malloc_or_die(unsigned int size);
282void warning(char *fmt, ...); 280void 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,
79int tracecmd_ftrace_overrides(struct tracecmd_input *handle); 79int tracecmd_ftrace_overrides(struct tracecmd_input *handle);
80struct pevent *tracecmd_get_pevent(struct tracecmd_input *handle); 80struct 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 */
83extern __thread struct tracecmd_input *tracecmd_curr_thread_handle; 84extern __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
3from ctracecmd import *
4
5# Let's move the following into a new Trace object constructor
6filename = "trace.dat"
7trace_file = open(filename)
8handle = tracecmd_open(trace_file.fileno())
9tracecmd_read_headers(handle)
10tracecmd_init_data(handle)
11
12# These should be members, i.e. Trace.cpus
13pe = tracecmd_get_pevent(handle)
14cpus = tracecmd_cpus(handle)
15print "Trace %s contains data for %d cpus" % (filename, cpus)
16
17# FIXME: this doesn't print anything...
18tracecmd_print_events(handle)
19
20print "Cycling through the events for each CPU"
21for 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