Skip to content

Commit b7c6631

Browse files
committed
tracing: Add __print_dynamic_array() helper
JIRA: https://issues.redhat.com/browse/RHEL-52657 Tested: by AMD Conflicts: trace headers aren't split in different stages like upstream; trace-events-sample is behind on the tests so the number of arguments is lower 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: Aristeu Rozanski <arozansk@redhat.com>
1 parent ecfe576 commit b7c6631

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/trace/trace_events.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ TRACE_MAKE_SYSTEM_STR();
428428
trace_print_array_seq(p, array, count, el_size); \
429429
})
430430

431+
#undef __print_dynamic_array
432+
#define __print_dynamic_array(array, el_size) \
433+
({ \
434+
__print_array(__get_dynamic_array(array), \
435+
__get_dynamic_array_len(array) / (el_size), \
436+
(el_size)); \
437+
})
438+
431439
#undef __print_hex_dump
432440
#define __print_hex_dump(prefix_str, prefix_type, \
433441
rowsize, groupsize, buf, len, ascii) \
@@ -966,6 +974,7 @@ static inline void ftrace_test_probe_##call(void) \
966974
#undef __get_rel_bitmask
967975
#undef __get_rel_sockaddr
968976
#undef __print_array
977+
#undef __print_dynamic_array
969978
#undef __print_hex_dump
970979
#undef __get_buf
971980

samples/trace_events/trace-events-sample.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ TRACE_EVENT(foo_bar,
277277
__assign_bitmask(cpus, cpumask_bits(mask), num_possible_cpus());
278278
),
279279

280-
TP_printk("foo %s %d %s %s %s %s (%s)", __entry->foo, __entry->bar,
280+
TP_printk("foo %s %d %s %s %s %s %s (%s)", __entry->foo, __entry->bar,
281281

282282
/*
283283
* Notice here the use of some helper functions. This includes:
@@ -321,6 +321,11 @@ TRACE_EVENT(foo_bar,
321321
__print_array(__get_dynamic_array(list),
322322
__get_dynamic_array_len(list) / sizeof(int),
323323
sizeof(int)),
324+
325+
/* A shortcut is to use __print_dynamic_array for dynamic arrays */
326+
327+
__print_dynamic_array(list, sizeof(int)),
328+
324329
__get_str(str), __get_bitmask(cpus))
325330
);
326331

0 commit comments

Comments
 (0)