Skip to contentSkip to conversation

Extend coverage of "trace-cmd reset" command

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 4 messages Apr 14, 2020

lore
Share & tools
lore
#0 lore raw

v5 cover Extend coverage of "trace-cmd reset" command

The "trace-cmd reset" command is supposed to set the ftrace state to default. However, some ftrace configurations are not reseted: synthetic events and error_log file. The command is extended to clean these.
Two new tracefs APIs were also implemented, to check if given ftrace file / directory exists:
bool tracefs_file_exist(struct tracefs_instance *instance, char *name); bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);

[
v5 changes:
Removed accepted patches from the set
Address Steven's comments
v4 chanegs:
Implemented new tracefs APIs to check if given ftrace file / directory exists. Use the new APIs to check if synthetic_events and error_log files exist, before accessing them.
v3 changes:
Remove the warning in case there are no configured synthetic events.
v2 changes:
Removed these patches from the "SQL-like syntax for ftrace histograms configuration" patch set, as they are not directly related to it.
]

Tzvetomir Stoyanov (VMware) (3):
trace-cmd: Add new tracefs APIs for checking if a ftrace file /
directory exists
trace-cmd: Unit tests for new libtracefs APIs
trace-cmd: Clear error log on reset subcommand

 include/tracefs/tracefs.h      |  3 +++
 lib/tracefs/tracefs-instance.c | 46 +++++++++++++++++++++++++++++++++-
 tracecmd/trace-record.c        | 23 +++++++++++++++++
 utest/tracefs-utest.c          | 16 ++++++++++++
 4 files changed, 87 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/3 trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists

Some ftrace files and directories are optional, depending on specific kernel configuration or version. It is a good practice to check if the file / directory exist, before trying to access it.
There are a lot of places in trace-cmd implementation with such checks. The new libtracefs APIs can be used for this, they are ftarce instance aware:
bool tracefs_file_exist(struct tracefs_instance *instance, char *name); bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);

---
 include/tracefs/tracefs.h      |  3 +++
 lib/tracefs/tracefs-instance.c | 46 +++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)
include/tracefs/tracefs.h +3 -0
index 85690b66..bc8bebcb 100644
@@ -33,6 +33,9 @@ int tracefs_instance_file_write(struct tracefs_instance *instance,
 char *tracefs_instance_file_read(struct tracefs_instance *instance,
 				 char *file, int *psize);
 
+bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
+bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);
+
 /* events */
 void tracefs_list_free(char **list);
 char **tracefs_event_systems(const char *tracing_dir);
lib/tracefs/tracefs-instance.c +45 -1

55 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH v5 2/3 trace-cmd: Unit tests for new libtracefs APIs

In reply to Tzvetomir Stoyanov (VMware)

Unit tests for tracefs APIs, checking for ftrace file / directory existence:
bool tracefs_file_exist(struct tracefs_instance *instance, char *name); bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);

---
 utest/tracefs-utest.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
utest/tracefs-utest.c +16 -0
index 2473e893..3f57ecad 100644
@@ -175,6 +175,7 @@ static void test_instance_file_read(struct tracefs_instance *inst, char *fname)
 
 #define ALL_TRACERS	"available_tracers"
 #define CUR_TRACER	"current_tracer"
+#define PER_CPU		"per_cpu"
 static void test_instance_file(void)
 {
 	struct tracefs_instance *instance = NULL;
@@ -251,6 +252,21 @@ static void test_instance_file(void)
 	tracefs_put_tracing_file(inst_file);
 	free(fname);
 
+	CU_TEST(tracefs_file_exist(NULL, (char *)name) == false);
+	CU_TEST(tracefs_dir_exist(NULL, (char *)name) == false);
+	CU_TEST(tracefs_file_exist(instance, (char *)name) == false);
+	CU_TEST(tracefs_dir_exist(instance, (char *)name) == false);
+
+	CU_TEST(tracefs_file_exist(NULL, CUR_TRACER) == true);
+	CU_TEST(tracefs_dir_exist(NULL, CUR_TRACER) == false);
+	CU_TEST(tracefs_file_exist(instance, CUR_TRACER) == true);
+	CU_TEST(tracefs_dir_exist(instance, CUR_TRACER) == false);
+
+	CU_TEST(tracefs_file_exist(NULL, PER_CPU) == false);
+	CU_TEST(tracefs_dir_exist(NULL, PER_CPU) == true);
+	CU_TEST(tracefs_file_exist(instance, PER_CPU) == false);
+	CU_TEST(tracefs_dir_exist(instance, PER_CPU) == true);
+
 	CU_TEST(tracefs_instance_destroy(NULL) != 0);
 	CU_TEST(tracefs_instance_destroy(instance) == 0);
 	CU_TEST(tracefs_instance_destroy(instance) != 0);
Signature · 1 line
2.25.1
#3 lore raw

PATCH v5 3/3 trace-cmd: Clear error log on reset subcommand

In reply to 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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
tracecmd/trace-record.c +23 -0
index 1b3f403f..349a5596 100644
@@ -4820,6 +4820,28 @@ static void clear_triggers(void)
 		clear_instance_triggers(instance);
 }
 
+static void clear_instance_error_log(struct buffer_instance *instance)
+{
+	char *file;
+
+	if (!tracefs_file_exist(instance->tracefs, "error_log"))
+		return;
+
+	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];
@@ -5564,6 +5586,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.25.1