public inbox for linux-trace-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type
@ 2026-02-06  9:15 Donglin Peng
  2026-02-06 15:02 ` Steven Rostedt
  0 siblings, 1 reply; 6+ messages in thread
From: Donglin Peng @ 2026-02-06  9:15 UTC (permalink / raw)
  To: rostedt; +Cc: mhiramat, linux-trace-devel, Donglin Peng

From: Donglin Peng <pengdonglin@xiaomi.com>

The tep_btf_print_args() function currently prints values of
enum parameters in decimal format, which reduces readability.

Utilize the BTF information to resolve enum type parameters
and print their symbolic names where possible. This enhances
the trace log readability by displaying meaningful identifiers
instead of raw numbers.

Before:
mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5, val=320)

After:
mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5 [NR_SLAB_RECLAIMABLE_B], val=320)

Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
---
 src/trace-btf.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/trace-btf.c b/src/trace-btf.c
index 859b0860ce2a..85f5fefb4d3b 100644
--- a/src/trace-btf.c
+++ b/src/trace-btf.c
@@ -32,6 +32,16 @@ struct tep_btf {
 #define REALLOC_SIZE (1 << 10)
 #define REALLOC_MASK (REALLOC_SIZE - 1)
 
+#define for_each_enum(i, enum_type, member)			\
+	for (i = 0, member = btf_enum(enum_type);		\
+	     i < BTF_INFO_VLEN(enum_type->info);		\
+	     i++, member++)
+
+static inline struct btf_enum *btf_enum(const struct btf_type *t)
+{
+	return (struct btf_enum *)(t + 1);
+}
+
 static const char *btf_name(struct tep_btf *btf, int off)
 {
 	if (off < btf->hdr->str_len)
@@ -546,10 +556,11 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
 	struct tep_btf *btf = tep->btf;
 	struct btf_type *type = tep_btf_find_func(btf, func);
 	struct btf_param *param;
+	struct btf_enum *enump;
 	unsigned long long arg;
 	unsigned int encode;
 	const char *param_name;
-	int a, p, x, nr;
+	int a, p, x, nr, i;
 
 	if (!func)
 		return -1;
@@ -628,6 +639,13 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
 			break;
 		case BTF_KIND_ENUM:
 			trace_seq_printf(s, "%lld", arg);
+			for_each_enum(i, t, enump) {
+				if (arg == enump->val) {
+					trace_seq_printf(s, " [%s]",
+						btf_name(btf, enump->name_off));
+					break;
+				}
+			}
 			break;
 		default:
 			/* This does not handle complex arguments */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type
  2026-02-06  9:15 [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type Donglin Peng
@ 2026-02-06 15:02 ` Steven Rostedt
  2026-02-07  4:28   ` Donglin Peng
  2026-02-07  5:04   ` Donglin Peng
  0 siblings, 2 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-02-06 15:02 UTC (permalink / raw)
  To: Donglin Peng; +Cc: mhiramat, linux-trace-devel, Donglin Peng

On Fri,  6 Feb 2026 17:15:12 +0800
Donglin Peng <dolinux.peng@gmail.com> wrote:

> From: Donglin Peng <pengdonglin@xiaomi.com>

Hi Donglin,

