Re: [PATCH v7 0/4] tracing: improve symbolic printing

From: Steven Rostedt

Date: Thu Nov 05 2026 - 11:35:42 EST


On Thu, 05 Nov 2026 16:04:21 +0100
Johannes Berg <johannes@xxxxxxxxxxxxxxxx> wrote:

> On Thu, 2026-11-05 at 09:12 -0500, Steven Rostedt wrote:
> > Could you also add code in the samples/trace_events directory. Perhaps add
> > a new event?
> >
> > This will make it easier to understand exactly how to add new __print_sym()s.
>
> I guess so. I was kinda hoping to simply convert all the others - it
> clearly has advantages this way.
>
> Any objection to simply converting the __print_symbolic() sample? It
> would look something like this:

Actually, keeping them both would be very useful. That way one can see how
to do it the other way. We can say, the old way is being deprecated so
please use the new way.


>
>
> --- a/samples/trace_events/trace-events-sample.h
> +++ b/samples/trace_events/trace-events-sample.h
> @@ -297,6 +297,28 @@ TRACE_DEFINE_ENUM(TRACE_SAMPLE_FOO);
> TRACE_DEFINE_ENUM(TRACE_SAMPLE_BAR);
> TRACE_DEFINE_ENUM(TRACE_SAMPLE_ZOO);
>
> +/* define the names as { value, "name" } tuples for __print_sym() below */
> +TRACE_DEFINE_SYM_LIST(sample_names,
> + { 0, "zero" },
> + { TRACE_SAMPLE_FOO, "TWO" },
> + { TRACE_SAMPLE_BAR, "FOUR" },
> + { TRACE_SAMPLE_ZOO, "EIGHT" },
> + { 10, "TEN" }
> +);
> +
> +/*
> + * Alternatively, you could define a function for the names:
> + *
> + * The _lookup() function returns the string for the given value.
> + *
> + * The _show() function must
> + * seq_printf(m, ", { %u, \"%s\" }", value, name);
> + * for each value that userspace should be able to parse.
> + */
> +const char *sample_names2_lookup(unsigned long long value);
> +void sample_names2_show(struct seq_file *m);

Are the above going to be defined somewhere?

> +TRACE_DEFINE_SYM_FNS(sample_names2, sample_names2_lookup, sample_names2_show);
> +
> TRACE_EVENT(foo_bar,
>
> TP_PROTO(const char *foo, int bar, const int *lst,
> @@ -340,14 +362,10 @@ TRACE_EVENT(foo_bar,
> * the variable matches one of the values, then it will print the
> * string in that pair. If non are matched, it returns a string
> * version of the number (if __entry->bar == 7 then "7" is returned).
> + *
> + * See above for the declaration of "sample_names".
> */
> - __print_symbolic(__entry->bar,
> - { 0, "zero" },
> - { TRACE_SAMPLE_FOO, "TWO" },
> - { TRACE_SAMPLE_BAR, "FOUR" },
> - { TRACE_SAMPLE_ZOO, "EIGHT" },
> - { 10, "TEN" }
> - ),
> + __print_sym(__entry->bar, sample_names),
>
> /*
> * __print_flags( variable, "delim", { value, "flag" }, ... ),
>
>
>
> It did show a bug because TRACE_SYSTEM isn't a C var in that file (and
> perhaps only in that file?), so I'll have to resend with that fixed
> anyway.
>
>
> > FYI, this series did pass all my tests.
>
> Cool. Sorry the earlier (long time ago) version had the __init_data
> issue, I'd mostly tested on UML and that wasn't protected there.
>

Thanks,

-- Steve