Skip to contentSkip to conversation

trace-cmd: Clear error log on reset subcommand

PATCH Superseded Tzvetomir Stoyanov (VMware) 2 participants 2 messages Feb 19, 2020 – Feb 24, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 trace-cmd: Clear error log on reset subcommand

The "trace-cmd reset" command is supposed to set the ftrace state to default. However, the ftrace error logs are not reseted.
A logic is added to delete the content of "error_log" file when "trace-cmd reset" is executed.

---
 tracecmd/trace-record.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tracecmd/trace-record.c +20 -0
index b6a412e..3e0d066 100644
@@ -4638,6 +4638,25 @@ static void clear_triggers(void)
 		clear_instance_triggers(instance);
 }
 
+static void clear_instance_error_log(struct buffer_instance *instance)
+{
+	char *file;
+
+	file = tracefs_instance_get_file(instance->tracefs, "error_log");
+	if (!file)
+		return;
+	write_file(file, " ");
+	tracefs_put_tracing_file(file);
+}
+
+static void clear_error_log(void)
+{
+	struct buffer_instance *instance;
+
+	for_all_instances(instance)
+		clear_instance_error_log(instance);
+}
+
 static void clear_all_synth_events(void)
 {
 	char sevent[BUFSIZ];
@@ -5382,6 +5401,7 @@ void trace_reset(int argc, char **argv)
 	clear_filters();
 	clear_triggers();
 	clear_all_synth_events();
+	clear_error_log();
 	/* set clock to "local" */
 	reset_clock();
 	reset_event_pid();
Signature · 1 line
2.24.1
#1 lore raw
Quoted 17 lines · On Wed, 19 Feb 2020 15:14:10 +0200 "Tzvetomir Stoyanov (VMware)"…

The "trace-cmd reset" command is supposed to set the ftrace state to default. However, the ftrace error logs are not reseted.
A logic is added to delete the content of "error_log" file when "trace-cmd reset" is executed.

---
 tracecmd/trace-record.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tracecmd/trace-record.c +0 -0
index b6a412e..3e0d066 100644
@@ -4638,6 +4638,25 @@ static void clear_triggers(void)
 		clear_instance_triggers(instance);
 }
 

tracecmd/trace-record.c static void clear_triggers(void) · line 4650

Quoted 10 lines
tracecmd/trace-record.c +10 -0
+static void clear_instance_error_log(struct buffer_instance *instance)
+{
+	char *file;
+
+	file = tracefs_instance_get_file(instance->tracefs, "error_log");
+	if (!file)
+		return;
+	write_file(file, " ");
+	tracefs_put_tracing_file(file);
+}

The error_log file is not guaranteed to exist. Please add a check for existence via stat() (hmm, perhaps we should make a file_exists() helper function). Otherwise I get this:

# trace-cmd reset
trace-cmd: No such file or directory
  opening to '/debug/tracing/error_log'
Quoted 20 lines
tracecmd/trace-record.c +10 -0
+
+static void clear_error_log(void)
+{
+	struct buffer_instance *instance;
+
+	for_all_instances(instance)
+		clear_instance_error_log(instance);
+}
+
 static void clear_all_synth_events(void)
 {
 	char sevent[BUFSIZ];
@@ -5382,6 +5401,7 @@ void trace_reset(int argc, char **argv)
 	clear_filters();
 	clear_triggers();
 	clear_all_synth_events();
+	clear_error_log();
 	/* set clock to "local" */
 	reset_clock();
 	reset_event_pid();