mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	 netdev@vger.kernel.org, Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Ilya Maximets <i.maximets@ovn.org>,
	Matthieu Baerts	 <matttbe@kernel.org>,
	Aaron Conole <aconole@redhat.com>,
	Eelco Chaudron	 <echaudro@redhat.com>,
	dev@openvswitch.org, Adrian Moreno <amorenoz@redhat.com>,
	 Antoine Tenart <atenart@kernel.org>
Subject: Re: [PATCH v7 0/4] tracing: improve symbolic printing
Date: Thu, 05 Nov 2026 16:04:21 +0100	[thread overview]
Message-ID: <8da2902c233de42ce756b3bfba5e5821f4dfa82b.camel@sipsolutions.net> (raw)
In-Reply-To: <20261105091216.7b91db5a@gandalf.local.home>

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:


--- 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);
+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.

johannes

  reply	other threads:[~2026-11-05 15:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 11:08 Johannes Berg
2026-09-22 11:08 ` [PATCH v7 1/4] tracing: add __print_sym() to replace __print_symbolic() Johannes Berg
2026-09-22 11:08 ` [PATCH v7 2/4] tracing/timer: use __print_sym() Johannes Berg
2026-09-22 11:08 ` [PATCH v7 3/4] net: dropreason: use new __print_sym() in tracing Johannes Berg
2026-09-24 15:31   ` Ilya Maximets
2026-09-28 13:34   ` Aaron Conole
2026-09-22 11:08 ` [PATCH v7 4/4] net: drop_monitor: use drop_reason_lookup() Johannes Berg
2026-11-05 14:12 ` [PATCH v7 0/4] tracing: improve symbolic printing Steven Rostedt
2026-11-05 15:04   ` Johannes Berg [this message]
2026-11-05 16:24     ` Steven Rostedt
2026-11-05 16:26       ` Johannes Berg
2026-11-05 16:38         ` Steven Rostedt
2026-11-05 17:09           ` Johannes Berg

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=8da2902c233de42ce756b3bfba5e5821f4dfa82b.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=aconole@redhat.com \
    --cc=amorenoz@redhat.com \
    --cc=atenart@kernel.org \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=i.maximets@ovn.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=matttbe@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=netdev@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®