tracecmd: Add initial python tracecmd API
PATCH 1/1 tracecmd: Add initial python tracecmd API
Quoted 1 line
From
31d6e865d4cdcd2ba7583bfefb9aa4df090d383dMon Sep 17 00:00:00 2001
From: Darren Hart <[email protected]>
Date: Thu, 17 Dec 2009 13:07:34 -0800
Subject: [PATCH] tracecmd: Add initial python tracecmd API
Add an object oriented python API in a new tracecmd.py module. This module contains a self test that duplicates the behavior of the tracecmd-test.py, so it has been removed.
This API is far from complete and only implements enough functionality to list the events on each CPU.
SWIG doesn't handle long longs so we have to add a wrapper, a typemapper, and a marshaller to get a 64bit integer out of the record data. This is a first take, comments welcome. We'll need to do something similar with the timestamp values.
--- ctracecmd.i | 15 ++++++ tracecmd-test.py | 36 -------------- tracecmd.py | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 36 deletions(-) delete mode 100755 tracecmd-test.py create mode 100644 tracecmd.py
ctracecmd.i +15 -0
@@ -1,13 +1,28 @@ // tracecmd.i %module ctracecmd +%include typemaps.i %{ #include "trace-cmd.h" %} +/* typemaps must come before the implementation of wrapped functions */ +extern int pevent_read_number_field_32(struct format_field *f, void *data, + unsigned long *OUTPUT, unsigned long *OUTPUT); + %inline %{ +int pevent_read_number_field_32(struct format_field *f, void *data, unsigned long *hi, unsigned long *lo) +{ + unsigned long long val64; + int ret; + ret = pevent_read_number_field(f, data, &val64); + *hi = (unsigned long)(val64>>32); + *lo = (unsigned long)((val64<<32)>>32); + return ret; +} %} + /* SWIG can't grok these, define them to nothing */ #define __trace #define __attribute__(x)
tracecmd-test.py deleted +0 -36
@@ -1,36 +0,0 @@ -#!/usr/bin/env python - -from ctracecmd import * - -# Let's move the following into a new Trace object constructor -filename = "trace.dat" -trace_file = open(filename) -handle = tracecmd_open(trace_file.fileno()) -tracecmd_read_headers(handle) -tracecmd_init_data(handle) - -# These should be members, i.e. Trace.cpus -pe = tracecmd_get_pevent(handle) -cpus = tracecmd_cpus(handle) -print "Trace %s contains data for %d cpus" % (filename, cpus) - -# FIXME: this doesn't print anything... -tracecmd_print_events(handle) - -print "Cycling through the events for each CPU" -for cpu in range(0,cpus): - print "CPU", cpu - rec = tracecmd_read_data(handle, cpu) - while True: - if rec: - # these should be members of a Record object - pid = pevent_data_pid(pe, rec) - comm = pevent_data_comm_from_pid(pe, pid) - type = pevent_data_type(pe, rec) - event = pevent_data_event_from_type(pe, type) - print "\t%f %s: pid=%d comm=%s type=%d" % \ - (record_ts_get(rec), event_name_get(event), pid, comm, type) - - rec = tracecmd_read_data(handle, cpu) - else: - break
tracecmd.py new file +135 -0
135 lines not on this page · raw message
Signature · 5 lines
1.6.3.3 -- Darren Hart IBM Linux Technology Center Real-Time Linux Team