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) {

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


Reply via email to