Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib traceevent: Support function __get_dynamic_array_len

Support helper function __get_dynamic_array_len() in libtraceevent, this
function is used accompany with __print_array() or __print_hex(), but
currently it is not an available function in the function list of
process_function().

The total allocated length of the dynamic array is embedded in the top
half of __data_loc_##item field. This patch adds new arg type
PRINT_DYNAMIC_ARRAY_LEN to return the length to eval_num_arg(),

Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1440822125-52691-32-git-send-email-wangnan0@huawei.com
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

He Kuang and committed by
Arnaldo Carvalho de Melo
76055940 dabf626f

+57 -2
+54 -2
tools/lib/traceevent/event-parse.c
··· 848 848 free(arg->bitmask.bitmask); 849 849 break; 850 850 case PRINT_DYNAMIC_ARRAY: 851 + case PRINT_DYNAMIC_ARRAY_LEN: 851 852 free(arg->dynarray.index); 852 853 break; 853 854 case PRINT_OP: ··· 2730 2729 } 2731 2730 2732 2731 static enum event_type 2732 + process_dynamic_array_len(struct event_format *event, struct print_arg *arg, 2733 + char **tok) 2734 + { 2735 + struct format_field *field; 2736 + enum event_type type; 2737 + char *token; 2738 + 2739 + if (read_expect_type(EVENT_ITEM, &token) < 0) 2740 + goto out_free; 2741 + 2742 + arg->type = PRINT_DYNAMIC_ARRAY_LEN; 2743 + 2744 + /* Find the field */ 2745 + field = pevent_find_field(event, token); 2746 + if (!field) 2747 + goto out_free; 2748 + 2749 + arg->dynarray.field = field; 2750 + arg->dynarray.index = 0; 2751 + 2752 + if (read_expected(EVENT_DELIM, ")") < 0) 2753 + goto out_err; 2754 + 2755 + type = read_token(&token); 2756 + *tok = token; 2757 + 2758 + return type; 2759 + 2760 + out_free: 2761 + free_token(token); 2762 + out_err: 2763 + *tok = NULL; 2764 + return EVENT_ERROR; 2765 + } 2766 + 2767 + static enum event_type 2733 2768 process_paren(struct event_format *event, struct print_arg *arg, char **tok) 2734 2769 { 2735 2770 struct print_arg *item_arg; ··· 3011 2974 if (strcmp(token, "__get_dynamic_array") == 0) { 3012 2975 free_token(token); 3013 2976 return process_dynamic_array(event, arg, tok); 2977 + } 2978 + if (strcmp(token, "__get_dynamic_array_len") == 0) { 2979 + free_token(token); 2980 + return process_dynamic_array_len(event, arg, tok); 3014 2981 } 3015 2982 3016 2983 func = find_func_handler(event->pevent, token); ··· 3696 3655 goto out_warning_op; 3697 3656 } 3698 3657 break; 3658 + case PRINT_DYNAMIC_ARRAY_LEN: 3659 + offset = pevent_read_number(pevent, 3660 + data + arg->dynarray.field->offset, 3661 + arg->dynarray.field->size); 3662 + /* 3663 + * The total allocated length of the dynamic array is 3664 + * stored in the top half of the field, and the offset 3665 + * is in the bottom half of the 32 bit field. 3666 + */ 3667 + val = (unsigned long long)(offset >> 16); 3668 + break; 3699 3669 case PRINT_DYNAMIC_ARRAY: 3700 3670 /* Without [], we pass the address to the dynamic data */ 3701 3671 offset = pevent_read_number(pevent, 3702 3672 data + arg->dynarray.field->offset, 3703 3673 arg->dynarray.field->size); 3704 3674 /* 3705 - * The actual length of the dynamic array is stored 3706 - * in the top half of the field, and the offset 3675 + * The total allocated length of the dynamic array is 3676 + * stored in the top half of the field, and the offset 3707 3677 * is in the bottom half of the 32 bit field. 3708 3678 */ 3709 3679 offset &= 0xffff;
+1
tools/lib/traceevent/event-parse.h
··· 294 294 PRINT_OP, 295 295 PRINT_FUNC, 296 296 PRINT_BITMASK, 297 + PRINT_DYNAMIC_ARRAY_LEN, 297 298 }; 298 299 299 300 struct print_arg {
+1
tools/perf/util/scripting-engines/trace-event-perl.c
··· 221 221 break; 222 222 case PRINT_BSTRING: 223 223 case PRINT_DYNAMIC_ARRAY: 224 + case PRINT_DYNAMIC_ARRAY_LEN: 224 225 case PRINT_STRING: 225 226 case PRINT_BITMASK: 226 227 break;
+1
tools/perf/util/scripting-engines/trace-event-python.c
··· 251 251 /* gcc warns for these? */ 252 252 case PRINT_BSTRING: 253 253 case PRINT_DYNAMIC_ARRAY: 254 + case PRINT_DYNAMIC_ARRAY_LEN: 254 255 case PRINT_FUNC: 255 256 case PRINT_BITMASK: 256 257 /* we should warn... */