diff mbox series

[v5,2/5] tracing: Add __print_dynamic_array() helper

Message ID 20241001181617.604573-3-avadhut.naik@amd.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series MCE wrapper and support for new SMCA syndrome MSRs | expand

Commit Message

Avadhut Naik Oct. 1, 2024, 6:12 p.m. UTC
From: Steven Rostedt <rostedt@goodmis.org>

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>
---
Changes in v5:
Patch introduced in the series.
---
 include/trace/stages/stage3_trace_output.h | 8 ++++++++
 include/trace/stages/stage7_class_define.h | 1 +
 samples/trace_events/trace-events-sample.h | 7 ++++++-
 3 files changed, 15 insertions(+), 1 deletion(-)

Comments

Steven Rostedt Oct. 2, 2024, 3:06 p.m. UTC | #1
On Tue, 1 Oct 2024 18:12:26 +0000
Avadhut Naik <avadhut.naik@amd.com> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> 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>

I'm currently adding code where I need this patch too ;-)

I can make a branch that only has this patch based off of v6.12-rc1 where
we can both use it. Can we do that?

-- Steve


> ---
> Changes in v5:
> Patch introduced in the series.
> ---
>  include/trace/stages/stage3_trace_output.h | 8 ++++++++
>  include/trace/stages/stage7_class_define.h | 1 +
>  samples/trace_events/trace-events-sample.h | 7 ++++++-
>  3 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/include/trace/stages/stage3_trace_output.h b/include/trace/stages/stage3_trace_output.h
> index c1fb1355d309..8e3215093e1f 100644
> --- a/include/trace/stages/stage3_trace_output.h
> +++ b/include/trace/stages/stage3_trace_output.h
> @@ -119,6 +119,14 @@
>  		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)		\
> diff --git a/include/trace/stages/stage7_class_define.h b/include/trace/stages/stage7_class_define.h
> index bcb960d16fc0..fcd564a590f4 100644
> --- a/include/trace/stages/stage7_class_define.h
> +++ b/include/trace/stages/stage7_class_define.h
> @@ -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
>  
> diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
> index 55f9a3da92d5..999f78d380ae 100644
> --- a/samples/trace_events/trace-events-sample.h
> +++ b/samples/trace_events/trace-events-sample.h
> @@ -319,7 +319,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:
> @@ -363,6 +363,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))
Steven Rostedt Oct. 2, 2024, 4:29 p.m. UTC | #2
On Wed, 2 Oct 2024 11:06:41 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> I'm currently adding code where I need this patch too ;-)
> 
> I can make a branch that only has this patch based off of v6.12-rc1 where
> we can both use it. Can we do that?

I take this back. I'm doing something a little different (updating ftrace
specific events, which has their own macros).

Feel free to keep using it and pulling it into your tree.

-- Steve
Naik, Avadhut Oct. 2, 2024, 4:35 p.m. UTC | #3
On 10/2/2024 11:29, Steven Rostedt wrote:
> On Wed, 2 Oct 2024 11:06:41 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
>> I'm currently adding code where I need this patch too ;-)
>>
>> I can make a branch that only has this patch based off of v6.12-rc1 where
>> we can both use it. Can we do that?
> 
> I take this back. I'm doing something a little different (updating ftrace
> specific events, which has their own macros).
> 
> Feel free to keep using it and pulling it into your tree.
> 
Okay, thanks!
> -- Steve
diff mbox series

Patch

diff --git a/include/trace/stages/stage3_trace_output.h b/include/trace/stages/stage3_trace_output.h
index c1fb1355d309..8e3215093e1f 100644
--- a/include/trace/stages/stage3_trace_output.h
+++ b/include/trace/stages/stage3_trace_output.h
@@ -119,6 +119,14 @@ 
 		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)		\
diff --git a/include/trace/stages/stage7_class_define.h b/include/trace/stages/stage7_class_define.h
index bcb960d16fc0..fcd564a590f4 100644
--- a/include/trace/stages/stage7_class_define.h
+++ b/include/trace/stages/stage7_class_define.h
@@ -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
 
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index 55f9a3da92d5..999f78d380ae 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -319,7 +319,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:
@@ -363,6 +363,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))