trace-cmd: Add more ways to view options
cover trace-cmd: Add more ways to view options
From: "Steven Rostedt (VMware)" <[email protected]>
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(-)
Signature · 1 line
2.29.2
PATCH 1/3 trace-cmd list: Have -o read the options directory instead of file
From: "Steven Rostedt (VMware)" <[email protected]>
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.
--- tracecmd/trace-list.c | 48 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)
tracecmd/trace-list.c +46 -2
@@ -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;
Signature · 1 line
2.29.2
Re: [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file
Quoted 65 lines · Steven Rostedt
From: "Steven Rostedt (VMware)" <[email protected]>
The
trace_optionsfile 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_optionsfile.Signed-off-by Steven Rostedt (VMware) <[email protected]>--- tracecmd/trace-list.c | 48 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)tracecmd/trace-list.c +38
-1@@ -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); + }
tracecmd/trace-list.c static void show_tracers(void) · line 307
Quoted 10 lines
tracecmd/trace-list.c +8
-0+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);
}Quoted 8 lines
tracecmd/trace-list.c +0
-2-static void show_clocks (void ) {char *clocks; --2.29.2
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
Re: [PATCH 1/3] trace-cmd list: Have -o read the options directory instead of file
Quoted 2 lines · On Mon, 19 Apr 2021 07:50:02 +0300 Tzvetomir Stoyanov <[email protected]>…
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.
Quoted 5 lines
struct
tracefs_options_mask*all =tracefs_options_get_supported(NULL); structtracefs_options_mask*enabled =tracefs_options_get_enabled(NULL); char *name;
Quoted 9 lines
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
PATCH 2/3 trace-cmd stat: Update the usage and man pages
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
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.
--- 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(-)
Documentation/trace-cmd/trace-cmd-stat.1.txt +11 -1
@@ -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),
tracecmd/trace-stat.c +1 -1
@@ -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) {
tracecmd/trace-usage.c +3 -1
@@ -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",
Signature · 1 line
2.29.2
PATCH 3/3 trace-cmd stat: Add -o option to show options
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
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.
--- 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(-)
Documentation/trace-cmd/trace-cmd-stat.1.txt +4 -0
@@ -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),
tracecmd/include/trace-local.h +1 -0
@@ -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;
tracecmd/trace-list.c +11 -7
@@ -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 ;
tracecmd/trace-stat.c +11 -3
@@ -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 ) {
tracecmd/trace-usage.c +2 -1
@@ -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",
Signature · 1 line
2.29.2