Add array printing support to libtraceevent
v8 cover Add array printing support to libtraceevent
This series add support to libtraceevent for dynamic arrays in traces. The kernel learned to create this traces in 6ea22486ba46 ("tracing: Add array printing helper"), which was merged for v4.0-rc1.
Changes since v7[0]:
- Call the fields of the struct print_arg_int_array "field", "count" and "el_size" to match the definition of __print_array as Namhyung Kim suggests. Incorporate his Acked-by.
Changes since v6[1]:
- s/alloc_and_process_arg/alloc_and_process_delim/ as Steven Rostedt suggests
[0] http://thread.gmane.org/gmane.linux.kernel/1897935
[1] http://thread.gmane.org/gmane.linux.kernel/1896232
Javi Merino (2):
tools lib traceevent: factor out allocating and processing args tools lib traceevent: Add support for __print_array()
tools/lib/traceevent/event-parse.c | 158 +++++++++++++++++++++++++++++-------- tools/lib/traceevent/event-parse.h | 8 ++ 2 files changed, 135 insertions(+), 31 deletions(-)
Signature · 1 line
1.9.1
PATCH RESEND v8 1/2 tools lib traceevent: factor out allocating and processing args
The sequence of allocating the print_arg field, calling process_arg() and verifying that the next event delimiter is repeated twice in process_hex() and will also be used for process_int_array(). Factor it out to a function to avoid writing the same code again and again.
--- tools/lib/traceevent/event-parse.c | 77 ++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-)
tools/lib/traceevent/event-parse.c +40 -37
@@ -2014,6 +2014,38 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,return EVENT_ERROR ; } +static int alloc_and_process_delim (struct event_format *event,char *next_token, +struct print_arg **print_arg) +{ +struct print_arg *field; +enum event_type type; +char *token; +int ret =0 ; + + field =alloc_arg (); +if (!field) { +do_warning_event (event,"%s: not enough memory!" , __func__); + errno =ENOMEM ; +return -1 ; + } + + type =process_arg (event, field, &token); + +if (test_type_token (type, token,EVENT_DELIM , next_token)) { + errno =EINVAL ; + ret =-1 ; +free_arg (field); + goto out_free_token; + } + + *print_arg = field; + +out_free_token: +free_token (token); + +return ret; +} +static char *arg_eval (struct print_arg *arg); static unsigned long long
@@ -2486,49 +2518,20 @@ out_free:static enum event_type process_hex (struct event_format *event,struct print_arg *arg,char **tok) { -struct print_arg *field; -enum event_type type; -char *token =NULL ; -memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_HEX ; - field =alloc_arg (); -if (!field) { -do_warning_event (event,"%s: not enough memory!" , __func__); - goto out_free; - } - - type =process_arg (event, field, &token); - -if (test_type_token (type, token,EVENT_DELIM ,"," )) - goto out_free; - - arg->hex.field = field; - -free_token (token); - - field =alloc_arg (); -if (!field) { -do_warning_event (event,"%s: not enough memory!" , __func__); - *tok =NULL ; -return EVENT_ERROR ; - } - - type =process_arg (event, field, &token); - -if (test_type_token (type, token,EVENT_DELIM ,")" )) - goto out_free; +if (alloc_and_process_delim (event,"," , &arg->hex.field)) + goto out; - arg->hex.size = field; +if (alloc_and_process_delim (event,")" , &arg->hex.size)) + goto free_field; -free_token (token); - type =read_token_item (tok); -return type; +return read_token_item (tok); - out_free: -free_arg (field); -free_token (token); +free_field: +free_arg (arg->hex.field); +out: *tok =NULL ;return EVENT_ERROR ; }
Signature · 1 line
1.9.1
tip-bot for Javi Merino
merge bot[tip:perf/core] tools lib traceevent: Factor out allocating and processing args
tools lib traceevent: Factor out allocating and processing args
Commit-ID: 929a6bb71aa5ae6cb15b4b42ab7ac183ee286a1a Gitweb: http://git.kernel.org/tip/929a6bb71aa5ae6cb15b4b42ab7ac183ee286a1a Author: Javi Merino <[email protected]> AuthorDate: Fri, 20 Mar 2015 18:12:55 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 24 Mar 2015 12:07:05 -0300
tools lib traceevent: Factor out allocating and processing args
The sequence of allocating the print_arg field, calling process_arg() and verifying that the next event delimiter is repeated twice in process_hex() and will also be used for process_int_array().
Factor it out to a function to avoid writing the same code again and again.
--- tools/lib/traceevent/event-parse.c | 77 ++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-)
tools/lib/traceevent/event-parse.c +40 -37
@@ -2014,6 +2014,38 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,return EVENT_ERROR ; } +static int alloc_and_process_delim (struct event_format *event,char *next_token, +struct print_arg **print_arg) +{ +struct print_arg *field; +enum event_type type; +char *token; +int ret =0 ; + + field =alloc_arg (); +if (!field) { +do_warning_event (event,"%s: not enough memory!" , __func__); + errno =ENOMEM ; +return -1 ; + } + + type =process_arg (event, field, &token); + +if (test_type_token (type, token,EVENT_DELIM , next_token)) { + errno =EINVAL ; + ret =-1 ; +free_arg (field); + goto out_free_token; + } + + *print_arg = field; + +out_free_token: +free_token (token); + +return ret; +} +static char *arg_eval (struct print_arg *arg); static unsigned long long
@@ -2486,49 +2518,20 @@ out_free:static enum event_type process_hex (struct event_format *event,struct print_arg *arg,char **tok) { -struct print_arg *field; -enum event_type type; -char *token =NULL ; -memset (arg,0 ,sizeof (*arg)); arg->type =PRINT_HEX ; - field =alloc_arg (); -if (!field) { -do_warning_event (event,"%s: not enough memory!" , __func__); - goto out_free; - } - - type =process_arg (event, field, &token); - -if (test_type_token (type, token,EVENT_DELIM ,"," )) - goto out_free; - - arg->hex.field = field; - -free_token (token); - - field =alloc_arg (); -if (!field) { -do_warning_event (event,"%s: not enough memory!" , __func__); - *tok =NULL ; -return EVENT_ERROR ; - } - - type =process_arg (event, field, &token); - -if (test_type_token (type, token,EVENT_DELIM ,")" )) - goto out_free; +if (alloc_and_process_delim (event,"," , &arg->hex.field)) + goto out; - arg->hex.size = field; +if (alloc_and_process_delim (event,")" , &arg->hex.size)) + goto free_field; -free_token (token); - type =read_token_item (tok); -return type; +return read_token_item (tok); - out_free: -free_arg (field); -free_token (token); +free_field: +free_arg (arg->hex.field); +out: *tok =NULL ;return EVENT_ERROR ; }
PATCH RESEND v8 2/2 tools lib traceevent: Add support for __print_array()
In reply to Javi MerinoSince 6ea22486ba46 ("tracing: Add array printing helper") trace can traces with variable element size arrays. Add support to parse them.
--- tools/lib/traceevent/event-parse.c | 93 ++++++++++++++++++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 8 ++++ 2 files changed, 101 insertions(+)
tools/lib/traceevent/event-parse.c +93 -0
@@ -758,6 +758,11 @@ static void free_arg(struct print_arg *arg)free_arg (arg->hex.field);free_arg (arg->hex.size);break ; +case PRINT_INT_ARRAY : +free_arg (arg->int_array.field); +free_arg (arg->int_array.count); +free_arg (arg->int_array.el_size); +break ;case PRINT_TYPE :free (arg->typecast.type);free_arg (arg->typecast.item);
@@ -2537,6 +2542,32 @@ out: }static enum event_type +process_int_array (struct event_format *event,struct print_arg *arg,char **tok) +{ +memset (arg,0 ,sizeof (*arg)); + arg->type =PRINT_INT_ARRAY ; + +if (alloc_and_process_delim (event,"," , &arg->int_array.field)) + goto out; + +if (alloc_and_process_delim (event,"," , &arg->int_array.count)) + goto free_field; + +if (alloc_and_process_delim (event,")" , &arg->int_array.el_size)) + goto free_size; + +return read_token_item (tok); + +free_size: +free_arg (arg->int_array.count); +free_field: +free_arg (arg->int_array.field); +out: + *tok =NULL ; +return EVENT_ERROR ; +} + +static enum event_type process_dynamic_array (struct event_format *event,struct print_arg *arg,char **tok) {struct format_field *field;
@@ -2831,6 +2862,10 @@ process_function(struct event_format *event, struct print_arg *arg,free_token (token);return process_hex (event, arg, tok); } +if (strcmp (token,"__print_array" ) ==0 ) { +free_token (token); +return process_int_array (event, arg, tok); + }if (strcmp (token,"__get_str" ) ==0 ) {free_token (token);return process_str (event, arg, tok);
@@ -3359,6 +3394,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_argbreak ;case PRINT_FLAGS :case PRINT_SYMBOL : +case PRINT_INT_ARRAY :case PRINT_HEX :break ;case PRINT_TYPE :
@@ -3769,6 +3805,54 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, }break ; +case PRINT_INT_ARRAY : { +void *num; +int el_size; + +if (arg->int_array.field->type ==PRINT_DYNAMIC_ARRAY ) { +unsigned long offset; +struct format_field *field = + arg->int_array.field->dynarray.field; + offset =pevent_read_number (pevent, + data + field->offset, + field->size); + num = data + (offset &0xffff ); + }else { + field = arg->int_array.field->field.field; +if (!field) { + str = arg->int_array.field->field.name; + field =pevent_find_any_field (event, str); +if (!field) + goto out_warning_field; + arg->int_array.field->field.field = field; + } + num = data + field->offset; + } + len =eval_num_arg (data, size, event, arg->int_array.count); + el_size =eval_num_arg (data, size, event, + arg->int_array.el_size); +for (i =0 ; i < len; i++) { +if (i) +trace_seq_putc (s,' ' ); + +if (el_size ==1 ) { +trace_seq_printf (s,"%u" , *(uint8_t *)num); + }else if (el_size ==2 ) { +trace_seq_printf (s,"%u" , *(uint16_t *)num); + }else if (el_size ==4 ) { +trace_seq_printf (s,"%u" , *(uint32_t *)num); + }else if (el_size ==8 ) { +trace_seq_printf (s,"%llu" , *(uint64_t *)num); + }else { +trace_seq_printf (s,"BAD SIZE:%d 0x%x" , + el_size, *(uint8_t *)num); + el_size =1 ; + } + + num += el_size; + } +break ; + }case PRINT_TYPE :break ;case PRINT_STRING : {
@@ -5259,6 +5343,15 @@ static void print_args(struct print_arg *args)print_args (args->hex.size);printf (")" );break ; +case PRINT_INT_ARRAY : +printf ("__print_array(" ); +print_args (args->int_array.field); +printf (", " ); +print_args (args->int_array.count); +printf (", " ); +print_args (args->int_array.el_size); +printf (")" ); +break ;case PRINT_STRING :case PRINT_BSTRING :printf ("__get_str(%s)" , args->string.string);
tools/lib/traceevent/event-parse.h +8 -0
@@ -245,6 +245,12 @@ struct print_arg_hex {struct print_arg *size; }; +struct print_arg_int_array { +struct print_arg *field; +struct print_arg *count; +struct print_arg *el_size; +}; +struct print_arg_dynarray {struct format_field *field;struct print_arg *index;
@@ -273,6 +279,7 @@ enum print_arg_type {PRINT_FLAGS ,PRINT_SYMBOL ,PRINT_HEX , +PRINT_INT_ARRAY ,PRINT_TYPE ,PRINT_STRING , PRINT_BSTRING,
@@ -292,6 +299,7 @@ struct print_arg {struct print_arg_flags flags;struct print_arg_symbol symbol;struct print_arg_hex hex; +struct print_arg_int_array int_array;struct print_arg_func func;struct print_arg_string string;struct print_arg_bitmask bitmask;
Signature · 1 line
1.9.1
Re: [RESEND PATCH v8 2/2] tools lib traceevent: Add support for __print_array()
Em Fri, Mar 20, 2015 at 06:12:56PM +0000, Javi Merino escreveu:
Quoted 8 lines
Since
6ea22486ba46("tracing: Add array printing helper") trace can traces with variable element size arrays. Add support to parse them.Cc Arnaldo Carvalho de Melo <[email protected]>Cc Jiri Olsa <[email protected]>Acked-by Steven Rostedt <[email protected]>Acked-by Namhyung Kim <[email protected]>Signed-off-by Javi Merino <[email protected]>
Oops:
CC util/pmu-flex.outil/scripting-engines/trace-event-python.c: In function ‘define_event_symbols’:util/scripting-engines/trace-event-python.c:205:2: error: enumeration value ‘PRINT_INT_ARRAY’ not handled in switch [-Werror=switch-enum]
switch (args->type) {
^
cc1: all warnings being treated as errors
make[6]: *** [util/scripting-engines/trace-event-python.o] Error 1
make[6]: *** Waiting for unfinished jobs....util/scripting-engines/trace-event-perl.c: In function ‘define_event_symbols’:util/scripting-engines/trace-event-perl.c:190:2: error: enumeration value ‘PRINT_INT_ARRAY’ not handled in switch [-Werror=switch-enum]
switch (args->type) {
^
cc1: all warnings being treated as errors
make[6]: *** [util/scripting-engines/trace-event-perl.o] Error 1
make[5]: *** [scripting-engines] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [util] Error 2
make[3]: *** [libperf-in.o] Error 2
make[2]: *** [all] Error 2
test: test -x ./perf
make[1]: *** [make_pure] Error 1
make: *** [build-test] Error 2
make: Leaving directory `/home/acme/git/linux/tools/perf'
real 0m14.738s
user 1m2.124s
sys 0m8.653s
[acme@ssdandy linux]$
First one is applied, please fix this one.
[acme@ssdandy linux]$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.3/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix
gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)
[acme@ssdandy linux]$
- Arnaldo
PATCH v9 1/1 tools lib traceevent: Add support for __print_array()
Since 6ea22486ba46 ("tracing: Add array printing helper") trace can generate traces with variable element size arrays. Add support to parse them.
---
Changes since v8:
- Add PRINT_INT_ARRAY to define_event_symbols() in perf's scripting engines as Arnaldo suggested.
- Use %lu instead of %llu for uint64_t
Note, I'm not familiar with perf, so I've only compile-tested the changes in tools/perf/util/scripting-engines/trace-event-python.c and tools/perf/util/scripting-engines/trace-event-perl.c by imitating the code that is around. I'm not sure if that is the correct fix or it should be ignored like PRINT_DYNAMIC_ARRAY and friends.
tools/lib/traceevent/event-parse.c | 93 ++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 8 ++ .../perf/util/scripting-engines/trace-event-perl.c | 5 ++ .../util/scripting-engines/trace-event-python.c | 5 ++ 4 files changed, 111 insertions(+)
tools/lib/traceevent/event-parse.c +93 -0
@@ -758,6 +758,11 @@ static void free_arg(struct print_arg *arg)free_arg (arg->hex.field);free_arg (arg->hex.size);break ; +case PRINT_INT_ARRAY : +free_arg (arg->int_array.field); +free_arg (arg->int_array.count); +free_arg (arg->int_array.el_size); +break ;case PRINT_TYPE :free (arg->typecast.type);free_arg (arg->typecast.item);
@@ -2537,6 +2542,32 @@ out: }static enum event_type +process_int_array (struct event_format *event,struct print_arg *arg,char **tok) +{ +memset (arg,0 ,sizeof (*arg)); + arg->type =PRINT_INT_ARRAY ; + +if (alloc_and_process_delim (event,"," , &arg->int_array.field)) + goto out; + +if (alloc_and_process_delim (event,"," , &arg->int_array.count)) + goto free_field; + +if (alloc_and_process_delim (event,")" , &arg->int_array.el_size)) + goto free_size; + +return read_token_item (tok); + +free_size: +free_arg (arg->int_array.count); +free_field: +free_arg (arg->int_array.field); +out: + *tok =NULL ; +return EVENT_ERROR ; +} + +static enum event_type process_dynamic_array (struct event_format *event,struct print_arg *arg,char **tok) {struct format_field *field;
@@ -2831,6 +2862,10 @@ process_function(struct event_format *event, struct print_arg *arg,free_token (token);return process_hex (event, arg, tok); } +if (strcmp (token,"__print_array" ) ==0 ) { +free_token (token); +return process_int_array (event, arg, tok); + }if (strcmp (token,"__get_str" ) ==0 ) {free_token (token);return process_str (event, arg, tok);
@@ -3359,6 +3394,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_argbreak ;case PRINT_FLAGS :case PRINT_SYMBOL : +case PRINT_INT_ARRAY :case PRINT_HEX :break ;case PRINT_TYPE :
@@ -3769,6 +3805,54 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, }break ; +case PRINT_INT_ARRAY : { +void *num; +int el_size; + +if (arg->int_array.field->type ==PRINT_DYNAMIC_ARRAY ) { +unsigned long offset; +struct format_field *field = + arg->int_array.field->dynarray.field; + offset =pevent_read_number (pevent, + data + field->offset, + field->size); + num = data + (offset &0xffff ); + }else { + field = arg->int_array.field->field.field; +if (!field) { + str = arg->int_array.field->field.name; + field =pevent_find_any_field (event, str); +if (!field) + goto out_warning_field; + arg->int_array.field->field.field = field; + } + num = data + field->offset; + } + len =eval_num_arg (data, size, event, arg->int_array.count); + el_size =eval_num_arg (data, size, event, + arg->int_array.el_size); +for (i =0 ; i < len; i++) { +if (i) +trace_seq_putc (s,' ' ); + +if (el_size ==1 ) { +trace_seq_printf (s,"%u" , *(uint8_t *)num); + }else if (el_size ==2 ) { +trace_seq_printf (s,"%u" , *(uint16_t *)num); + }else if (el_size ==4 ) { +trace_seq_printf (s,"%u" , *(uint32_t *)num); + }else if (el_size ==8 ) { +trace_seq_printf (s,"%lu" , *(uint64_t *)num); + }else { +trace_seq_printf (s,"BAD SIZE:%d 0x%x" , + el_size, *(uint8_t *)num); + el_size =1 ; + } + + num += el_size; + } +break ; + }case PRINT_TYPE :break ;case PRINT_STRING : {
@@ -5259,6 +5343,15 @@ static void print_args(struct print_arg *args)print_args (args->hex.size);printf (")" );break ; +case PRINT_INT_ARRAY : +printf ("__print_array(" ); +print_args (args->int_array.field); +printf (", " ); +print_args (args->int_array.count); +printf (", " ); +print_args (args->int_array.el_size); +printf (")" ); +break ;case PRINT_STRING :case PRINT_BSTRING :printf ("__get_str(%s)" , args->string.string);
tools/lib/traceevent/event-parse.h +8 -0
@@ -247,6 +247,12 @@ struct print_arg_hex {struct print_arg *size; }; +struct print_arg_int_array { +struct print_arg *field; +struct print_arg *count; +struct print_arg *el_size; +}; +struct print_arg_dynarray {struct format_field *field;struct print_arg *index;
@@ -275,6 +281,7 @@ enum print_arg_type {PRINT_FLAGS ,PRINT_SYMBOL ,PRINT_HEX , +PRINT_INT_ARRAY ,PRINT_TYPE ,PRINT_STRING , PRINT_BSTRING,
@@ -294,6 +301,7 @@ struct print_arg {struct print_arg_flags flags;struct print_arg_symbol symbol;struct print_arg_hex hex; +struct print_arg_int_array int_array;struct print_arg_func func;struct print_arg_string string;struct print_arg_bitmask bitmask;
tools/perf/util/scripting-engines/trace-event-perl.c +5 -0
@@ -214,6 +214,11 @@ static void define_event_symbols(struct event_format *event,define_event_symbols (event, ev_name, args->hex.field);define_event_symbols (event, ev_name, args->hex.size);break ; +case PRINT_INT_ARRAY : +define_event_symbols (event, ev_name, args->int_array.field); +define_event_symbols (event, ev_name, args->int_array.count); +define_event_symbols (event, ev_name, args->int_array.el_size); +break ;case PRINT_BSTRING :case PRINT_DYNAMIC_ARRAY :case PRINT_STRING :
tools/perf/util/scripting-engines/trace-event-python.c +5 -0
@@ -231,6 +231,11 @@ static void define_event_symbols(struct event_format *event,define_event_symbols (event, ev_name, args->hex.field);define_event_symbols (event, ev_name, args->hex.size);break ; +case PRINT_INT_ARRAY : +define_event_symbols (event, ev_name, args->int_array.field); +define_event_symbols (event, ev_name, args->int_array.count); +define_event_symbols (event, ev_name, args->int_array.el_size); +break ;case PRINT_STRING :break ;case PRINT_TYPE :
Signature · 1 line
1.9.1
Re: [PATCH v9] tools lib traceevent: Add support for __print_array()
Em Tue, Mar 24, 2015 at 11:07:19AM +0000, Javi Merino escreveu:
Quoted 16 lines
Since
6ea22486ba46("tracing: Add array printing helper") trace can generate traces with variable element size arrays. Add support to parse them.Cc Arnaldo Carvalho de Melo <[email protected]>Cc Jiri Olsa <[email protected]>Acked-by Steven Rostedt <[email protected]>Acked-by Namhyung Kim <[email protected]>Signed-off-by Javi Merino <[email protected]>---
Changes since v8:
- AddPRINT_INT_ARRAYtodefine_event_symbols()in perf's scripting engines as Arnaldo suggested.
- Use %lu instead of %llu foruint64_t
Quoted 5 lines
Note, I'm not familiar with perf, so I've only compile-tested the changes in
tools/perf/util/scripting-engines/trace-event-python.candtools/perf/util/scripting-engines/trace-event-perl.cby imitating the code that is around. I'm not sure if that is the correct fix or it should be ignored likePRINT_DYNAMIC_ARRAYand friends.
Yeah, would be good to get some acked-by tags, Steven? Jiri? Namhyung?
What you did is equivalent, but explicitely ignoring it on the switches, so I think I can keep the acks you got, just checking...
And now it builds fine, thanks.
- Arnaldo
Quoted 212 lines
tools/lib/traceevent/event-parse.c | 93 ++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 8 ++ .../perf/util/scripting-engines/trace-event-perl.c | 5 ++ .../util/scripting-engines/trace-event-python.c | 5 ++ 4 files changed, 111 insertions(+)tools/lib/traceevent/event-parse.c +93
-0@@ -758,6 +758,11 @@ static void free_arg(struct print_arg *arg)free_arg (arg->hex.field);free_arg (arg->hex.size);break ; +case PRINT_INT_ARRAY : +free_arg (arg->int_array.field); +free_arg (arg->int_array.count); +free_arg (arg->int_array.el_size); +break ;case PRINT_TYPE :free (arg->typecast.type);free_arg (arg->typecast.item);@@ -2537,6 +2542,32 @@ out: }static enum event_type +process_int_array (struct event_format *event,struct print_arg *arg,char **tok) +{ +memset (arg,0 ,sizeof (*arg)); + arg->type =PRINT_INT_ARRAY ; + +if (alloc_and_process_delim (event,"," , &arg->int_array.field)) + goto out; + +if (alloc_and_process_delim (event,"," , &arg->int_array.count)) + goto free_field; + +if (alloc_and_process_delim (event,")" , &arg->int_array.el_size)) + goto free_size; + +return read_token_item (tok); + +free_size: +free_arg (arg->int_array.count); +free_field: +free_arg (arg->int_array.field); +out: + *tok =NULL ; +return EVENT_ERROR ; +} + +static enum event_type process_dynamic_array (struct event_format *event,struct print_arg *arg,char **tok) {struct format_field *field;@@ -2831,6 +2862,10 @@ process_function(struct event_format *event, struct print_arg *arg,free_token (token);return process_hex (event, arg, tok); } +if (strcmp (token,"__print_array" ) ==0 ) { +free_token (token); +return process_int_array (event, arg, tok); + }if (strcmp (token,"__get_str" ) ==0 ) {free_token (token);return process_str (event, arg, tok);@@ -3359,6 +3394,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_argbreak ;case PRINT_FLAGS :case PRINT_SYMBOL : +case PRINT_INT_ARRAY :case PRINT_HEX :break ;case PRINT_TYPE :@@ -3769,6 +3805,54 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, }break ; +case PRINT_INT_ARRAY : { +void *num; +int el_size; + +if (arg->int_array.field->type ==PRINT_DYNAMIC_ARRAY ) { +unsigned long offset; +struct format_field *field = + arg->int_array.field->dynarray.field; + offset =pevent_read_number (pevent, + data + field->offset, + field->size); + num = data + (offset &0xffff ); + }else { + field = arg->int_array.field->field.field; +if (!field) { + str = arg->int_array.field->field.name; + field =pevent_find_any_field (event, str); +if (!field) + goto out_warning_field; + arg->int_array.field->field.field = field; + } + num = data + field->offset; + } + len =eval_num_arg (data, size, event, arg->int_array.count); + el_size =eval_num_arg (data, size, event, + arg->int_array.el_size); +for (i =0 ; i < len; i++) { +if (i) +trace_seq_putc (s,' ' ); + +if (el_size ==1 ) { +trace_seq_printf (s,"%u" , *(uint8_t *)num); + }else if (el_size ==2 ) { +trace_seq_printf (s,"%u" , *(uint16_t *)num); + }else if (el_size ==4 ) { +trace_seq_printf (s,"%u" , *(uint32_t *)num); + }else if (el_size ==8 ) { +trace_seq_printf (s,"%lu" , *(uint64_t *)num); + }else { +trace_seq_printf (s,"BAD SIZE:%d 0x%x" , + el_size, *(uint8_t *)num); + el_size =1 ; + } + + num += el_size; + } +break ; + }case PRINT_TYPE :break ;case PRINT_STRING : {@@ -5259,6 +5343,15 @@ static void print_args(struct print_arg *args)print_args (args->hex.size);printf (")" );break ; +case PRINT_INT_ARRAY : +printf ("__print_array(" ); +print_args (args->int_array.field); +printf (", " ); +print_args (args->int_array.count); +printf (", " ); +print_args (args->int_array.el_size); +printf (")" ); +break ;case PRINT_STRING :case PRINT_BSTRING :printf ("__get_str(%s)" , args->string.string);tools/lib/traceevent/event-parse.h +8
-0@@ -247,6 +247,12 @@ struct print_arg_hex {struct print_arg *size; }; +struct print_arg_int_array { +struct print_arg *field; +struct print_arg *count; +struct print_arg *el_size; +}; +struct print_arg_dynarray {struct format_field *field;struct print_arg *index;@@ -275,6 +281,7 @@ enum print_arg_type {PRINT_FLAGS ,PRINT_SYMBOL ,PRINT_HEX , +PRINT_INT_ARRAY ,PRINT_TYPE ,PRINT_STRING , PRINT_BSTRING,@@ -294,6 +301,7 @@ struct print_arg {struct print_arg_flags flags;struct print_arg_symbol symbol;struct print_arg_hex hex; +struct print_arg_int_array int_array;struct print_arg_func func;struct print_arg_string string;struct print_arg_bitmask bitmask;tools/perf/util/scripting-engines/trace-event-perl.c +5
-0@@ -214,6 +214,11 @@ static void define_event_symbols(struct event_format *event,define_event_symbols (event, ev_name, args->hex.field);define_event_symbols (event, ev_name, args->hex.size);break ; +case PRINT_INT_ARRAY : +define_event_symbols (event, ev_name, args->int_array.field); +define_event_symbols (event, ev_name, args->int_array.count); +define_event_symbols (event, ev_name, args->int_array.el_size); +break ;case PRINT_BSTRING :case PRINT_DYNAMIC_ARRAY :case PRINT_STRING :tools/perf/util/scripting-engines/trace-event-python.c +5
-0@@ -231,6 +231,11 @@ static void define_event_symbols(struct event_format *event,define_event_symbols (event, ev_name, args->hex.field);define_event_symbols (event, ev_name, args->hex.size);break ; +case PRINT_INT_ARRAY : +define_event_symbols (event, ev_name, args->int_array.field); +define_event_symbols (event, ev_name, args->int_array.count); +define_event_symbols (event, ev_name, args->int_array.el_size); +break ;case PRINT_STRING :break ;case PRINT_TYPE :Signature · 1 line
1.9.1
tip-bot for Javi Merino
merge bot[tip:perf/core] tools lib traceevent: Add support for __print_array()
In reply to Javi Merinotools lib traceevent: Add support for __print_array()
Commit-ID: b839e1e846edb15cff322e262e8ce412d298232e Gitweb: http://git.kernel.org/tip/b839e1e846edb15cff322e262e8ce412d298232e Author: Javi Merino <[email protected]> AuthorDate: Tue, 24 Mar 2015 11:07:19 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 24 Mar 2015 12:46:39 -0300
tools lib traceevent: Add support for __print_array()
Since 6ea22486ba46 ("tracing: Add array printing helper") trace can generate traces with variable element size arrays. Add support to parse them.
--- tools/lib/traceevent/event-parse.c | 93 ++++++++++++++++++++++ tools/lib/traceevent/event-parse.h | 8 ++ .../perf/util/scripting-engines/trace-event-perl.c | 5 ++ .../util/scripting-engines/trace-event-python.c | 5 ++ 4 files changed, 111 insertions(+)
tools/lib/traceevent/event-parse.c +93 -0
@@ -766,6 +766,11 @@ static void free_arg(struct print_arg *arg)free_arg (arg->hex.field);free_arg (arg->hex.size);break ; +case PRINT_INT_ARRAY : +free_arg (arg->int_array.field); +free_arg (arg->int_array.count); +free_arg (arg->int_array.el_size); +break ;case PRINT_TYPE :free (arg->typecast.type);free_arg (arg->typecast.item);
@@ -2545,6 +2550,32 @@ out: }static enum event_type +process_int_array (struct event_format *event,struct print_arg *arg,char **tok) +{ +memset (arg,0 ,sizeof (*arg)); + arg->type =PRINT_INT_ARRAY ; + +if (alloc_and_process_delim (event,"," , &arg->int_array.field)) + goto out; + +if (alloc_and_process_delim (event,"," , &arg->int_array.count)) + goto free_field; + +if (alloc_and_process_delim (event,")" , &arg->int_array.el_size)) + goto free_size; + +return read_token_item (tok); + +free_size: +free_arg (arg->int_array.count); +free_field: +free_arg (arg->int_array.field); +out: + *tok =NULL ; +return EVENT_ERROR ; +} + +static enum event_type process_dynamic_array (struct event_format *event,struct print_arg *arg,char **tok) {struct format_field *field;
@@ -2839,6 +2870,10 @@ process_function(struct event_format *event, struct print_arg *arg,free_token (token);return process_hex (event, arg, tok); } +if (strcmp (token,"__print_array" ) ==0 ) { +free_token (token); +return process_int_array (event, arg, tok); + }if (strcmp (token,"__get_str" ) ==0 ) {free_token (token);return process_str (event, arg, tok);
@@ -3367,6 +3402,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_argbreak ;case PRINT_FLAGS :case PRINT_SYMBOL : +case PRINT_INT_ARRAY :case PRINT_HEX :break ;case PRINT_TYPE :
@@ -3777,6 +3813,54 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, }break ; +case PRINT_INT_ARRAY : { +void *num; +int el_size; + +if (arg->int_array.field->type ==PRINT_DYNAMIC_ARRAY ) { +unsigned long offset; +struct format_field *field = + arg->int_array.field->dynarray.field; + offset =pevent_read_number (pevent, + data + field->offset, + field->size); + num = data + (offset &0xffff ); + }else { + field = arg->int_array.field->field.field; +if (!field) { + str = arg->int_array.field->field.name; + field =pevent_find_any_field (event, str); +if (!field) + goto out_warning_field; + arg->int_array.field->field.field = field; + } + num = data + field->offset; + } + len =eval_num_arg (data, size, event, arg->int_array.count); + el_size =eval_num_arg (data, size, event, + arg->int_array.el_size); +for (i =0 ; i < len; i++) { +if (i) +trace_seq_putc (s,' ' ); + +if (el_size ==1 ) { +trace_seq_printf (s,"%u" , *(uint8_t *)num); + }else if (el_size ==2 ) { +trace_seq_printf (s,"%u" , *(uint16_t *)num); + }else if (el_size ==4 ) { +trace_seq_printf (s,"%u" , *(uint32_t *)num); + }else if (el_size ==8 ) { +trace_seq_printf (s,"%lu" , *(uint64_t *)num); + }else { +trace_seq_printf (s,"BAD SIZE:%d 0x%x" , + el_size, *(uint8_t *)num); + el_size =1 ; + } + + num += el_size; + } +break ; + }case PRINT_TYPE :break ;case PRINT_STRING : {
@@ -5361,6 +5445,15 @@ static void print_args(struct print_arg *args)print_args (args->hex.size);printf (")" );break ; +case PRINT_INT_ARRAY : +printf ("__print_array(" ); +print_args (args->int_array.field); +printf (", " ); +print_args (args->int_array.count); +printf (", " ); +print_args (args->int_array.el_size); +printf (")" ); +break ;case PRINT_STRING :case PRINT_BSTRING :printf ("__get_str(%s)" , args->string.string);
tools/lib/traceevent/event-parse.h +8 -0
@@ -251,6 +251,12 @@ struct print_arg_hex {struct print_arg *size; }; +struct print_arg_int_array { +struct print_arg *field; +struct print_arg *count; +struct print_arg *el_size; +}; +struct print_arg_dynarray {struct format_field *field;struct print_arg *index;
@@ -279,6 +285,7 @@ enum print_arg_type {PRINT_FLAGS ,PRINT_SYMBOL ,PRINT_HEX , +PRINT_INT_ARRAY ,PRINT_TYPE ,PRINT_STRING , PRINT_BSTRING,
@@ -298,6 +305,7 @@ struct print_arg {struct print_arg_flags flags;struct print_arg_symbol symbol;struct print_arg_hex hex; +struct print_arg_int_array int_array;struct print_arg_func func;struct print_arg_string string;struct print_arg_bitmask bitmask;
tools/perf/util/scripting-engines/trace-event-perl.c +5 -0
@@ -214,6 +214,11 @@ static void define_event_symbols(struct event_format *event,define_event_symbols (event, ev_name, args->hex.field);define_event_symbols (event, ev_name, args->hex.size);break ; +case PRINT_INT_ARRAY : +define_event_symbols (event, ev_name, args->int_array.field); +define_event_symbols (event, ev_name, args->int_array.count); +define_event_symbols (event, ev_name, args->int_array.el_size); +break ;case PRINT_BSTRING :case PRINT_DYNAMIC_ARRAY :case PRINT_STRING :
tools/perf/util/scripting-engines/trace-event-python.c +5 -0
@@ -231,6 +231,11 @@ static void define_event_symbols(struct event_format *event,define_event_symbols (event, ev_name, args->hex.field);define_event_symbols (event, ev_name, args->hex.size);break ; +case PRINT_INT_ARRAY : +define_event_symbols (event, ev_name, args->int_array.field); +define_event_symbols (event, ev_name, args->int_array.count); +define_event_symbols (event, ev_name, args->int_array.el_size); +break ;case PRINT_STRING :break ;case PRINT_TYPE :
Arnaldo Carvalho de Melo
AppliedEm Fri, Mar 20, 2015 at 06:12:54PM +0000, Javi Merino escreveu:
Quoted 4 lines
This series add support to libtraceevent for dynamic arrays in traces. The kernel learned to create this traces in
6ea22486ba46("tracing: Add array printing helper"), which was merged for v4.0-rc1.
Quoted 9 lines
Changes since v7[0]:
- Call the fields of the structprint_arg_int_array"field", "count" and "el_size" to match the definition of__print_arrayas Namhyung Kim suggests. Incorporate his Acked-by.Changes since v6[1]:
- s/alloc_and_process_arg/alloc_and_process_delim/ as Steven Rostedt suggests
Thanks, applied.