trace-cmd reset fixes
v3 cover trace-cmd reset fixes
[
V3 changes:
- Refactored reset_max_latency() and reset_max_latency_instance(), as Steven Rostedt suggested.
V2 changes:
- Fixed subjects of the patches.
- Refactored add_event_pid() and reset_event_pid(),
as Steven Rostedt suggested.
]
This patch series fixes "trace-cmd reset" command to restore default values of various ftrace configurations:tracng_on, trace_clock, set_event_pid and tracing_max_latency. It also fixes a segfault when the command is executed with "-a -d" options.
Tzvetomir Stoyanov (6):
trace-cmd: Fix "trace-cmd reset" command to restore "tracng_on"
trace-cmd: Fix "trace-cmd reset -a -d" segfault
trace-cmd: Fix "trace-cmd reset" command to restore default clock
trace-cmd: Reafctored add_event_pid()to utilize write_instance_file()
trace-cmd: Fix "trace-cmd reset" command to restore the default value
of set_event_pid
trace-cmd: Reafctored reset_max_latency() to utilize
write_instance_file()
Yordan Karadzhov (1):
kernel-shark: Fix a bug in ksmodel_set_next_bin_edge()
kernel-shark/src/libkshark-model.c | 9 -- tracecmd/trace-record.c | 137 ++++++++++++++++------------- 2 files changed, 75 insertions(+), 71 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/7 kernel-shark: Fix a bug in ksmodel_set_next_bin_edge()
From: Yordan Karadzhov <[email protected]>
The modification of the last bin of the model makes no sense (this is my mistake). The comment above the code that is doing this modification is partially correct, however it speaks about increasing the size of the last bin, while the code below the comment changes the lower edge of this bin. The actual increase of the size of the last bin is done in ksmodel_set_upper_edge() where the lower edge of the Upper Overflow bin gets shifted (max + 1). This effectively increases the size of the last bin.
--- kernel-shark/src/libkshark-model.c | 9 --------- 1 file changed, 9 deletions(-)
kernel-shark/src/libkshark-model.c +0 -9
@@ -266,15 +266,6 @@ static void ksmodel_set_next_bin_edge(struct kshark_trace_histo *histo,/* Calculate the beginning of the next bin. */ time = histo->min + next_bin * histo->bin_size; -/* -* The timestamp of the very last entry of the dataset can be exactly -* equal to the value of the upper edge of the range. This is very -* likely to happen when we use ksmodel_set_in_range_bining(). In this -* case we have to increase the size of the very last bin in order to -* make sure that the last entry of the dataset will fall into it. -*/ -if (next_bin == histo->n_bins -1 ) - ++time;/* * Find the index of the first entry inside * the next bin (timestamp > time).
Signature · 1 line
2.20.1
PATCH v3 2/7 trace-cmd: Fix "trace-cmd reset" command to restore "tracng_on"
In reply to Tzvetomir StoyanovThe "trace-cmd reset" command should restore ftrace to its default state. By default, "tracing/current_tracer" is "nop" and "tracing/tracing_on" is "1". This patch sets "tracing/tracing_on" to 1, when the command "trace-cmd reset" is executed.
--- tracecmd/trace-record.c | 2 ++ 1 file changed, 2 insertions(+)
tracecmd/trace-record.c +2 -0
@@ -4496,6 +4496,8 @@ void trace_reset(int argc, char **argv)clear_triggers ();tracecmd_remove_instances ();clear_func_filters (); +/* restore tracing_on to 1 */ +tracecmd_enable_tracing ();exit (0 ); }
Signature · 1 line
2.20.1
PATCH v3 3/7 trace-cmd: Fix "trace-cmd reset -a -d" segfault
In reply to Tzvetomir StoyanovThis patch fixes a segfault when "trace-cmd reset -a -d" is executed and there is at least one ftrace instance created.
--- tracecmd/trace-record.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tracecmd/trace-record.c +3 -3
@@ -4472,14 +4472,14 @@ void trace_reset(int argc, char **argv)case 'a' : last_specified_all =1 ;add_all_instances (); -for_each_instance (instance) { - instance->flags |=BUFFER_FL_KEEP ; +for_each_instance (inst) { + inst->flags |=BUFFER_FL_KEEP ; }break ;case 'd' :if (last_specified_all) {for_each_instance (inst) { - instance->flags &= ~BUFFER_FL_KEEP ; + inst->flags &= ~BUFFER_FL_KEEP ; } }else {if (is_top_instance (instance))
Signature · 1 line
2.20.1
PATCH v3 4/7 trace-cmd: Fix "trace-cmd reset" command to restore default clock
In reply to Tzvetomir StoyanovThe "trace-cmd reset" command should restore ftrace to its default state. This patch sets "tracing/trace_clock" to its default value "local", when the "trace-cmd reset" command is executed.
--- tracecmd/trace-record.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tracecmd/trace-record.c +10 -0
@@ -3793,6 +3793,14 @@ static void clear_filters(void)clear_instance_filters (instance); } +static void reset_clock (void ) +{ +struct buffer_instance *instance; + + for_all_instances(instance) + write_instance_file(instance, "trace_clock", "local", "clock"); +} +static void clear_triggers (void ) {struct buffer_instance *instance;
@@ -4494,6 +4502,8 @@ void trace_reset(int argc, char **argv)set_buffer_size ();clear_filters ();clear_triggers (); +/* set clock to "local" */ +reset_clock ();tracecmd_remove_instances ();clear_func_filters ();/* restore tracing_on to 1 */
Signature · 1 line
2.20.1
PATCH v3 5/7 trace-cmd: Reafctored add_event_pid()to utilize write_instance_file()
In reply to Tzvetomir StoyanovThis patch changes add_event_pid() to utilize write_instance_file() for writing set_event_pid instance file, instead of directly opening it.
--- tracecmd/trace-record.c | 89 +++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 47 deletions(-)
tracecmd/trace-record.c +42 -47
@@ -1094,30 +1094,64 @@ static void update_sched_events(struct buffer_instance *instance, int pid)static int open_instance_fd (struct buffer_instance *instance,const char *file,int flags); -static void add_event_pid (const char *buf,int len) +static int write_file (const char *file,const char *str,const char *type) { -struct buffer_instance *instance; +char buf[BUFSIZ ];int fd; +int ret; -for_all_instances (instance) { - fd =open_instance_fd (instance,"set_event_pid" ,O_WRONLY ); -write (fd, buf, len); + fd =open (file,O_WRONLY |O_TRUNC ); +if (fd <0 ) +die ("opening to '%s'" , file); + ret =write (fd, str,strlen (str)); +close (fd); +if (ret <0 && type) { +/* write failed */ + fd =open (file,O_RDONLY ); +if (fd <0 ) +die ("writing to '%s'" , file); +/* the filter has the error */ +while ((ret =read (fd, buf,BUFSIZ )) >0 ) +fprintf (stderr,"%.*s" , ret, buf); +die ("Failed %s of %s\n" , type, file);close (fd); } +return ret; +} + +static int +write_instance_file (struct buffer_instance *instance, +const char *file,const char *str,const char *type) +{ +char *path; +int ret; + + path =get_instance_file (instance, file); + ret =write_file (path, str, type); +tracecmd_put_tracing_file (path); + +return ret; +} + +static void add_event_pid (const char *buf) +{ +struct buffer_instance *instance; + + for_all_instances(instance) + write_instance_file(instance, "set_event_pid", buf, "event_pid"); }static void add_new_filter_pid (int pid) {struct buffer_instance *instance;char buf[100 ]; -int len;add_filter_pid (pid,0 ); - len =sprintf (buf,"%d" , pid); +sprintf (buf,"%d" , pid);update_ftrace_pid (buf,0 );if (have_set_event_pid) -return add_event_pid (buf, len); +return add_event_pid (buf); common_pid_filter =append_pid_filter (common_pid_filter,"common_pid" , pid);
@@ -1596,45 +1630,6 @@ static void reset_events(void)reset_events_instance (instance); } -static int write_file (const char *file,const char *str,const char *type) -{ -char buf[BUFSIZ ]; -int fd; -int ret; - - fd =open (file,O_WRONLY |O_TRUNC ); -if (fd <0 ) -die ("opening to '%s'" , file); - ret =write (fd, str,strlen (str)); -close (fd); -if (ret <0 && type) { -/* write failed */ - fd =open (file,O_RDONLY ); -if (fd <0 ) -die ("writing to '%s'" , file); -/* the filter has the error */ -while ((ret =read (fd, buf,BUFSIZ )) >0 ) -fprintf (stderr,"%.*s" , ret, buf); -die ("Failed %s of %s\n" , type, file); -close (fd); - } -return ret; -} - -static int -write_instance_file (struct buffer_instance *instance, -const char *file,const char *str,const char *type) -{ -char *path; -int ret; - - path =get_instance_file (instance, file); - ret =write_file (path, str, type); -tracecmd_put_tracing_file (path); - -return ret; -} -enum {STATE_NEWLINE ,STATE_SKIP ,
Signature · 1 line
2.20.1
PATCH v3 6/7 trace-cmd: Fix "trace-cmd reset" command to restore the default value of set_event_pid
In reply to Tzvetomir StoyanovThe "trace-cmd reset" command should restore ftrace to its default state. This patch sets "tracing/set_event_pid" to an empty string, when the "trace-cmd reset" command is executed.
--- tracecmd/trace-record.c | 7 +++++++ 1 file changed, 7 insertions(+)
tracecmd/trace-record.c +7 -0
@@ -3796,6 +3796,12 @@ static void reset_clock(void)write_instance_file (instance,"trace_clock" ,"local" ,"clock" ); } +static void reset_event_pid (void ) +{ +add_event_pid ("" ); +} + +static void clear_triggers (void ) {struct buffer_instance *instance;
@@ -4499,6 +4505,7 @@ void trace_reset(int argc, char **argv)clear_triggers ();/* set clock to "local" */ reset_clock (); +reset_event_pid ();tracecmd_remove_instances ();clear_func_filters ();/* restore tracing_on to 1 */
Signature · 1 line
2.20.1
PATCH v3 7/7 trace-cmd: Reafctored reset_max_latency() to utilize write_instance_file()
In reply to Tzvetomir StoyanovThis patch changes reset_max_latency() to utilize write_instance_file() for writing set_event_pid instance file, instead of directly opening it. It also changes the function to work per instance.
--- tracecmd/trace-record.c | 99 ++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 50 deletions(-)
tracecmd/trace-record.c +49 -50
@@ -814,19 +814,49 @@ static void clear_trace(void)fclose (fp); } -static void reset_max_latency (void ) +static int write_file (const char *file,const char *str,const char *type) +{ +char buf[BUFSIZ ]; +int fd; +int ret; + + fd =open (file,O_WRONLY |O_TRUNC ); +if (fd <0 ) +die ("opening to '%s'" , file); + ret =write (fd, str,strlen (str)); +close (fd); +if (ret <0 && type) { +/* write failed */ + fd =open (file,O_RDONLY ); +if (fd <0 ) +die ("writing to '%s'" , file); +/* the filter has the error */ +while ((ret =read (fd, buf,BUFSIZ )) >0 ) +fprintf (stderr,"%.*s" , ret, buf); +die ("Failed %s of %s\n" , type, file); +close (fd); + } +return ret; +} + +static int +write_instance_file (struct buffer_instance *instance, +const char *file,const char *str,const char *type) { -FILE *fp;char *path; +int ret; -/* reset the trace */ - path =tracecmd_get_tracing_file ("tracing_max_latency" ); - fp =fopen (path,"w" ); -if (!fp) -die ("writing to '%s'" , path); + path =get_instance_file (instance, file); + ret =write_file (path, str, type);tracecmd_put_tracing_file (path); -fwrite ("0" ,1 ,1 , fp); -fclose (fp); + +return ret; +} + +static void reset_max_latency (struct buffer_instance *instance) +{ +write_instance_file (instance, +"tracing_max_latency" ,"0" ,"max_latency" ); }static void add_filter_pid (int pid,int exclude)
@@ -1094,45 +1124,6 @@ static void update_sched_events(struct buffer_instance *instance, int pid)static int open_instance_fd (struct buffer_instance *instance,const char *file,int flags); -static int write_file (const char *file,const char *str,const char *type) -{ -char buf[BUFSIZ ]; -int fd; -int ret; - - fd =open (file,O_WRONLY |O_TRUNC ); -if (fd <0 ) -die ("opening to '%s'" , file); - ret =write (fd, str,strlen (str)); -close (fd); -if (ret <0 && type) { -/* write failed */ - fd =open (file,O_RDONLY ); -if (fd <0 ) -die ("writing to '%s'" , file); -/* the filter has the error */ -while ((ret =read (fd, buf,BUFSIZ )) >0 ) -fprintf (stderr,"%.*s" , ret, buf); -die ("Failed %s of %s\n" , type, file); -close (fd); - } -return ret; -} - -static int -write_instance_file (struct buffer_instance *instance, -const char *file,const char *str,const char *type) -{ -char *path; -int ret; - - path =get_instance_file (instance, file); - ret =write_file (path, str, type); -tracecmd_put_tracing_file (path); - -return ret; -} -static void add_event_pid (const char *buf) {struct buffer_instance *instance;
@@ -1931,6 +1922,14 @@ static int read_tracing_on(struct buffer_instance *instance)return ret; } +static void reset_max_latency_instance (void ) +{ +struct buffer_instance *instance; + +for_all_instances (instance) +reset_max_latency (instance); +} +void tracecmd_enable_tracing (void ) {struct buffer_instance *instance;
@@ -1941,7 +1940,7 @@ void tracecmd_enable_tracing(void)write_tracing_on (instance,1 );if (latency) -reset_max_latency (); +reset_max_latency_instance (); }void tracecmd_disable_tracing (void )
@@ -3801,7 +3800,6 @@ static void reset_event_pid(void)add_event_pid ("" ); } -static void clear_triggers (void ) {struct buffer_instance *instance;
@@ -4506,6 +4504,7 @@ void trace_reset(int argc, char **argv)/* set clock to "local" */ reset_clock ();reset_event_pid (); +reset_max_latency_instance ();tracecmd_remove_instances ();clear_func_filters ();/* restore tracing_on to 1 */
Signature · 1 line
2.20.1