Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] trace-cmd: Add more ways to view options
@ 2021-04-16 17:23 Steven Rostedt
  2021-04-16 17:23 ` [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Steven Rostedt @ 2021-04-16 17:23 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

When testing the func-norepeats patch series from Yordan, I wanted a way
to see what options were enabled for all tracers without having to
enable a tracer first.

Change trace-cmd list to look at the options in the options directory
instead of the trace_options file, as the trace_options file only shows
the options for the current tracer and global options. The options
directory shows all options since Linux 4.4.

Add -o to stat to display the options, as stat lets you see instances
where as list does not.

Steven Rostedt (VMware) (3):
  trace-cmd list: Have -o read the options directory instead of file
  trace-cmd stat: Update the usage and man pages
  trace-cmd stat: Add -o option to show options

 Documentation/trace-cmd/trace-cmd-stat.1.txt | 16 +++++-
 tracecmd/include/trace-local.h               |  1 +
 tracecmd/trace-list.c                        | 58 ++++++++++++++++++--
 tracecmd/trace-stat.c                        | 14 ++++-
 tracecmd/trace-usage.c                       |  5 +-
 5 files changed, 84 insertions(+), 10 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file
  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
  2021-04-19  4:50   ` Tzvetomir Stoyanov
  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
  2 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2021-04-16 17:23 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] trace-cmd stat: Update the usage and man pages
  2021-04-16 17:23 [PATCH 0/2] trace-cmd: Add more ways to view options Steven Rostedt
  2021-04-16 17:23 ` [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file Steven Rostedt
@ 2021-04-16 17:23 ` Steven Rostedt
  2021-04-16 17:23 ` [PATCH 3/3] trace-cmd stat: Add -o option to show options Steven Rostedt
  2 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2021-04-16 17:23 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

trace-cmd stat takes some options (-B and -t, as well as -h), but the
usage and the man pages do not display them.

Also, since 'h' was not included in the getopt(), it failed to be called.
Fix that.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/trace-cmd/trace-cmd-stat.1.txt | 12 +++++++++++-
 tracecmd/trace-stat.c                        |  2 +-
 tracecmd/trace-usage.c                       |  4 +++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/Documentation/trace-cmd/trace-cmd-stat.1.txt b/Documentation/trace-cmd/trace-cmd-stat.1.txt
index e5fccce9..1be9e609 100644
--- a/Documentation/trace-cmd/trace-cmd-stat.1.txt
+++ b/Documentation/trace-cmd/trace-cmd-stat.1.txt
@@ -7,7 +7,7 @@ trace-cmd-stat - show the status of the tracing (ftrace) system
 
 SYNOPSIS
 --------
-*trace-cmd stat*
+*trace-cmd stat* ['OPTIONS']
 
 DESCRIPTION
 -----------
@@ -45,6 +45,16 @@ system. The status that it shows is:
 
 *Error log:* Dump the content of ftrace error_log file.
 
+OPTIONS
+-------
+*-B* 'buffer-name'::
+    Display the status of a given buffer instance. May be specified more than once
+    to display the status of multiple instances.
+
+*-t*::
+    If *-B* is also specified, show the status of the top level tracing directory
+    as well as the instance(s).
+
 SEE ALSO
 --------
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
index 31127872..e640a9e5 100644
--- a/tracecmd/trace-stat.c
+++ b/tracecmd/trace-stat.c
@@ -875,7 +875,7 @@ void trace_stat (int argc, char **argv)
 	init_top_instance();
 
 	for (;;) {
-		c = getopt(argc-1, argv+1, "tB:");
+		c = getopt(argc-1, argv+1, "htB:");
 		if (c == -1)
 			break;
 		switch (c) {
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 98247074..094c6397 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -258,7 +258,9 @@ static struct usage_help usage_help[] = {
 	{
 		"stat",
 		"show the status of the running tracing (ftrace) system",
-		" %s stat"
+		" %s stat [-B buf][-t]"
+		"          -B show the status of a instance buffer\n"
+		"          -t show the top level status along with buffer specified by -B\n"
 	},
 	{
 		"split",
-- 
2.29.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] trace-cmd stat: Add -o option to show options
  2021-04-16 17:23 [PATCH 0/2] trace-cmd: Add more ways to view options Steven Rostedt
  2021-04-16 17:23 ` [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file 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 ` Steven Rostedt
  2 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2021-04-16 17:23 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

Add "-o" to trace-cmd stat to list the options that are enabled or disable
(like it does with trace-cmd list). The difference with stat is that it
allows you to see the available options for an instance, where as
trace-cmd list does not.

 trace-cmd stat -B foo -o

Will list the options that are set for instance foo.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/trace-cmd/trace-cmd-stat.1.txt |  4 ++++
 tracecmd/include/trace-local.h               |  1 +
 tracecmd/trace-list.c                        | 18 +++++++++++-------
 tracecmd/trace-stat.c                        | 14 +++++++++++---
 tracecmd/trace-usage.c                       |  3 ++-
 5 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/Documentation/trace-cmd/trace-cmd-stat.1.txt b/Documentation/trace-cmd/trace-cmd-stat.1.txt
index 1be9e609..fb800f91 100644
--- a/Documentation/trace-cmd/trace-cmd-stat.1.txt
+++ b/Documentation/trace-cmd/trace-cmd-stat.1.txt
@@ -55,6 +55,10 @@ OPTIONS
     If *-B* is also specified, show the status of the top level tracing directory
     as well as the instance(s).
 
+*-o*::
+    Display the all the options along with their values. If they start with "no", then
+    the option is disabled.
+
 SEE ALSO
 --------
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index d504ea14..bd1602eb 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -294,6 +294,7 @@ void add_instance(struct buffer_instance *instance, int cpu_count);
 void update_first_instance(struct buffer_instance *instance, int topt);
 
 void show_instance_file(struct buffer_instance *instance, const char *name);
+void show_options(const char *prefix, struct buffer_instance *buffer);
 
 struct trace_guest {
 	char *name;
diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 0ba49853..4615b322 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -255,14 +255,18 @@ static void show_tracers(void)
 	show_file("available_tracers");
 }
 
-static void show_options(void)
+void show_options(const char *prefix, struct buffer_instance *buffer)
 {
+	struct tracefs_instance *instance = buffer ? buffer->tracefs : NULL;
 	struct dirent *dent;
 	struct stat st;
 	char *path;
 	DIR *dir;
 
-	path = tracefs_get_tracing_file("options");
+	if (!prefix)
+		prefix = "";
+
+	path = tracefs_instance_get_file(instance, "options");
 	if (!path)
 		goto show_file;
 	if (stat(path, &st) < 0)
@@ -288,12 +292,12 @@ static void show_options(void)
 		ret = asprintf(&file, "options/%s", name);
 		if (ret < 0)
 			die("Failed to allocate file name");
-		ret = tracefs_instance_file_read_number(NULL, file, &val);
+		ret = tracefs_instance_file_read_number(instance, file, &val);
 		if (!ret) {
 			if (val)
-				printf("%s\n", name);
+				printf("%s%s\n", prefix, name);
 			else
-				printf("no%s\n", name);
+				printf("%sno%s\n", prefix, name);
 		}
 		free(file);
 	}
@@ -549,7 +553,7 @@ void trace_list(int argc, char **argv)
 		show_tracers();
 
 	if (options)
-		show_options();
+		show_options(NULL, NULL);
 
 	if (plug)
 		show_plugins();
@@ -575,7 +579,7 @@ void trace_list(int argc, char **argv)
 		printf("\ntracers:\n");
 		show_tracers();
 		printf("\noptions:\n");
-		show_options();
+		show_options(NULL, NULL);
 	}
 
 	return;
diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
index e640a9e5..d1003c38 100644
--- a/tracecmd/trace-stat.c
+++ b/tracecmd/trace-stat.c
@@ -835,7 +835,7 @@ static void report_traceon(struct buffer_instance *instance)
 	free(str);
 }
 
-static void stat_instance(struct buffer_instance *instance)
+static void stat_instance(struct buffer_instance *instance, bool opt)
 {
 	if (instance != &top_instance) {
 		if (instance != first_instance)
@@ -859,6 +859,10 @@ static void stat_instance(struct buffer_instance *instance)
 	report_file(instance, "set_event_pid", "", "Filtered event PIDs:\n");
 	report_file(instance, "set_ftrace_pid", "no pid",
 		    "Filtered function tracer PIDs:\n");
+	if (opt) {
+		printf("\nOptions:\n");
+		show_options("   ", instance);
+	}
 	report_traceon(instance);
 	report_file(instance, "error_log", "", "Error log:\n");
 	if (instance == &top_instance)
@@ -868,6 +872,7 @@ static void stat_instance(struct buffer_instance *instance)
 void trace_stat (int argc, char **argv)
 {
 	struct buffer_instance *instance = &top_instance;
+	bool opt = false;
 	int topt = 0;
 	int status;
 	int c;
@@ -875,7 +880,7 @@ void trace_stat (int argc, char **argv)
 	init_top_instance();
 
 	for (;;) {
-		c = getopt(argc-1, argv+1, "htB:");
+		c = getopt(argc-1, argv+1, "htoB:");
 		if (c == -1)
 			break;
 		switch (c) {
@@ -896,6 +901,9 @@ void trace_stat (int argc, char **argv)
 			topt = 1;
 			instance = &top_instance;
 			break;
+		case 'o':
+			opt = 1;
+			break;
 		default:
 			usage(argv);
 		}
@@ -904,7 +912,7 @@ void trace_stat (int argc, char **argv)
 	update_first_instance(instance, topt);
 
 	for_all_instances(instance) {
-		stat_instance(instance);
+		stat_instance(instance, opt);
 	}
 
 	if (tracecmd_stack_tracer_status(&status) >= 0) {
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 094c6397..3faa287b 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -258,9 +258,10 @@ static struct usage_help usage_help[] = {
 	{
 		"stat",
 		"show the status of the running tracing (ftrace) system",
-		" %s stat [-B buf][-t]"
+		" %s stat [-B buf][-t][-o]"
 		"          -B show the status of a instance buffer\n"
 		"          -t show the top level status along with buffer specified by -B\n"
+		"          -o list tracing options\n"
 	},
 	{
 		"split",
-- 
2.29.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file
  2021-04-16 17:23 ` [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file Steven Rostedt
@ 2021-04-19  4:50   ` Tzvetomir Stoyanov
  2021-04-19 12:16     ` Steven Rostedt
  0 siblings, 1 reply; 6+ messages in thread
From: Tzvetomir Stoyanov @ 2021-04-19  4:50 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Linux Trace Devel

On Fri, Apr 16, 2021 at 9:55 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> 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");
>  }

The libtracefs options APIs can be used, instead of walking through
the directory:

struct tracefs_options_mask *all = tracefs_options_get_supported(NULL);
struct tracefs_options_mask *enabled = tracefs_options_get_enabled(NULL);
char *name;

for (int i = 1; i < TRACEFS_OPTION_MAX; i++) {
        if (!tracefs_option_mask_is_set(all, i))
                continue;
        name = tracefs_option_name(i);
        if (!tracefs_option_mask_is_set(enabled, i))
                printf("%s\n", name);
        else
                printf("no%s\n", name);
}

>
> -
>  static void show_clocks(void)
>  {
>         char *clocks;
> --
> 2.29.2
>


-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file
  2021-04-19  4:50   ` Tzvetomir Stoyanov
@ 2021-04-19 12:16     ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2021-04-19 12:16 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Linux Trace Devel

On Mon, 19 Apr 2021 07:50:02 +0300
Tzvetomir Stoyanov <tz.stoyanov@gmail.com> wrote:

> The libtracefs options APIs can be used, instead of walking through
> the directory:

No it can't! And this just confirms my fears about using the option mask
and not actually looking at what is on the system. We need a way to see
what's on the system and not just what libtracefs knows about.

> 
> struct tracefs_options_mask *all = tracefs_options_get_supported(NULL);
> struct tracefs_options_mask *enabled = tracefs_options_get_enabled(NULL);
> char *name;
> 
> for (int i = 1; i < TRACEFS_OPTION_MAX; i++) {
>         if (!tracefs_option_mask_is_set(all, i))
>                 continue;
>         name = tracefs_option_name(i);
>         if (!tracefs_option_mask_is_set(enabled, i))
>                 printf("%s\n", name);
>         else
>                 printf("no%s\n", name);
> }

The reason I wrote this was to test the func-no-repeat option that Yordan
wrote, and was sick of going to the /sys/kernel/tracing directory and doing
it by hand.

I want to know what the kernel supports, not what libtracefs supports!

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 17:23 [PATCH 0/2] trace-cmd: Add more ways to view options Steven Rostedt
2021-04-16 17:23 ` [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file Steven Rostedt
2021-04-19  4:50   ` 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

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git