tools lib traceevent: Add changes from trace-cmd repo
cover tools lib traceevent: Add changes from trace-cmd repo
Arnaldo,
I was looking at the differences between the event-parse.c file in trace-cmd compared to what's in tools/lib/traceevent, and discovered that they have diverged a little. I pulled in several patches from upstream and realized I had some clean ups that I would like to be added too.
Maybe someday we can get a nice package that puts libtraceevent into its own .so that can be used by all.
Anyway you can pull this or you can take the patches straight in. I based off of Linus's 3.12-rc7.
-- Steve
Please pull the latest traceevent/updates tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
traceevent/updates
Head SHA1: 29ad23b00474c34e3b5040dda508c78d33a1a3eb 9ab76c2620680c767771f307e2dc5b152a153350
Howard Cochran (1):
tools lib traceevent: Handle __print_hex(__get_dynamic_array(fieldname), len)
Steven Rostedt (2):
tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events tools lib traceevent: Add pevent_print_func_field() helper function
Steven Rostedt (Red Hat) (4):
tools lib traceevent: Update printk formats when entered tools lib traceevent: If %s is a pointer, check printk formats tools lib traceevent: Have bprintk output the same as the kernel does tools lib traceevent: Check for spaces in character array
Yoshihiro YUNOMAE (1):
tools lib traceevent: Add support for extracting trace_clock in report
----
tools/lib/traceevent/event-parse.c | 165 ++++++++++++++++++++++++++++--------- tools/lib/traceevent/event-parse.h | 14 +++- 2 files changed, 136 insertions(+), 43 deletions(-)
PATCH 1/8 tools lib traceevent: Add support for extracting trace_clock in report
From: Yoshihiro YUNOMAE <[email protected]>
If trace-cmd extracts trace_clock, trace-cmd reads trace_clock data from the trace.dat and switches outputting format of timestamp for each trace_clock.
--- tools/lib/traceevent/event-parse.c | 50 +++++++++++++++++++++++++++++--------- tools/lib/traceevent/event-parse.h | 6 ++++- 2 files changed, 44 insertions(+), 12 deletions(-)
tools/lib/traceevent/event-parse.c +39 -11
@@ -305,6 +305,11 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)return 0 ; } +void pevent_register_trace_clock (struct pevent *pevent,char *trace_clock) +{ + pevent->trace_clock = trace_clock; +} +struct func_map {unsigned long long addr;char *func;
@@ -4443,8 +4448,21 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,trace_seq_terminate (s); } +static bool is_timestamp_in_us (char *trace_clock,bool use_trace_clock) +{ +if (!use_trace_clock) +return true; + +if (!strcmp (trace_clock,"local" ) || !strcmp (trace_clock,"global" ) + || !strcmp (trace_clock,"uptime" ) || !strcmp (trace_clock,"perf" )) +return true; + +/* trace_clock is setting in tsc or counter mode */ +return false; +} +void pevent_print_event (struct pevent *pevent,struct trace_seq *s, -struct pevent_record *record) +struct pevent_record *record,bool use_trace_clock) {static const char *spaces =" " ;/* 20 spaces */ struct event_format *event;
@@ -4457,9 +4475,14 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,int pid;int len;int p; +bool use_usec_format; - secs = record->ts /NSECS_PER_SEC ; - nsecs = record->ts - secs *NSECS_PER_SEC ; + use_usec_format =is_timestamp_in_us (pevent->trace_clock, + use_trace_clock); +if (use_usec_format) { + secs = record->ts /NSECS_PER_SEC ; + nsecs = record->ts - secs *NSECS_PER_SEC ; + }if (record->size <0 ) {do_warning ("ug! negative record size %d" , record->size);
@@ -4484,15 +4507,20 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s, }else trace_seq_printf (s,"%16s-%-5d [%03d]" , comm, pid, record->cpu); -if (pevent->flags &PEVENT_NSEC_OUTPUT ) { - usecs = nsecs; - p =9 ; - }else { - usecs = (nsecs +500 ) /NSECS_PER_USEC ; - p =6 ; - } +if (use_usec_format) { +if (pevent->flags &PEVENT_NSEC_OUTPUT ) { + usecs = nsecs; + p =9 ; + }else { + usecs = (nsecs +500 ) /NSECS_PER_USEC ; + p =6 ; + } -trace_seq_printf (s," %5lu.%0*lu: %s: " , secs, p, usecs, event->name); +trace_seq_printf (s," %5lu.%0*lu: %s: " , + secs, p, usecs, event->name); + }else +trace_seq_printf (s," %12llu: %s: " , + record->ts, event->name);/* Space out the event names evenly. */ len =strlen (event->name);
tools/lib/traceevent/event-parse.h +5 -1
@@ -20,6 +20,7 @@#ifndef _PARSE_EVENTS_H#define _PARSE_EVENTS_H +#include <stdbool.h> #include <stdarg.h> #include <regex.h>
@@ -450,6 +451,8 @@ struct pevent {/* cache */ struct event_format *last_event; + +char *trace_clock; };static inline void pevent_set_flag (struct pevent *pevent,int flag)
@@ -527,6 +530,7 @@ enum trace_flag_type { };int pevent_register_comm (struct pevent *pevent,const char *comm,int pid); +void pevent_register_trace_clock (struct pevent *pevent,char *trace_clock);int pevent_register_function (struct pevent *pevent,char *name,unsigned long long addr,char *mod); int pevent_register_print_string(struct pevent *pevent, char *fmt,
@@ -534,7 +538,7 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,int pevent_pid_is_registered (struct pevent *pevent,int pid);void pevent_print_event (struct pevent *pevent,struct trace_seq *s, -struct pevent_record *record); +struct pevent_record *record,bool use_trace_clock);int pevent_parse_header_page (struct pevent *pevent,char *buf,unsigned long size,int long_size);
Signature · 1 line
1.8.4.rc3
PATCH 2/8 tools lib traceevent: Update printk formats when entered
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Instead of cropping off the '"' and '\n"' from a printk format every time it is referenced, do it when it's added. This makes it easier to reference a printk_map and should speed things up a little.
--- tools/lib/traceevent/event-parse.c | 29 ++++++++++++++--------------- tools/lib/traceevent/event-parse.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-)
tools/lib/traceevent/event-parse.c +14 -15
@@ -604,10 +604,11 @@ find_printk(struct pevent *pevent, unsigned long long addr)* This registers a string by the address it was stored in the kernel. * The @fmt passed in is duplicated. */ -int pevent_register_print_string (struct pevent *pevent,char *fmt, +int pevent_register_print_string (struct pevent *pevent,const char *fmt,unsigned long long addr) {struct printk_list *item =malloc (sizeof (*item)); +char *p;if (!item)return -1 ;
@@ -615,10 +616,21 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt, item->next = pevent->printklist; item->addr = addr; +/* Strip off quotes and '\n' from the end */ +if (fmt[0 ] =='"' ) + fmt++; item->printk =strdup (fmt);if (!item->printk) goto out_free; + p = item->printk +strlen (item->printk) -1 ; +if (*p =='"' ) + *p =0 ; + + p -=2 ; +if (strcmp (p,"\\n" ) ==0 ) + *p =0 ; + pevent->printklist = item; pevent->printk_count++;
@@ -3887,7 +3899,6 @@ get_bprint_format(void *data, int size __maybe_unused,struct format_field *field;struct printk_map *printk;char *format; -char *p; field = pevent->bprint_fmt_field;
@@ -3909,20 +3920,8 @@ get_bprint_format(void *data, int size __maybe_unused,return format; } - p = printk->printk; -/* Remove any quotes. */ -if (*p =='"' ) - p++; -if (asprintf (&format,"%s : %s" ,"%pf" , p) <0 ) +if (asprintf (&format,"%s : %s" ,"%pf" , printk->printk) <0 )return NULL ; -/* remove ending quotes and new line since we will add one too */ - p = format +strlen (format) -1 ; -if (*p =='"' ) - *p =0 ; - - p -=2 ; -if (strcmp (p,"\\n" ) ==0 ) - *p =0 ;return format; }
tools/lib/traceevent/event-parse.h +1 -1
@@ -533,7 +533,7 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);void pevent_register_trace_clock (struct pevent *pevent,char *trace_clock);int pevent_register_function (struct pevent *pevent,char *name,unsigned long long addr,char *mod); -int pevent_register_print_string (struct pevent *pevent,char *fmt, +int pevent_register_print_string (struct pevent *pevent,const char *fmt,unsigned long long addr);int pevent_pid_is_registered (struct pevent *pevent,int pid);
Signature · 1 line
1.8.4.rc3
tip-bot for Steven Rostedt (Red Hat)
merge bot[tip:perf/core] tools lib traceevent: Update printk formats when entered
tools lib traceevent: Update printk formats when entered
Commit-ID: 18900af8292180151c82f0762506fa0740aa54a5 Gitweb: http://git.kernel.org/tip/18900af8292180151c82f0762506fa0740aa54a5 Author: Steven Rostedt (Red Hat) <[email protected]> AuthorDate: Fri, 1 Nov 2013 17:53:54 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 Nov 2013 14:33:59 -0300
tools lib traceevent: Update printk formats when entered
Instead of cropping off the '"' and '\n"' from a printk format every time it is referenced, do it when it's added. This makes it easier to reference a printk_map and should speed things up a little.
--- tools/lib/traceevent/event-parse.c | 29 ++++++++++++++--------------- tools/lib/traceevent/event-parse.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-)
tools/lib/traceevent/event-parse.c +14 -15
@@ -604,10 +604,11 @@ find_printk(struct pevent *pevent, unsigned long long addr)* This registers a string by the address it was stored in the kernel. * The @fmt passed in is duplicated. */ -int pevent_register_print_string (struct pevent *pevent,char *fmt, +int pevent_register_print_string (struct pevent *pevent,const char *fmt,unsigned long long addr) {struct printk_list *item =malloc (sizeof (*item)); +char *p;if (!item)return -1 ;
@@ -615,10 +616,21 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt, item->next = pevent->printklist; item->addr = addr; +/* Strip off quotes and '\n' from the end */ +if (fmt[0 ] =='"' ) + fmt++; item->printk =strdup (fmt);if (!item->printk) goto out_free; + p = item->printk +strlen (item->printk) -1 ; +if (*p =='"' ) + *p =0 ; + + p -=2 ; +if (strcmp (p,"\\n" ) ==0 ) + *p =0 ; + pevent->printklist = item; pevent->printk_count++;
@@ -3887,7 +3899,6 @@ get_bprint_format(void *data, int size __maybe_unused,struct format_field *field;struct printk_map *printk;char *format; -char *p; field = pevent->bprint_fmt_field;
@@ -3909,20 +3920,8 @@ get_bprint_format(void *data, int size __maybe_unused,return format; } - p = printk->printk; -/* Remove any quotes. */ -if (*p =='"' ) - p++; -if (asprintf (&format,"%s : %s" ,"%pf" , p) <0 ) +if (asprintf (&format,"%s : %s" ,"%pf" , printk->printk) <0 )return NULL ; -/* remove ending quotes and new line since we will add one too */ - p = format +strlen (format) -1 ; -if (*p =='"' ) - *p =0 ; - - p -=2 ; -if (strcmp (p,"\\n" ) ==0 ) - *p =0 ;return format; }
tools/lib/traceevent/event-parse.h +1 -1
@@ -533,7 +533,7 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);void pevent_register_trace_clock (struct pevent *pevent,char *trace_clock);int pevent_register_function (struct pevent *pevent,char *name,unsigned long long addr,char *mod); -int pevent_register_print_string (struct pevent *pevent,char *fmt, +int pevent_register_print_string (struct pevent *pevent,const char *fmt,unsigned long long addr);int pevent_pid_is_registered (struct pevent *pevent,int pid);
PATCH 3/8 tools lib traceevent: If %s is a pointer, check printk formats
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
If the format string of TP_printk() contains a %s, and the argument is not a string, check if the argument is a pointer that might match the printk_formats that were stored.
--- tools/lib/traceevent/event-parse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +7 -1
@@ -3505,6 +3505,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,struct pevent *pevent = event->pevent;struct print_flag_sym *flag;struct format_field *field; +struct printk_map *printk;unsigned long long val, fval;unsigned long addr;char *str;
@@ -3540,7 +3541,12 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,if (!(field->flags &FIELD_IS_ARRAY ) && field->size == pevent->long_size) { addr = *(unsigned long *)(data + field->offset); -trace_seq_printf (s,"%lx" , addr); +/* Check if it matches a print format */ + printk =find_printk (pevent, addr); +if (printk) +trace_seq_puts (s, printk->printk); +else +trace_seq_printf (s,"%lx" , addr);break ; } str =malloc (len +1 );
Signature · 1 line
1.8.4.rc3
tip-bot for Steven Rostedt (Red Hat)
merge bot[tip:perf/core] tools lib traceevent: If %s is a pointer, check printk formats
tools lib traceevent: If %s is a pointer, check printk formats
Commit-ID: 0970b5f438261216afcd0ccaa2fcfffc83df7ca2 Gitweb: http://git.kernel.org/tip/0970b5f438261216afcd0ccaa2fcfffc83df7ca2 Author: Steven Rostedt (Red Hat) <[email protected]> AuthorDate: Fri, 1 Nov 2013 17:53:55 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 Nov 2013 14:34:26 -0300
tools lib traceevent: If %s is a pointer, check printk formats
If the format string of TP_printk() contains a %s, and the argument is not a string, check if the argument is a pointer that might match the printk_formats that were stored.
--- tools/lib/traceevent/event-parse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +7 -1
@@ -3505,6 +3505,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,struct pevent *pevent = event->pevent;struct print_flag_sym *flag;struct format_field *field; +struct printk_map *printk;unsigned long long val, fval;unsigned long addr;char *str;
@@ -3540,7 +3541,12 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,if (!(field->flags &FIELD_IS_ARRAY ) && field->size == pevent->long_size) { addr = *(unsigned long *)(data + field->offset); -trace_seq_printf (s,"%lx" , addr); +/* Check if it matches a print format */ + printk =find_printk (pevent, addr); +if (printk) +trace_seq_puts (s, printk->printk); +else +trace_seq_printf (s,"%lx" , addr);break ; } str =malloc (len +1 );
PATCH 4/8 tools lib traceevent: Handle __print_hex(__get_dynamic_array(fieldname), len)
In reply to Steven RostedtFrom: Howard Cochran <[email protected]>
The kernel has a few events with a format similar to this excerpt:
field:unsigned int len; offset:12; size:4; signed:0;
field:__data_loc unsigned char[] data_array; offset:16; size:4; signed:0;print fmt: "%s", __print_hex(__get_dynamic_array(data_array), REC->len)
trace-cmd could already parse that arg correctly, but print_str_arg() was unable to handle the first parameter being a dynamic array. (It just printed a "field not found" warning).
Teach print_str_arg's PRINT_HEX case to handle the nested PRINT_DYNAMIC_ARRAY correctly. The output now matches the kernel's own formatting for this case.
--- tools/lib/traceevent/event-parse.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
tools/lib/traceevent/event-parse.c +16 -8
@@ -3588,15 +3588,23 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, }break ;case PRINT_HEX : - field = arg->hex.field->field.field; -if (!field) { - str = arg->hex.field->field.name; - field =pevent_find_any_field (event, str); -if (!field) - goto out_warning_field; - arg->hex.field->field.field = field; +if (arg->hex.field->type ==PRINT_DYNAMIC_ARRAY ) { +unsigned long offset; + offset =pevent_read_number (pevent, + data + arg->hex.field->dynarray.field->offset, + arg->hex.field->dynarray.field->size); + hex = data + (offset &0xffff ); + }else { + field = arg->hex.field->field.field; +if (!field) { + str = arg->hex.field->field.name; + field =pevent_find_any_field (event, str); +if (!field) + goto out_warning_field; + arg->hex.field->field.field = field; + } + hex = data + field->offset; } - hex = data + field->offset; len =eval_num_arg (data, size, event, arg->hex.size);for (i =0 ; i < len; i++) {if (i)
Signature · 1 line
1.8.4.rc3
PATCH 5/8 tools lib traceevent: Have bprintk output the same as the kernel does
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
The trace_bprintk() in the kernel looks like:
ring_buffer_producer_thread: Missed: 0
ring_buffer_producer_thread: Hit: 62174350
ring_buffer_producer_thread: Entries per millisec: 6296 ring_buffer_producer_thread: 158 ns per entry ring_buffer_producer_thread: Sleeping for 10 secs ring_buffer_producer_thread: Starting ring buffer hammer ring_buffer_producer_thread: End ring buffer hammer
But the current output looks like this:
ring_buffer_producer_thread : Time: 9407018 (usecs)
ring_buffer_producer_thread : Overruns: 43285485
ring_buffer_producer_thread : Read: 4405365 (by events) ring_buffer_producer_thread : Entries: 0 ring_buffer_producer_thread : Total: 47690850 ring_buffer_producer_thread : Missed: 0 ring_buffer_producer_thread : Hit: 47690850
Remove the space between the function and the colon.
--- tools/lib/traceevent/event-parse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse.c +4 -4
@@ -3802,8 +3802,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, strucif (asprintf (&arg->atom.atom,"%lld" , ip) <0 ) goto out_free; -/* skip the first "%pf : " */ -for (ptr = fmt +6 , bptr = data + field->offset; +/* skip the first "%pf: " */ +for (ptr = fmt +5 , bptr = data + field->offset; bptr < data + size && *ptr; ptr++) {int ls =0 ;
@@ -3929,12 +3929,12 @@ get_bprint_format(void *data, int size __maybe_unused, printk =find_printk (pevent, addr);if (!printk) { -if (asprintf (&format,"%%pf : (NO FORMAT FOUND at %llx)\n" , addr) <0 ) +if (asprintf (&format,"%%pf: (NO FORMAT FOUND at %llx)\n" , addr) <0 )return NULL ;return format; } -if (asprintf (&format,"%s : %s" ,"%pf" , printk->printk) <0 ) +if (asprintf (&format,"%s: %s" ,"%pf" , printk->printk) <0 )return NULL ;return format;
Signature · 1 line
1.8.4.rc3
tip-bot for Steven Rostedt (Red Hat)
merge bot[tip:perf/core] tools lib traceevent: Have bprintk output the same as the kernel does
tools lib traceevent: Have bprintk output the same as the kernel does
Commit-ID: 0883d9d730fc294c3d90ebd190b94e5782ead316 Gitweb: http://git.kernel.org/tip/0883d9d730fc294c3d90ebd190b94e5782ead316 Author: Steven Rostedt (Red Hat) <[email protected]> AuthorDate: Fri, 1 Nov 2013 17:53:57 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 Nov 2013 14:35:35 -0300
tools lib traceevent: Have bprintk output the same as the kernel does
The trace_bprintk() in the kernel looks like:
ring_buffer_producer_thread: Missed: 0
ring_buffer_producer_thread: Hit: 62174350
ring_buffer_producer_thread: Entries per millisec: 6296 ring_buffer_producer_thread: 158 ns per entry ring_buffer_producer_thread: Sleeping for 10 secs ring_buffer_producer_thread: Starting ring buffer hammer ring_buffer_producer_thread: End ring buffer hammer
But the current output looks like this:
ring_buffer_producer_thread : Time: 9407018 (usecs)
ring_buffer_producer_thread : Overruns: 43285485
ring_buffer_producer_thread : Read: 4405365 (by events) ring_buffer_producer_thread : Entries: 0 ring_buffer_producer_thread : Total: 47690850 ring_buffer_producer_thread : Missed: 0 ring_buffer_producer_thread : Hit: 47690850
Remove the space between the function and the colon.
--- tools/lib/traceevent/event-parse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse.c +4 -4
@@ -3802,8 +3802,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, strucif (asprintf (&arg->atom.atom,"%lld" , ip) <0 ) goto out_free; -/* skip the first "%pf : " */ -for (ptr = fmt +6 , bptr = data + field->offset; +/* skip the first "%pf: " */ +for (ptr = fmt +5 , bptr = data + field->offset; bptr < data + size && *ptr; ptr++) {int ls =0 ;
@@ -3929,12 +3929,12 @@ get_bprint_format(void *data, int size __maybe_unused, printk =find_printk (pevent, addr);if (!printk) { -if (asprintf (&format,"%%pf : (NO FORMAT FOUND at %llx)\n" , addr) <0 ) +if (asprintf (&format,"%%pf: (NO FORMAT FOUND at %llx)\n" , addr) <0 )return NULL ;return format; } -if (asprintf (&format,"%s : %s" ,"%pf" , printk->printk) <0 ) +if (asprintf (&format,"%s: %s" ,"%pf" , printk->printk) <0 )return NULL ;return format;
PATCH 6/8 tools lib traceevent: Check for spaces in character array
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Currently when using the raw format for fields, when looking at a character array, to determine if it is a string or not, we make sure all characters are "isprint()". If not, then we consider it a numeric array, and print the hex numbers of the characters instead.
But it seems that '\n' fails the isprint() check! Add isspace() to the check as well, such that if all characters pass isprint() or isspace() it will assume the character array is a string.
--- tools/lib/traceevent/event-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +1 -1
@@ -3981,7 +3981,7 @@ static int is_printable_array(char *p, unsigned int len)unsigned int i;for (i =0 ; i < len && p[i]; i++) -if (!isprint (p[i])) +if (!isprint (p[i]) && !isspace (p[i]))return 0 ;return 1 ; }
Signature · 1 line
1.8.4.rc3
tip-bot for Steven Rostedt (Red Hat)
merge bot[tip:perf/core] tools lib traceevent: Check for spaces in character array
tools lib traceevent: Check for spaces in character array
Commit-ID: 5efb9fbd5f1bfe4435bd0a3ea5f0e187875509c2 Gitweb: http://git.kernel.org/tip/5efb9fbd5f1bfe4435bd0a3ea5f0e187875509c2 Author: Steven Rostedt (Red Hat) <[email protected]> AuthorDate: Fri, 1 Nov 2013 17:53:58 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 Nov 2013 14:35:54 -0300
tools lib traceevent: Check for spaces in character array
Currently when using the raw format for fields, when looking at a character array, to determine if it is a string or not, we make sure all characters are "isprint()". If not, then we consider it a numeric array, and print the hex numbers of the characters instead.
But it seems that '\n' fails the isprint() check! Add isspace() to the check as well, such that if all characters pass isprint() or isspace() it will assume the character array is a string.
--- tools/lib/traceevent/event-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/traceevent/event-parse.c +1 -1
@@ -3981,7 +3981,7 @@ static int is_printable_array(char *p, unsigned int len)unsigned int i;for (i =0 ; i < len && p[i]; i++) -if (!isprint (p[i])) +if (!isprint (p[i]) && !isspace (p[i]))return 0 ;return 1 ; }
PATCH 7/8 tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add the flags EVENT_FL_NOHANDLE and EVENT_FL_PRINTRAW to the event flags to have the event either ignore the register handler or to ignore the handler and also print the raw format respectively.
This allows a tool to force a raw format or non handle for an event.
--- tools/lib/traceevent/event-parse.c | 4 ++-- tools/lib/traceevent/event-parse.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +2 -2
@@ -4446,11 +4446,11 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event, {int print_pretty =1 ; -if (event->pevent->print_raw) +if (event->pevent->print_raw || (event->flags &EVENT_FL_PRINTRAW ))print_event_fields (s, record->data, record->size, event);else { -if (event->handler) +if (event->handler && !(event->flags &EVENT_FL_NOHANDLE )) print_pretty = event->handler (s, record, event, event->context);
tools/lib/traceevent/event-parse.h +2 -0
@@ -308,6 +308,8 @@ enum {EVENT_FL_ISBPRINT =0x04 ,EVENT_FL_ISFUNCENT =0x10 ,EVENT_FL_ISFUNCRET =0x20 , +EVENT_FL_NOHANDLE =0x40 , +EVENT_FL_PRINTRAW =0x80 , EVENT_FL_FAILED = 0x80000000 };
Signature · 1 line
1.8.4.rc3
tip-bot for Steven Rostedt
merge bot[tip:perf/core] tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events
tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events
Commit-ID: c6c2b960b7a4105f096499fba3df65d6c0272a20 Gitweb: http://git.kernel.org/tip/c6c2b960b7a4105f096499fba3df65d6c0272a20 Author: Steven Rostedt <[email protected]> AuthorDate: Fri, 1 Nov 2013 17:53:59 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 Nov 2013 14:36:27 -0300
tools lib traceevent: Add flags NOHANDLE and PRINTRAW to individual events
Add the flags EVENT_FL_NOHANDLE and EVENT_FL_PRINTRAW to the event flags to have the event either ignore the register handler or to ignore the handler and also print the raw format respectively.
This allows a tool to force a raw format or non handle for an event.
--- tools/lib/traceevent/event-parse.c | 4 ++-- tools/lib/traceevent/event-parse.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +2 -2
@@ -4446,11 +4446,11 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event, {int print_pretty =1 ; -if (event->pevent->print_raw) +if (event->pevent->print_raw || (event->flags &EVENT_FL_PRINTRAW ))print_event_fields (s, record->data, record->size, event);else { -if (event->handler) +if (event->handler && !(event->flags &EVENT_FL_NOHANDLE )) print_pretty = event->handler (s, record, event, event->context);
tools/lib/traceevent/event-parse.h +2 -0
@@ -308,6 +308,8 @@ enum {EVENT_FL_ISBPRINT =0x04 ,EVENT_FL_ISFUNCENT =0x10 ,EVENT_FL_ISFUNCRET =0x20 , +EVENT_FL_NOHANDLE =0x40 , +EVENT_FL_PRINTRAW =0x80 , EVENT_FL_FAILED = 0x80000000 };
PATCH 8/8 tools lib traceevent: Add pevent_print_func_field() helper function
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add the pevent_print_func_field() that will look up a field that is expected to be a function pointer, and it will print the function name and offset of the address given by the field.
--- tools/lib/traceevent/event-parse.c | 42 ++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 4 ++++ 2 files changed, 46 insertions(+)
tools/lib/traceevent/event-parse.c +42 -0
@@ -5367,6 +5367,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,return -1 ; } +/** +* pevent_print_func_field - print a field and a format for function pointers +* @s: The seq to print to +* @fmt: The printf format to print the field with. +* @event: the event that the field is for +* @name: The name of the field +* @record: The record with the field name. +* @err: print default error if failed. +* +* Returns: 0 on success, -1 field not found, or 1 if buffer is full. +*/ +int pevent_print_func_field (struct trace_seq *s,const char *fmt, +struct event_format *event,const char *name, +struct pevent_record *record,int err) +{ +struct format_field *field =pevent_find_field (event, name); +struct pevent *pevent = event->pevent; +unsigned long long val; +struct func_map *func; +char tmp[128 ]; + +if (!field) + goto failed; + +if (pevent_read_number_field (field, record->data, &val)) + goto failed; + + func =find_func (pevent, val); + +if (func) +snprintf (tmp,128 ,"%s/0x%llx" , func->func, func->addr - val); +else +sprintf (tmp,"0x%08llx" , val); + +return trace_seq_printf (s, fmt, tmp); + + failed: +if (err) +trace_seq_printf (s,"CAN'T FIND FIELD \"%s\"" , name); +return -1 ; +} +static void free_func_handle (struct pevent_function_handler *func) {struct pevent_func_params *params;
tools/lib/traceevent/event-parse.h +4 -0
@@ -569,6 +569,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt, struct event_format *event, const char *name, struct pevent_record *record, int err); +int pevent_print_func_field (struct trace_seq *s,const char *fmt, +struct event_format *event,const char *name, +struct pevent_record *record,int err); +int pevent_register_event_handler (struct pevent *pevent,int id,const char *sys_name,const char *event_name,pevent_event_handler_func func,void *context);
Signature · 1 line
1.8.4.rc3
tip-bot for Steven Rostedt
merge bot[tip:perf/core] tools lib traceevent: Add pevent_print_func_field () helper function
tools lib traceevent: Add pevent_print_func_field() helper function
Commit-ID: 6d862b8c14ba539c7c87ffc77f2e1d6dc9630c4d Gitweb: http://git.kernel.org/tip/6d862b8c14ba539c7c87ffc77f2e1d6dc9630c4d Author: Steven Rostedt <[email protected]> AuthorDate: Fri, 1 Nov 2013 17:54:00 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 Nov 2013 14:36:49 -0300
tools lib traceevent: Add pevent_print_func_field() helper function
Add the pevent_print_func_field() that will look up a field that is expected to be a function pointer, and it will print the function name and offset of the address given by the field.
--- tools/lib/traceevent/event-parse.c | 42 ++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 4 ++++ 2 files changed, 46 insertions(+)
tools/lib/traceevent/event-parse.c +42 -0
@@ -5367,6 +5367,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,return -1 ; } +/** +* pevent_print_func_field - print a field and a format for function pointers +* @s: The seq to print to +* @fmt: The printf format to print the field with. +* @event: the event that the field is for +* @name: The name of the field +* @record: The record with the field name. +* @err: print default error if failed. +* +* Returns: 0 on success, -1 field not found, or 1 if buffer is full. +*/ +int pevent_print_func_field (struct trace_seq *s,const char *fmt, +struct event_format *event,const char *name, +struct pevent_record *record,int err) +{ +struct format_field *field =pevent_find_field (event, name); +struct pevent *pevent = event->pevent; +unsigned long long val; +struct func_map *func; +char tmp[128 ]; + +if (!field) + goto failed; + +if (pevent_read_number_field (field, record->data, &val)) + goto failed; + + func =find_func (pevent, val); + +if (func) +snprintf (tmp,128 ,"%s/0x%llx" , func->func, func->addr - val); +else +sprintf (tmp,"0x%08llx" , val); + +return trace_seq_printf (s, fmt, tmp); + + failed: +if (err) +trace_seq_printf (s,"CAN'T FIND FIELD \"%s\"" , name); +return -1 ; +} +static void free_func_handle (struct pevent_function_handler *func) {struct pevent_func_params *params;
tools/lib/traceevent/event-parse.h +4 -0
@@ -569,6 +569,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt, struct event_format *event, const char *name, struct pevent_record *record, int err); +int pevent_print_func_field (struct trace_seq *s,const char *fmt, +struct event_format *event,const char *name, +struct pevent_record *record,int err); +int pevent_register_event_handler (struct pevent *pevent,int id,const char *sys_name,const char *event_name,pevent_event_handler_func func,void *context);