trace-cmd list: Add --full to show print fmt of an event
PATCH 1/1 trace-cmd list: Add --full to show print fmt of an event
From: "Steven Rostedt (VMware)" <[email protected]>
There's several times I want to see the print fmt from the event's format file, and there's no way to do that with trace-cmd list -e. Add a --full option to display the entire format file of an event, including the print fmt, which can be useful as well.
--- Documentation/trace-cmd/trace-cmd-list.1.txt | 5 ++- tracecmd/trace-list.c | 39 ++++++++++++-------- tracecmd/trace-usage.c | 1 + 3 files changed, 28 insertions(+), 17 deletions(-)
Documentation/trace-cmd/trace-cmd-list.1.txt +4 -1
@@ -26,7 +26,10 @@ OPTIONS trace-cmd list -e '^sys.*' *-F*:: - Used with *-e* 'regex' to show those events formats. + Used with *-e* 'regex' to show the fields of the event. + +*--full*:: + Used with *-F* which will show the "print fmt" of the event along with the fields. *-l*:: Used with *-e* 'regex' to show those events filters.
tracecmd/trace-list.c +23 -16
@@ -44,6 +44,7 @@ enum {SHOW_EVENT_FORMAT =1 <<0 ,SHOW_EVENT_FILTER =1 <<1 ,SHOW_EVENT_TRIGGER =1 <<2 , + SHOW_EVENT_FULL = 1 << 3, };
@@ -56,10 +57,10 @@ void show_file(const char *name)tracefs_put_tracing_file (path); } -typedef int (*process_file_func )(char *buf,int len); +typedef int (*process_file_func )(char *buf,int len,int flags);static void process_file_re (process_file_func func, -const char *name,const char *re) +const char *name,const char *re,int flags) {regex_t reg;char *path;
@@ -84,7 +85,7 @@ static void process_file_re(process_file_func func,strcpy (&str[l-1 ],"\n*$" );if (regcomp (®, str,REG_ICASE |REG_NOSUB )) -die ("invalid function regex '%s'" , re); +die ("invalid function regex '%s'" , re, flags);free (str);
@@ -97,7 +98,7 @@ static void process_file_re(process_file_func func,do { n =getline (&buf, &l, fp);if (n >0 &®exec (®, buf,0 ,NULL ,0 ) ==0 ) -func (buf, n); +func (buf, n, flags); }while (n >0 );free (buf);fclose (fp);
@@ -105,14 +106,14 @@ static void process_file_re(process_file_func func,regfree (®); } -static int show_file_write (char *buf,int len) +static int show_file_write (char *buf,int len,int flags) {return fwrite (buf,1 , len, stdout); }static void show_file_re (const char *name,const char *re) { -process_file_re (show_file_write, name, re); +process_file_re (show_file_write, name, re,0 ); }static char *get_event_file (const char *type,char *buf,int len)
@@ -144,7 +145,7 @@ static char *get_event_file(const char *type, char *buf, int len)return file; } -static int event_filter_write (char *buf,int len) +static int event_filter_write (char *buf,int len,int flags) {char *file;
@@ -161,7 +162,7 @@ static int event_filter_write(char *buf, int len)return 0 ; } -static int event_trigger_write (char *buf,int len) +static int event_trigger_write (char *buf,int len,int flags) {char *file;
@@ -178,14 +179,17 @@ static int event_trigger_write(char *buf, int len)return 0 ; } -static int event_format_write (char *fbuf,int len) +static int event_format_write (char *fbuf,int len,int flags) {char *file =get_event_file ("format" , fbuf, len);char *buf =NULL ;size_t l;FILE *fp; +bool full;int n; + full = flags &SHOW_EVENT_FULL ; +/* The get_event_file() crops system in fbuf */ printf ("system: %s\n" , fbuf);
@@ -198,7 +202,7 @@ static int event_format_write(char *fbuf, int len) do { n = getline(&buf, &l, fp); if (n > 0) { - if (strncmp(buf, "print fmt", 9) == 0) + if (!full && strncmp(buf, "print fmt", 9) == 0) break; fwrite(buf, 1, n, stdout); }
@@ -213,19 +217,19 @@ static int event_format_write(char *fbuf, int len)static void show_event_filter_re (const char *re) { -process_file_re (event_filter_write,"available_events" , re); +process_file_re (event_filter_write,"available_events" , re,0 ); }static void show_event_trigger_re (const char *re) { -process_file_re (event_trigger_write,"available_events" , re); +process_file_re (event_trigger_write,"available_events" , re,0 ); } -static void show_event_format_re (const char *re) +static void show_event_format_re (const char *re,int flags) { -process_file_re (event_format_write,"available_events" , re); +process_file_re (event_format_write,"available_events" , re, flags); }
@@ -236,7 +240,7 @@ static void show_events(const char *eventre, int flags)if (eventre) {if (flags &SHOW_EVENT_FORMAT ) -show_event_format_re (eventre); +show_event_format_re (eventre, flags);else if (flags &SHOW_EVENT_FILTER )show_event_filter_re (eventre);
@@ -453,7 +457,6 @@ static void show_plugins(void)tep_free (pevent); } -void trace_list (int argc,char **argv) {int events =0 ;
@@ -536,6 +539,10 @@ void trace_list(int argc, char **argv)tracecmd_set_debug (true);break ; } +if (strcmp (argv[i],"--full" ) ==0 ) { + flags |=SHOW_EVENT_FULL ; +break ; + }fprintf (stderr,"list: invalid option -- '%s'\n" , argv[i]);default :
tracecmd/trace-usage.c +1 -0
@@ -322,6 +322,7 @@ static struct usage_help usage_help[] = {" %s list [-e [regex]][-t][-o][-f [regex]]\n" " -e list available events\n" " -F show event format\n" +" --full show the print fmt with -F\n" " -R show event triggers\n" " -l show event filters\n" " -t list available tracers\n"
Signature · 1 line
2.29.2
Quoted 56 lines · Steven Rostedt
From: "Steven Rostedt (VMware)" <[email protected]>
There's several times I want to see the print fmt from the event's format file, and there's no way to do that with trace-cmd list -e. Add a --full option to display the entire format file of an event, including the print fmt, which can be useful as well.
Signed-off-by Steven Rostedt (VMware) <[email protected]>---
Documentation/trace-cmd/trace-cmd-list.1.txt | 5 ++- tracecmd/trace-list.c | 39 ++++++++++++-------- tracecmd/trace-usage.c | 1 + 3 files changed, 28 insertions(+), 17 deletions(-)Documentation/trace-cmd/trace-cmd-list.1.txt +4
-1@@ -26,7 +26,10 @@ OPTIONS trace-cmd list -e '^sys.*' *-F*:: - Used with *-e* 'regex' to show those events formats. + Used with *-e* 'regex' to show the fields of the event. + +*--full*:: + Used with *-F* which will show the "print fmt" of the event along with the fields. *-l*:: Used with *-e* 'regex' to show those events filters.tracecmd/trace-list.c +3
-2@@ -44,6 +44,7 @@ enum {SHOW_EVENT_FORMAT =1 <<0 ,SHOW_EVENT_FILTER =1 <<1 ,SHOW_EVENT_TRIGGER =1 <<2 , + SHOW_EVENT_FULL = 1 << 3, };@@ -56,10 +57,10 @@ void show_file(const char *name)tracefs_put_tracing_file (path); } -typedef int (*process_file_func )(char *buf,int len); +typedef int (*process_file_func )(char *buf,int len,int flags);static void process_file_re (process_file_func func, -const char *name,const char *re) +const char *name,const char *re,int flags) {regex_t reg;char *path;
tracecmd/trace-list.c static void process_file_re(process_file_func func, · line 88
Quoted 5 lines
tracecmd/trace-list.c +1
-1@@ -84,7 +85,7 @@ static void process_file_re(process_file_func func,strcpy (&str[l-1 ],"\n*$" );if (regcomp (®, str,REG_ICASE |REG_NOSUB )) -die ("invalid function regex '%s'" , re); +die ("invalid function regex '%s'" , re, flags);
Shouldn't we add flags inside the fmt string?:
die("invalid function regex '%s' with '%d' as flags", re, flags);Quoted 141 lines
tracecmd/trace-list.c +19
-13free (str);@@ -97,7 +98,7 @@ static void process_file_re(process_file_func func,do { n =getline (&buf, &l, fp);if (n >0 &®exec (®, buf,0 ,NULL ,0 ) ==0 ) -func (buf, n); +func (buf, n, flags); }while (n >0 );free (buf);fclose (fp);@@ -105,14 +106,14 @@ static void process_file_re(process_file_func func,regfree (®); } -static int show_file_write (char *buf,int len) +static int show_file_write (char *buf,int len,int flags) {return fwrite (buf,1 , len, stdout); }static void show_file_re (const char *name,const char *re) { -process_file_re (show_file_write, name, re); +process_file_re (show_file_write, name, re,0 ); }static char *get_event_file (const char *type,char *buf,int len)@@ -144,7 +145,7 @@ static char *get_event_file(const char *type, char *buf, int len)return file; } -static int event_filter_write (char *buf,int len) +static int event_filter_write (char *buf,int len,int flags) {char *file;@@ -161,7 +162,7 @@ static int event_filter_write(char *buf, int len)return 0 ; } -static int event_trigger_write (char *buf,int len) +static int event_trigger_write (char *buf,int len,int flags) {char *file;@@ -178,14 +179,17 @@ static int event_trigger_write(char *buf, int len)return 0 ; } -static int event_format_write (char *fbuf,int len) +static int event_format_write (char *fbuf,int len,int flags) {char *file =get_event_file ("format" , fbuf, len);char *buf =NULL ;size_t l;FILE *fp; +bool full;int n; + full = flags &SHOW_EVENT_FULL ; +/* The get_event_file() crops system in fbuf */ printf ("system: %s\n" , fbuf);@@ -198,7 +202,7 @@ static int event_format_write(char *fbuf, int len) do { n = getline(&buf, &l, fp); if (n > 0) { - if (strncmp(buf, "print fmt", 9) == 0) + if (!full && strncmp(buf, "print fmt", 9) == 0) break; fwrite(buf, 1, n, stdout); }@@ -213,19 +217,19 @@ static int event_format_write(char *fbuf, int len)static void show_event_filter_re (const char *re) { -process_file_re (event_filter_write,"available_events" , re); +process_file_re (event_filter_write,"available_events" , re,0 ); }static void show_event_trigger_re (const char *re) { -process_file_re (event_trigger_write,"available_events" , re); +process_file_re (event_trigger_write,"available_events" , re,0 ); } -static void show_event_format_re (const char *re) +static void show_event_format_re (const char *re,int flags) { -process_file_re (event_format_write,"available_events" , re); +process_file_re (event_format_write,"available_events" , re, flags); }@@ -236,7 +240,7 @@ static void show_events(const char *eventre, int flags)if (eventre) {if (flags &SHOW_EVENT_FORMAT ) -show_event_format_re (eventre); +show_event_format_re (eventre, flags);else if (flags &SHOW_EVENT_FILTER )show_event_filter_re (eventre);@@ -453,7 +457,6 @@ static void show_plugins(void)tep_free (pevent); } -void trace_list (int argc,char **argv) {int events =0 ;@@ -536,6 +539,10 @@ void trace_list(int argc, char **argv)tracecmd_set_debug (true);break ; } +if (strcmp (argv[i],"--full" ) ==0 ) { + flags |=SHOW_EVENT_FULL ; +break ; + }fprintf (stderr,"list: invalid option -- '%s'\n" , argv[i]);default :tracecmd/trace-usage.c +1
-0@@ -322,6 +322,7 @@ static struct usage_help usage_help[] = {" %s list [-e [regex]][-t][-o][-f [regex]]\n" " -e list available events\n" " -F show event format\n" +" --full show the print fmt with -F\n" " -R show event triggers\n" " -l show event filters\n" " -t list available tracers\n" Signature · 1 line
2.29.2
---
Nicolas Sterchele
Quoted 9 lines · On Thu, 22 Apr 2021 22:41:54 +0200 Nicolas Sterchele <[email protected]>…
tracecmd/trace-list.c static void process_file_re(process_file_func func, · line 88
Quoted 6 lines
tracecmd/trace-list.c +1
-1@@ -84,7 +85,7 @@ static void process_file_re(process_file_func func,strcpy (&str[l-1 ],"\n*$" );if (regcomp (®, str,REG_ICASE |REG_NOSUB )) -die ("invalid function regex '%s'" , re); +die ("invalid function regex '%s'" , re, flags);Shouldn't we add
flagsinside the fmt string?:die("invalid function regex '%s' with '%d' as flags", re, flags);
Nice catch, but no, flags just needs to be dropped.
The "flags" was added in a different patch, and as I was writing updates in individual patches (and not a series), I found that in some places that I had conflicts. And the patch that added "flags" all over the place I had to update accordingly.
This is simply a case of me adding ", flags" to the wrong function (*embarrassed*)!
It doesn't need to be printed, but it shouldn't be passed to die either.
One way I could have caught this was by adding the printf attribute to the die() header, where things like this will cause warnings.
Thanks for the report. I'll fix it.
-- Steve
Quoted 2 lines
Quoted 2 lines
tracecmd/trace-list.c +0
-0free (str);
Quoted 4 lines · On Thu, 22 Apr 2021 16:51:48 -0400 Steven Rostedt <[email protected]> wrote:
One way I could have caught this was by adding the printf attribute to the
die()header, where things like this will cause warnings.Thanks for the report. I'll fix it.
You'll probably notice that this fix is not in my "die" update. That's simply because this fix is not in the tree yet. I had to update my other list options, and I'll include the update to this patch as well in my v2 posting.
Thanks,
-- Steve