[PATCH] trace-cmd list: Allow adding a regex to filter out showing of options
Steven Rostedt <[email protected]> Wed, 27 Aug 2025 20:41:00 -0400
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
From: "Steven Rostedt (Google)" <[email protected]> The command "trace-cmd list -o" list all the options that are enabled. Most of the time the user just wants to see a single option. Allow the -o option to take an optional parameter that will filter the options shown. Signed-off-by: Steven Rostedt (Google) <[email protected]> --- tracecmd/include/trace-local.h | 2 +- tracecmd/trace-list.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 54a1b51e..4ad07b63 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -343,7 +343,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); +void show_options(const char *prefix, struct buffer_instance *buffer, const char *re); struct trace_guest { struct tracefs_instance *instance; diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c index 073b37fb..b9e23f66 100644 --- a/tracecmd/trace-list.c +++ b/tracecmd/trace-list.c @@ -389,14 +389,22 @@ static void show_tracers(void) show_file("available_tracers"); } -void show_options(const char *prefix, struct buffer_instance *buffer) +void show_options(const char *prefix, struct buffer_instance *buffer, const char *re) { struct tracefs_instance *instance = buffer ? buffer->tracefs : NULL; struct dirent *dent; struct stat st; + regex_t reg; char *path; DIR *dir; + if (re && strlen(re)) { + if (regcomp(®, re, REG_ICASE|REG_NOSUB)) + die("invalid function regex '%s'", re); + } else { + re = NULL; + } + if (!prefix) prefix = ""; @@ -423,6 +431,9 @@ void show_options(const char *prefix, struct buffer_instance *buffer) strcmp(name, "..") == 0) continue; + if (re && regexec(®, name, 0, NULL, 0) != 0) + continue; + ret = asprintf(&file, "options/%s", name); if (ret < 0) die("Failed to allocate file name"); @@ -645,6 +656,7 @@ void trace_list(int argc, char **argv) const char *arg; const char *funcre = NULL; const char *eventre = NULL; + const char *optionre = NULL; for (i = 2; i < argc; i++) { arg = NULL; @@ -694,6 +706,7 @@ void trace_list(int argc, char **argv) break; case 'o': options = 1; + optionre = arg; show_all = 0; break; case 'f': @@ -735,7 +748,7 @@ void trace_list(int argc, char **argv) show_tracers(); if (options) - show_options(NULL, NULL); + show_options(NULL, NULL, optionre); if (plug) show_plugins(); @@ -763,7 +776,7 @@ void trace_list(int argc, char **argv) printf("\ntracers:\n"); show_tracers(); printf("\noptions:\n"); - show_options(NULL, NULL); + show_options(NULL, NULL, NULL); show_compression(); } -- 2.47.2