Message ID | 20210416172331.3870833-2-rostedt@goodmis.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | trace-cmd: Add more ways to view options | expand |
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 >
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
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;