trace-cmd: fix python bindings
The python bindings stopped working after some changes to trace-cmd. This series addresses the bindings and python object member naming issues. With these changes, event-viewer.py and the tracecmd.py self-tests work again.
--
Darren
PATCH 3/3 trace-cmd: correct trace._handle usage in event-viewer.py
The handle member object was changed to _handle, correct the usage in event-viewer.py.
--- event-viewer.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
event-viewer.py +2 -2
@@ -66,13 +66,13 @@ class EventStore(gtk.GenericTreeModel): print "Building trace index..." index = 0 for cpu in range(0, trace.cpus): - rec = tracecmd_read_data(self.trace.handle, cpu) + rec = tracecmd_read_data(self.trace._handle, cpu) while rec: offset = record_offset_get(rec) ts = record_ts_get(rec) self.refs.append(self.EventRef(index, ts, offset, cpu)) index = index + 1 - rec = tracecmd_read_data(self.trace.handle, cpu) + rec = tracecmd_read_data(self.trace._handle, cpu) print "Loaded %d events from trace" % (index) @timing
Signature · 1 line
1.7.1
PATCH 1/3 trace-cmd: move *_tracing_file into trace-util.c
In reply to Darren HartMake tracecmd_(get|put)_tracing_file available to shared objects, such the python ctracecmd.so module generated by the SWIG mechanism.
--- trace-cmd.c | 111 +++++++++++++++++++-------------------------------------- trace-util.c | 24 ++++++++++++ 2 files changed, 61 insertions(+), 74 deletions(-)
trace-cmd.c +37 -74
@@ -55,19 +55,6 @@int silence_warnings;int show_status; -static char *get_tracing_file (const char *name); -static void put_tracing_file (char *file); - -char *tracecmd_get_tracing_file (const char *name) -{ -return get_tracing_file (name); -} - -void tracecmd_put_tracing_file (char *name) -{ -put_tracing_file (name); -} -static int tracing_on_init_val;static int rt_prio;
@@ -305,11 +292,11 @@ static void clear_trace(void)char *path;/* reset the trace */ - path =get_tracing_file ("trace" ); + path =tracecmd_get_tracing_file ("trace" ); fp =fopen (path,"w" );if (!fp)die ("writing to '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path);fwrite ("0" ,1 ,1 , fp);fclose (fp); }
@@ -320,11 +307,11 @@ static void reset_max_latency(void)char *path;/* reset the trace */ - path =get_tracing_file ("tracing_max_latency" ); + path =tracecmd_get_tracing_file ("tracing_max_latency" ); fp =fopen (path,"w" );if (!fp)die ("writing to '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path);fwrite ("0" ,1 ,1 , fp);fclose (fp); }
@@ -335,7 +322,7 @@ static void update_ftrace_pid(const char *pid)int ret;int fd; - path =get_tracing_file ("set_ftrace_pid" ); + path =tracecmd_get_tracing_file ("set_ftrace_pid" );if (!path)return ;
@@ -399,30 +386,6 @@ void run_cmd(int argc, char **argv)waitpid (pid, &status,0 ); } -static char *get_tracing_file (const char *name) -{ -static const char *tracing; -char *file; - -if (!tracing) { - tracing =tracecmd_find_tracing_dir (); -if (!tracing) -die ("Can't find tracing dir" ); - } - - file =malloc_or_die (strlen (tracing) +strlen (name) +2 ); -if (!file) -return NULL ; - -sprintf (file,"%s/%s" , tracing, name); -return file; -} - -static void put_tracing_file (char *file) -{ -free (file); -} -static void show_events (void ) {char buf[BUFSIZ ];
@@ -430,11 +393,11 @@ static void show_events(void)FILE *fp;size_t n; - path =get_tracing_file ("available_events" ); + path =tracecmd_get_tracing_file ("available_events" ); fp =fopen (path,"r" );if (!fp)die ("reading %s" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path); do { n = fread(buf, 1, BUFSIZ, fp);
@@ -451,11 +414,11 @@ static void show_plugins(void)FILE *fp;size_t n; - path =get_tracing_file ("available_tracers" ); + path =tracecmd_get_tracing_file ("available_tracers" ); fp =fopen (path,"r" );if (!fp)die ("reading %s" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path); do { n = fread(buf, 1, BUFSIZ, fp);
@@ -470,11 +433,11 @@ static void set_plugin(const char *name)FILE *fp;char *path; - path =get_tracing_file ("current_tracer" ); + path =tracecmd_get_tracing_file ("current_tracer" ); fp =fopen (path,"w" );if (!fp)die ("writing to '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path);fwrite (name,1 ,strlen (name), fp);fclose (fp);
@@ -487,11 +450,11 @@ static void show_options(void)FILE *fp;size_t n; - path =get_tracing_file ("trace_options" ); + path =tracecmd_get_tracing_file ("trace_options" ); fp =fopen (path,"r" );if (!fp)die ("reading %s" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path); do { n = fread(buf, 1, BUFSIZ, fp);
@@ -516,11 +479,11 @@ static void set_option(const char *option)FILE *fp;char *path; - path =get_tracing_file ("trace_options" ); + path =tracecmd_get_tracing_file ("trace_options" ); fp =fopen (path,"w" );if (!fp)die ("writing to '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path);fwrite (option,1 ,strlen (option), fp);fclose (fp);
@@ -548,11 +511,11 @@ static void old_update_events(const char *name, char update) name ="*:*" ;/* need to use old way */ - path =get_tracing_file ("set_event" ); + path =tracecmd_get_tracing_file ("set_event" ); fp =fopen (path,"w" );if (!fp)die ("opening '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path);/* Disable the event with "!" */ if (update =='0' )
@@ -611,13 +574,13 @@ static int update_glob(const char *name, const char *filter, len =strlen (name) +strlen ("events//enable" ) +1 ; str =malloc_or_die (len);snprintf (str, len,"events/%s/enable" , name); - path =get_tracing_file (str); + path =tracecmd_get_tracing_file (str);free (str); globbuf.gl_offs =0 ;printf ("path = %s\n" , path); ret =glob (path,GLOB_ONLYDIR ,NULL , &globbuf); -put_tracing_file (path); +tracecmd_put_tracing_file (path);if (ret <0 )return 0 ;
@@ -660,11 +623,11 @@ static void filter_all_systems(const char *filter)int ret;int i; - path =get_tracing_file ("events/*/filter" ); + path =tracecmd_get_tracing_file ("events/*/filter" ); globbuf.gl_offs =0 ; ret =glob (path,0 ,NULL , &globbuf); -put_tracing_file (path); +tracecmd_put_tracing_file (path);if (ret <0 )die ("No filters found" );
@@ -689,12 +652,12 @@ static void update_event(const char *name, const char *filter,int ret2;/* Check if the kernel has the events/enable file */ - path =get_tracing_file ("events/enable" ); + path =tracecmd_get_tracing_file ("events/enable" ); ret =stat (path, &st);if (ret <0 ) {if (filter_only)return ; -put_tracing_file (path); +tracecmd_put_tracing_file (path);/* old kernel */ old_update_events (name, update);return ;
@@ -713,14 +676,14 @@ static void update_event(const char *name, const char *filter,filter_all_systems ("0" );if (filter_only) { -put_tracing_file (path); +tracecmd_put_tracing_file (path);return ; } fp =fopen (path,"w" );if (!fp)die ("writing to '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path); ret =fwrite (&update,1 ,1 , fp);fclose (fp);if (ret <0 )
@@ -740,7 +703,7 @@ static void update_event(const char *name, const char *filter,if (!strlen (ptr) ||strcmp (ptr,"*" ) ==0 ) { ret =update_glob (str, filter, filter_only, update);free (str); -put_tracing_file (path); +tracecmd_put_tracing_file (path);if (!ret) goto fail;return ;
@@ -785,9 +748,9 @@ static void check_tracing_enabled(void)char *path;if (fd <0 ) { - path =get_tracing_file ("tracing_enabled" ); + path =tracecmd_get_tracing_file ("tracing_enabled" ); fd =open (path,O_WRONLY ); -put_tracing_file (path); +tracecmd_put_tracing_file (path);if (fd <0 )return ;
@@ -805,11 +768,11 @@ static int open_tracing_on(void)if (fd >=0 )return fd; - path =get_tracing_file ("tracing_on" ); + path =tracecmd_get_tracing_file ("tracing_on" ); fd =open (path,O_RDWR );if (fd <0 )die ("opening '%s'" , path); -put_tracing_file (path); +tracecmd_put_tracing_file (path); tracing_on_fd = fd;return fd;
@@ -892,7 +855,7 @@ static void update_filter(const char *event_name, const char *field, strlen("events//filter") + 1);sprintf (filter_name,"events/%s/filter" , event_name); - path =get_tracing_file (filter_name); + path =tracecmd_get_tracing_file (filter_name);free (filter_name);/* Ignore if file does not exist */
@@ -928,7 +891,7 @@ static void update_filter(const char *event_name, const char *field,free (filter); out: -put_tracing_file (path); +tracecmd_put_tracing_file (path); }static void update_pid_event_filters (const char *pid)
@@ -1321,7 +1284,7 @@ static int trace_empty(void)* that is without a '#' the trace is not empty. * Otherwise it is. */ - path =get_tracing_file ("trace" ); + path =tracecmd_get_tracing_file ("trace" ); fp =fopen (path,"r" );if (!fp)die ("reading '%s'" , path);
@@ -1334,7 +1297,7 @@ static int trace_empty(void) } }while (line && n >0 ); -put_tracing_file (path); +tracecmd_put_tracing_file (path);fclose (fp);
@@ -1347,7 +1310,7 @@ static void write_func_file(const char *file, struct func_list **list)char *path;int fd; - path =get_tracing_file (file); + path =tracecmd_get_tracing_file (file); fd =open (path,O_WRONLY |O_TRUNC );if (fd <0 )
@@ -1363,7 +1326,7 @@ static void write_func_file(const char *file, struct func_list **list)close (fd); free: -put_tracing_file (path); +tracecmd_put_tracing_file (path); }static void set_funcs (void )
@@ -1398,7 +1361,7 @@ void set_buffer_size(void)snprintf (buf,BUFSIZ ,"%d" , buffer_size); - path =get_tracing_file ("buffer_size_kb" ); + path =tracecmd_get_tracing_file ("buffer_size_kb" ); fd =open (path,O_WRONLY );if (fd <0 )die ("can't open %s" , path);
trace-util.c +24 -0
@@ -830,3 +830,27 @@ void tracecmd_unload_plugins(struct plugin_list *plugin_list)free (list); } } + +char *tracecmd_get_tracing_file (const char *name) +{ +static const char *tracing; +char *file; + +if (!tracing) { + tracing =tracecmd_find_tracing_dir (); +if (!tracing) +die ("Can't find tracing dir" ); + } + + file =malloc_or_die (strlen (tracing) +strlen (name) +2 ); +if (!file) +return NULL ; + +sprintf (file,"%s/%s" , tracing, name); +return file; +} + +void tracecmd_put_tracing_file (char *name) +{ +free (name); +}
Signature · 1 line
1.7.1
PATCH 2/3 trace-cmd: move trace-usage to lib objects
In reply to Darren HartMake the usage function available to shared objects, such as the python ctracecmd.so module built by the SWIG mechanism.
--- Makefile | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
Makefile +2 -3
@@ -261,8 +261,7 @@ $(obj)/%.o: $(src)/%.c TRACE_GUI_OBJS = trace-filter.o trace-compat.o trace-hash.o trace-dialog.o \ trace-xml.o -TRACE_CMD_OBJS = trace-cmd.o trace-usage.o trace-read.o trace-split.o trace-listen.o \ - trace-stack.o +TRACE_CMD_OBJS = trace-cmd.o trace-read.o trace-split.o trace-listen.o trace-stack.o TRACE_VIEW_OBJS = trace-view.o trace-view-store.o TRACE_GRAPH_OBJS = trace-graph.o trace-plot.o trace-plot-cpu.o trace-plot-task.o TRACE_VIEW_MAIN_OBJS = trace-view-main.o $(TRACE_VIEW_OBJS) $(TRACE_GUI_OBJS)
@@ -272,7 +271,7 @@ KERNEL_SHARK_OBJS = $(TRACE_VIEW_OBJS) $(TRACE_GRAPH_OBJS) $(TRACE_GUI_OBJS) \ PEVENT_LIB_OBJS = parse-events.o trace-seq.o parse-filter.o parse-utils.o TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \ - trace-output.o trace-record.o trace-restore.o + trace-output.o trace-record.o trace-restore.o trace-usage.o PLUGIN_OBJS = plugin_hrtimer.o plugin_kmem.o plugin_sched_switch.o \ plugin_mac80211.o plugin_jbd2.o plugin_function.o plugin_kvm.o
Signature · 1 line
1.7.1
Steven Rostedt
AppliedQuoted 3 lines · Darren Hart
The python bindings stopped working after some changes to trace-cmd. This series addresses the bindings and python object member naming issues. With these changes,
event-viewer.pyand thetracecmd.pyself-tests work again.
Applied,
Thanks Darren!
-- Steve