trace-cmd list: Allow adding a regex to filter out showing of options
PATCH v2 1/1 trace-cmd list: Allow adding a regex to filter out showing of options
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]>
---
Changes since v1: https://lore.kernel.org/all/[email protected]/
- Fix a missed "show_options()" update
tracecmd/include/trace-local.h | 2 +- tracecmd/trace-list.c | 19 ++++++++++++++++--- tracecmd/trace-stat.c | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-)
tracecmd/include/trace-local.h +1 -1
@@ -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;
tracecmd/trace-list.c +16 -3
@@ -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 &®exec (®, 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 (); }
tracecmd/trace-stat.c +1 -1
@@ -851,7 +851,7 @@ static void stat_instance(struct buffer_instance *instance, bool opt) "Filtered function tracer notrace PIDs:\n");if (opt) {printf ("\nOptions:\n" ); -show_options (" " , instance); +show_options (" " , instance,NULL ); }report_traceon (instance);report_file (instance,"error_log" ,"" ,"Error log:\n" );
Signature · 1 line
2.50.1