Skip to content

Commit f82565e

Browse files
tracing: Add __print_dynamic_array() helper
JIRA: https://issues.redhat.com/browse/RHEL-115358 commit e52750f Author: Steven Rostedt <rostedt@goodmis.org> Date: Tue Oct 22 19:36:28 2024 +0000 tracing: Add __print_dynamic_array() helper 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) <rostedt@goodmis.org> Signed-off-by: Avadhut Naik <avadhut.naik@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com> Link: https://lore.kernel.org/r/20241022194158.110073-3-avadhut.naik@amd.com Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
1 parent a0a0278 commit f82565e

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)