> 
> The tep_btf_print_args() function currently prints values of
> enum parameters in decimal format, which reduces readability.
> 
> Utilize the BTF information to resolve enum type parameters
> and print their symbolic names where possible. This enhances
> the trace log readability by displaying meaningful identifiers
> instead of raw numbers.
> 
> Before:
> mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5, val=320)
> 
> After:
> mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5 [NR_SLAB_RECLAIMABLE_B], val=320)
> 
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
> ---
>  src/trace-btf.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/src/trace-btf.c b/src/trace-btf.c
> index 859b0860ce2a..85f5fefb4d3b 100644
> --- a/src/trace-btf.c
> +++ b/src/trace-btf.c
> @@ -32,6 +32,16 @@ struct tep_btf {
>  #define REALLOC_SIZE (1 << 10)
>  #define REALLOC_MASK (REALLOC_SIZE - 1)
>  
> +#define for_each_enum(i, enum_type, member)			\
> +	for (i = 0, member = btf_enum(enum_type);		\
> +	     i < BTF_INFO_VLEN(enum_type->info);		\
> +	     i++, member++)


You can make the above into:

 #define for_each_enum(enum_type, member)			\
	for (int __i = 0, member = btf_enum(enum_type);		\
	     __i < BTF_INFO_VLEN((enum_type)->info);		\
	     __i++, member++)

Then you don't need to pass in the counter "i".

(also it's good to put parenthesis around "enum_type").

> +
> +static inline struct btf_enum *btf_enum(const struct btf_type *t)
> +{
> +	return (struct btf_enum *)(t + 1);
> +}
> +
>  static const char *btf_name(struct tep_btf *btf, int off)
>  {
>  	if (off < btf->hdr->str_len)
> @@ -546,10 +556,11 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
>  	struct tep_btf *btf = tep->btf;
>  	struct btf_type *type = tep_btf_find_func(btf, func);
>  	struct btf_param *param;
> +	struct btf_enum *enump;
>  	unsigned long long arg;
>  	unsigned int encode;
>  	const char *param_name;
> -	int a, p, x, nr;
> +	int a, p, x, nr, i;

And the above doesn't need to be changed.

Thanks,

-- Steve

>  
>  	if (!func)
>  		return -1;
> @@ -628,6 +639,13 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
>  			break;
>  		case BTF_KIND_ENUM:
>  			trace_seq_printf(s, "%lld", arg);
> +			for_each_enum(i, t, enump) {
> +				if (arg == enump->val) {
> +					trace_seq_printf(s, " [%s]",
> +						btf_name(btf, enump->name_off));
> +					break;
> +				}
> +			}
>  			break;
>  		default:
>  			/* This does not handle complex arguments */


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type
  2026-02-06 15:02 ` Steven Rostedt
@ 2026-02-07  4:28   ` Donglin Peng
  2026-02-07  5:04   ` Donglin Peng
  1 sibling, 0 replies; 6+ messages in thread
From: Donglin Peng @ 2026-02-07  4:28 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: mhiramat, linux-trace-devel, Donglin Peng

On Fri, Feb 6, 2026 at 11:01 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri,  6 Feb 2026 17:15:12 +0800
> Donglin Peng <dolinux.peng@gmail.com> wrote:
>
> > From: Donglin Peng <pengdonglin@xiaomi.com>
>
> Hi Donglin,
>
> >
> > The tep_btf_print_args() function currently prints values of
> > enum parameters in decimal format, which reduces readability.
> >
> > Utilize the BTF information to resolve enum type parameters
> > and print their symbolic names where possible. This enhances
> > the trace log readability by displaying meaningful identifiers
> > instead of raw numbers.
> >
> > Before:
> > mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5, val=320)
> >
> > After:
> > mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5 [NR_SLAB_RECLAIMABLE_B], val=320)
> >
> > Cc: Steven Rostedt <rostedt@goodmis.org>
> > Cc: Masami Hiramatsu <mhiramat@kernel.org>
> > Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
> > ---
> >  src/trace-btf.c | 20 +++++++++++++++++++-
> >  1 file changed, 19 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/trace-btf.c b/src/trace-btf.c
> > index 859b0860ce2a..85f5fefb4d3b 100644
> > --- a/src/trace-btf.c
> > +++ b/src/trace-btf.c
> > @@ -32,6 +32,16 @@ struct tep_btf {
> >  #define REALLOC_SIZE (1 << 10)
> >  #define REALLOC_MASK (REALLOC_SIZE - 1)
> >
> > +#define for_each_enum(i, enum_type, member)                  \
> > +     for (i = 0, member = btf_enum(enum_type);               \
> > +          i < BTF_INFO_VLEN(enum_type->info);                \
> > +          i++, member++)
>
>
> You can make the above into:
>
>  #define for_each_enum(enum_type, member)                       \
>         for (int __i = 0, member = btf_enum(enum_type);         \
>              __i < BTF_INFO_VLEN((enum_type)->info);            \
>              __i++, member++)
>
> Then you don't need to pass in the counter "i".

Good, I will fix it in the next version.

>
> (also it's good to put parenthesis around "enum_type").

Thanks.

>
> > +
> > +static inline struct btf_enum *btf_enum(const struct btf_type *t)
> > +{
> > +     return (struct btf_enum *)(t + 1);
> > +}
> > +
> >  static const char *btf_name(struct tep_btf *btf, int off)
> >  {
> >       if (off < btf->hdr->str_len)
> > @@ -546,10 +556,11 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
> >       struct tep_btf *btf = tep->btf;
> >       struct btf_type *type = tep_btf_find_func(btf, func);
> >       struct btf_param *param;
> > +     struct btf_enum *enump;
> >       unsigned long long arg;
> >       unsigned int encode;
> >       const char *param_name;
> > -     int a, p, x, nr;
> > +     int a, p, x, nr, i;
>
> And the above doesn't need to be changed.

Thanks, I understood.

>
> Thanks,
>
> -- Steve
>
> >
> >       if (!func)
> >               return -1;
> > @@ -628,6 +639,13 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
> >                       break;
> >               case BTF_KIND_ENUM:
> >                       trace_seq_printf(s, "%lld", arg);
> > +                     for_each_enum(i, t, enump) {
> > +                             if (arg == enump->val) {
> > +                                     trace_seq_printf(s, " [%s]",
> > +                                             btf_name(btf, enump->name_off));
> > +                                     break;
> > +                             }
> > +                     }
> >                       break;
> >               default:
> >                       /* This does not handle complex arguments */
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type
  2026-02-06 15:02 ` Steven Rostedt
  2026-02-07  4:28   ` Donglin Peng
@ 2026-02-07  5:04   ` Donglin Peng
  2026-02-07 14:16     ` Steven Rostedt
  1 sibling, 1 reply; 6+ messages in thread
From: Donglin Peng @ 2026-02-07  5:04 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: mhiramat, linux-trace-devel, Donglin Peng

On Fri, Feb 6, 2026 at 11:01 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri,  6 Feb 2026 17:15:12 +0800
> Donglin Peng <dolinux.peng@gmail.com> wrote:
>
> > From: Donglin Peng <pengdonglin@xiaomi.com>
>
> Hi Donglin,
>
> >
> > The tep_btf_print_args() function currently prints values of
> > enum parameters in decimal format, which reduces readability.
> >
> > Utilize the BTF information to resolve enum type parameters
> > and print their symbolic names where possible. This enhances
> > the trace log readability by displaying meaningful identifiers
> > instead of raw numbers.
> >
> > Before:
> > mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5, val=320)
> >
> > After:
> > mod_memcg_lruvec_state(lruvec=0xffff88800c18a540, idx=5 [NR_SLAB_RECLAIMABLE_B], val=320)
> >
> > Cc: Steven Rostedt <rostedt@goodmis.org>
> > Cc: Masami Hiramatsu <mhiramat@kernel.org>
> > Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
> > ---
> >  src/trace-btf.c | 20 +++++++++++++++++++-
> >  1 file changed, 19 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/trace-btf.c b/src/trace-btf.c
> > index 859b0860ce2a..85f5fefb4d3b 100644
> > --- a/src/trace-btf.c
> > +++ b/src/trace-btf.c
> > @@ -32,6 +32,16 @@ struct tep_btf {
> >  #define REALLOC_SIZE (1 << 10)
> >  #define REALLOC_MASK (REALLOC_SIZE - 1)
> >
> > +#define for_each_enum(i, enum_type, member)                  \
> > +     for (i = 0, member = btf_enum(enum_type);               \
> > +          i < BTF_INFO_VLEN(enum_type->info);                \
> > +          i++, member++)
>
>
> You can make the above into:
>
>  #define for_each_enum(enum_type, member)                       \
>         for (int __i = 0, member = btf_enum(enum_type);         \
>              __i < BTF_INFO_VLEN((enum_type)->info);            \
>              __i++, member++)
>
> Then you don't need to pass in the counter "i".

Sorry, I found that the previous change causes a build failure.

The error occurs in trace-btf.c:36:
warning: initialization of 'int' from 'struct btf_enum *' makes
integer from pointer without a cast [-Wint-conversion]
   36 |         for (int __i = 0, member = btf_enum(enum_type); \

This is due to the member variable being redefined as an int type,
conflicting with its assignment of a struct btf_enum *pointer from
btf_enum(enum_type).

>
> (also it's good to put parenthesis around "enum_type").
>
> > +
> > +static inline struct btf_enum *btf_enum(const struct btf_type *t)
> > +{
> > +     return (struct btf_enum *)(t + 1);
> > +}
> > +
> >  static const char *btf_name(struct tep_btf *btf, int off)
> >  {
> >       if (off < btf->hdr->str_len)
> > @@ -546,10 +556,11 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
> >       struct tep_btf *btf = tep->btf;
> >       struct btf_type *type = tep_btf_find_func(btf, func);
> >       struct btf_param *param;
> > +     struct btf_enum *enump;
> >       unsigned long long arg;
> >       unsigned int encode;
> >       const char *param_name;
> > -     int a, p, x, nr;
> > +     int a, p, x, nr, i;
>
> And the above doesn't need to be changed.
>
> Thanks,
>
> -- Steve
>
> >
> >       if (!func)
> >               return -1;
> > @@ -628,6 +639,13 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
> >                       break;
> >               case BTF_KIND_ENUM:
> >                       trace_seq_printf(s, "%lld", arg);
> > +                     for_each_enum(i, t, enump) {
> > +                             if (arg == enump->val) {
> > +                                     trace_seq_printf(s, " [%s]",
> > +                                             btf_name(btf, enump->name_off));
> > +                                     break;
> > +                             }
> > +                     }
> >                       break;
> >               default:
> >                       /* This does not handle complex arguments */
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type
  2026-02-07  5:04   ` Donglin Peng
@ 2026-02-07 14:16     ` Steven Rostedt
  2026-02-08 12:02       ` Donglin Peng
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2026-02-07 14:16 UTC (permalink / raw)
  To: Donglin Peng; +Cc: mhiramat, linux-trace-devel, Donglin Peng

On Sat, 7 Feb 2026 13:04:02 +0800
Donglin Peng <dolinux.peng@gmail.com> wrote:

> > > +#define for_each_enum(i, enum_type, member)                  \
> > > +     for (i = 0, member = btf_enum(enum_type);               \
> > > +          i < BTF_INFO_VLEN(enum_type->info);                \
> > > +          i++, member++)  
> >
> >
> > You can make the above into:
> >
> >  #define for_each_enum(enum_type, member)                       \
> >         for (int __i = 0, member = btf_enum(enum_type);         \
> >              __i < BTF_INFO_VLEN((enum_type)->info);            \
> >              __i++, member++)
> >
> > Then you don't need to pass in the counter "i".  
> 
> Sorry, I found that the previous change causes a build failure.
> 
> The error occurs in trace-btf.c:36:
> warning: initialization of 'int' from 'struct btf_enum *' makes
> integer from pointer without a cast [-Wint-conversion]
>    36 |         for (int __i = 0, member = btf_enum(enum_type); \
> 
> This is due to the member variable being redefined as an int type,
> conflicting with its assignment of a struct btf_enum *pointer from
> btf_enum(enum_type).

Ah, I had that issue before. But this should work:

 #define for_each_enum(enum_type, member)				\
	member = btf_enum(enum_type);					\
	for (int __i = 0; __i < BTF_INFO_VLEN((enum_type)->info);	\
	     __i++, member++)

Just can't use it as a single line for if statements.

	if (x)
		for_each_enum() {
		}

But we shouldn't be doing that anyway.

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type
  2026-02-07 14:16     ` Steven Rostedt
@ 2026-02-08 12:02       ` Donglin Peng
  0 siblings, 0 replies; 6+ messages in thread
From: Donglin Peng @ 2026-02-08 12:02 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: mhiramat, linux-trace-devel, Donglin Peng

On Sat, Feb 7, 2026 at 10:16 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Sat, 7 Feb 2026 13:04:02 +0800
> Donglin Peng <dolinux.peng@gmail.com> wrote:
>
> > > > +#define for_each_enum(i, enum_type, member)                  \
> > > > +     for (i = 0, member = btf_enum(enum_type);               \
> > > > +          i < BTF_INFO_VLEN(enum_type->info);                \
> > > > +          i++, member++)
> > >
> > >
> > > You can make the above into:
> > >
> > >  #define for_each_enum(enum_type, member)                       \
> > >         for (int __i = 0, member = btf_enum(enum_type);         \
> > >              __i < BTF_INFO_VLEN((enum_type)->info);            \
> > >              __i++, member++)
> > >
> > > Then you don't need to pass in the counter "i".
> >
> > Sorry, I found that the previous change causes a build failure.
> >
> > The error occurs in trace-btf.c:36:
> > warning: initialization of 'int' from 'struct btf_enum *' makes
> > integer from pointer without a cast [-Wint-conversion]
> >    36 |         for (int __i = 0, member = btf_enum(enum_type); \
> >
> > This is due to the member variable being redefined as an int type,
> > conflicting with its assignment of a struct btf_enum *pointer from
> > btf_enum(enum_type).
>
> Ah, I had that issue before. But this should work:
>
>  #define for_each_enum(enum_type, member)                               \
>         member = btf_enum(enum_type);                                   \
>         for (int __i = 0; __i < BTF_INFO_VLEN((enum_type)->info);       \
>              __i++, member++)
>
> Just can't use it as a single line for if statements.
>
>         if (x)
>                 for_each_enum() {
>                 }
>
> But we shouldn't be doing that anyway.

Thanks. I will do it in v2.

>
> -- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-08 12:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-06  9:15 [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type Donglin Peng
2026-02-06 15:02 ` Steven Rostedt
2026-02-07  4:28   ` Donglin Peng
2026-02-07  5:04   ` Donglin Peng
2026-02-07 14:16     ` Steven Rostedt
2026-02-08 12:02       ` Donglin Peng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox