]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tracing: Add __print_dynamic_array() helper
authorSteven Rostedt <rostedt@goodmis.org>
Tue, 22 Oct 2024 19:36:28 +0000 (19:36 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:50:37 +0000 (07:50 +0200)
[ Upstream commit e52750fb1458ae9ea5860a08ed7a149185bc5b97 ]

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
Stable-dep-of: ea8d7647f9dd ("tracing: Verify event formats that have "%*p.."")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/trace/stages/stage3_trace_output.h
include/trace/stages/stage7_class_define.h
samples/trace_events/trace-events-sample.h

index c1fb1355d3094b59c4f0f0084fe9d37d52ba1d13..1e7b0bef95f5257b51880092c43d01842d385a73 100644 (file)
                trace_print_array_seq(p, array, count, el_size);        \
        })
 
+#undef __print_dynamic_array
+#define __print_dynamic_array(array, el_size)                          \
+       ({                                                              \
+               __print_array(__get_dynamic_array(array),               \
+                             __get_dynamic_array_len(array) / (el_size), \
+                             (el_size));                               \
+       })
+
 #undef __print_hex_dump
 #define __print_hex_dump(prefix_str, prefix_type,                      \
                         rowsize, groupsize, buf, len, ascii)           \
index bcb960d16fc0ed676e25fbb50af3e6f16a06e0de..fcd564a590f434648525e02815e7c33477ba8bd5 100644 (file)
@@ -22,6 +22,7 @@
 #undef __get_rel_cpumask
 #undef __get_rel_sockaddr
 #undef __print_array
+#undef __print_dynamic_array
 #undef __print_hex_dump
 #undef __get_buf
 
index 04541dfbd44cc5213ef96422dc3a6e35172e645d..24ec968d481fb7a676f5d98ff83a131ee8068adb 100644 (file)
@@ -317,7 +317,7 @@ TRACE_EVENT(foo_bar,
                __assign_cpumask(cpum, cpumask_bits(mask));
        ),
 
-       TP_printk("foo %s %d %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
+       TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
 
 /*
  * Notice here the use of some helper functions. This includes:
@@ -361,6 +361,11 @@ TRACE_EVENT(foo_bar,
                  __print_array(__get_dynamic_array(list),
                                __get_dynamic_array_len(list) / sizeof(int),
                                sizeof(int)),
+
+/*     A shortcut is to use __print_dynamic_array for dynamic arrays */
+
+                 __print_dynamic_array(list, sizeof(int)),
+
                  __get_str(str), __get_str(lstr),
                  __get_bitmask(cpus), __get_cpumask(cpum),
                  __get_str(vstr))