Skip to content

Commit 87c9dc3

Browse files
rostedtjfvogel
authored andcommitted
tracing: Add __print_dynamic_array() helper
[ Upstream commit e52750f ] When printing a dynamic array in a trace event, the method is rather ugly. It has the format of: __print_array(__get_dynamic_array(array), __get_dynmaic_array_len(array) / el_size, el_size) Since dynamic arrays are known to the tracing infrastructure, create a helper macro that does the above for you. __print_dynamic_array(array, el_size) Which would expand to the same output. Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Avadhut Naik <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Qiuxu Zhuo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Stable-dep-of: ea8d7647f9dd ("tracing: Verify event formats that have "%*p.."") Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 0b603e77597959a97c66b1df0402e1e7fb4886ee) Signed-off-by: Jack Vogel <[email protected]>
1 parent 9d5dbaa commit 87c9dc3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

include/trace/stages/stage3_trace_output.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@
119119
trace_print_array_seq(p, array, count, el_size); \
120120
})
121121

122+
#undef __print_dynamic_array
123+
#define __print_dynamic_array(array, el_size) \
124+
({ \
125+
__print_array(__get_dynamic_array(array), \
126+
__get_dynamic_array_len(array) / (el_size), \
127+
(el_size)); \
128+
})
129+
122130
#undef __print_hex_dump
123131
#define __print_hex_dump(prefix_str, prefix_type, \
124132
rowsize, groupsize, buf, len, ascii) \

include/trace/stages/stage7_class_define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#undef __get_rel_cpumask
2323
#undef __get_rel_sockaddr
2424
#undef __print_array
25+
#undef __print_dynamic_array
2526
#undef __print_hex_dump
2627
#undef __get_buf
2728

samples/trace_events/trace-events-sample.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ TRACE_EVENT(foo_bar,
319319
__assign_cpumask(cpum, cpumask_bits(mask));
320320
),
321321

322-
TP_printk("foo %s %d %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
322+
TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
323323

324324
/*
325325
* Notice here the use of some helper functions. This includes:
@@ -363,6 +363,11 @@ TRACE_EVENT(foo_bar,
363363
__print_array(__get_dynamic_array(list),
364364
__get_dynamic_array_len(list) / sizeof(int),
365365
sizeof(int)),
366+
367+
/* A shortcut is to use __print_dynamic_array for dynamic arrays */
368+
369+
__print_dynamic_array(list, sizeof(int)),
370+
366371
__get_str(str), __get_str(lstr),
367372
__get_bitmask(cpus), __get_cpumask(cpum),
368373
__get_str(vstr))

0 commit comments

Comments
 (0)