From: Donglin Peng <dolinux.peng@gmail.com>
To: rostedt@goodmis.org
Cc: mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org,
Donglin Peng <pengdonglin@xiaomi.com>
Subject: [PATCH] libtraceevent: Pretty print function parameters of enum-type
Date: Fri, 6 Feb 2026 16:40:41 +0800 [thread overview]
Message-ID: <20260206084041.2049369-1-dolinux.peng@gmail.com> (raw)
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
reply other threads:[~2026-02-06 8:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260206084041.2049369-1-dolinux.peng@gmail.com \
--to=dolinux.peng@gmail.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=pengdonglin@xiaomi.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox