linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file
Date: Fri, 16 Apr 2021 13:23:29 -0400	[thread overview]
Message-ID: <20210416172331.3870833-2-rostedt@goodmis.org> (raw)
In-Reply-To: <20210416172331.3870833-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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@goodmis.org>
---
 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


  reply	other threads:[~2021-04-16 17:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 17:23 [PATCH 0/2] trace-cmd: Add more ways to view options Steven Rostedt
2021-04-16 17:23 ` Steven Rostedt [this message]
2021-04-19  4:50   ` [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file Tzvetomir Stoyanov
2021-04-19 12:16     ` Steven Rostedt
2021-04-16 17:23 ` [PATCH 2/3] trace-cmd stat: Update the usage and man pages Steven Rostedt
2021-04-16 17:23 ` [PATCH 3/3] trace-cmd stat: Add -o option to show options Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416172331.3870833-2-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).