[PATCH v2] libtraceevent: Pretty print function parameters of enum-type
Donglin Peng <[email protected]> Sun, 8 Feb 2026 20:44:06 +0800
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Donglin Peng <[email protected]> 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 <[email protected]> Cc: Masami Hiramatsu <[email protected]> Signed-off-by: Donglin Peng <[email protected]> --- v1 -> v2: - Refactor for_each_enum helper macro to use internal loop variable __i (thanks to Steve) --- src/trace-btf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/trace-btf.c b/src/trace-btf.c index 859b0860ce2a..2d66e0113077 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(enum_type, member) \ + member = btf_enum(enum_type); \ + for (int __i = 0; __i < BTF_INFO_VLEN((enum_type)->info); \ + __i++, member++) + +static inline struct btf_enum *btf_enum(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,6 +556,7 @@ 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; @@ -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(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