On Mon,  2 Feb 2026 19:15:48 +0800
Donglin Peng <[email protected]> wrote:

> From: Donglin Peng <[email protected]>
> 
> Use BTF to print symbolic names for enum-type function arguments,
> improving trace readability.
> 
> Before:
> count_memcg_events(memcg=0xffff..., idx=20, count=0x1) {
> 
> After:
> count_memcg_events(memcg=0xffff..., idx=20 [PGFAULT], count=0x1) {

Hmm, it is interesting idea. Maybe I can also introduce the same
feature to fetcharg for fprobe/kprobes as a new type.
Since the enum type should be solved in parsing the event definition,
for fprobe/kprobes the performance will not be a performance problem.

Thanks,

> 
> Cc: Steven Rostedt <[email protected]>
> Cc: Masami Hiramatsu <[email protected]>
> Cc: [email protected]
> Signed-off-by: Donglin Peng <[email protected]>
> ---
>  kernel/trace/trace_output.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index cc2d3306bb60..c395f768c3b8 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -695,12 +695,13 @@ void print_function_args(struct trace_seq *s, unsigned 
> long *args,
>  {
>       const struct btf_param *param;
>       const struct btf_type *t;
> +     const struct btf_enum *enump;
>       const char *param_name;
>       char name[KSYM_NAME_LEN];
>       unsigned long arg;
>       struct btf *btf;
>       s32 tid, nr = 0;
> -     int a, p, x;
> +     int a, p, x, i;
>       u16 encode;
>  
>       trace_seq_printf(s, "(");
> @@ -754,6 +755,14 @@ void print_function_args(struct trace_seq *s, unsigned 
> long *args,
>                       break;
>               case BTF_KIND_ENUM:
>                       trace_seq_printf(s, "%ld", arg);
> +                     for_each_enum(i, t, enump) {
> +                             if (arg == enump->val) {
> +                                     trace_seq_printf(s, " [%s]",
> +                                                      btf_name_by_offset(btf,
> +                                                      enump->name_off));
> +                                     break;
> +                             }
> +                     }
>                       break;
>               default:
>                       /* This does not handle complex arguments */
> -- 
> 2.34.1
> 


-- 
Masami Hiramatsu (Google) <[email protected]>

Reply via email to