[PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>

The trace_options file only shows the options that are available when a
tracer is set. This is annoying as one needs to enable the tracer in order
to see all the options that are available.

Starting with Linux v4.4, all tracers options are displayed in the options
directory. Walk through the options directory instead of simply reading
the trace_options file.

Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
 tracecmd/trace-list.c | 48 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 63216b43..0ba49853 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -255,13 +255,57 @@ static void show_tracers(void)
 	show_file("available_tracers");
 }
 
-
 static void show_options(void)
 {
+	struct dirent *dent;
+	struct stat st;
+	char *path;
+	DIR *dir;
+
+	path = tracefs_get_tracing_file("options");
+	if (!path)
+		goto show_file;
+	if (stat(path, &st) < 0)
+		goto show_file;
+
+	if ((st.st_mode & S_IFMT) != S_IFDIR)
+		goto show_file;
+
+	dir = opendir(path);
+	if (!dir)
+		die("Can not read instance directory");
+
+	while ((dent = readdir(dir))) {
+		const char *name = dent->d_name;
+		long long val;
+		char *file;
+		int ret;
+
+		if (strcmp(name, ".") == 0 ||
+		    strcmp(name, "..") == 0)
+			continue;
+
+		ret = asprintf(&file, "options/%s", name);
+		if (ret < 0)
+			die("Failed to allocate file name");
+		ret = tracefs_instance_file_read_number(NULL, file, &val);
+		if (!ret) {
+			if (val)
+				printf("%s\n", name);
+			else
+				printf("no%s\n", name);
+		}
+		free(file);
+	}
+	closedir(dir);
+	tracefs_put_tracing_file(path);
+	return;
+
+ show_file:
+	tracefs_put_tracing_file(path);
 	show_file("trace_options");
 }
 
-
 static void show_clocks(void)
 {
 	char *clocks;
-- 
2.29.2




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux