mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: Steven Rostedt <rostedt@goodmis.org>,
	 Masami Hiramatsu <mhiramat@kernel.org>,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH RFC 7/7] tracing: Parse filter from event string
Date: Thu, 13 Aug 2026 16:07:20 +0200	[thread overview]
Message-ID: <20260813-tracing-cli-event-filter-v1-7-57c4e8029c86@linutronix.de> (raw)
In-Reply-To: <20260813-tracing-cli-event-filter-v1-0-57c4e8029c86@linutronix.de>

Make it possible to specify a trace event filter from the
kernel command line.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

---
For the non-RFC patch this should probably be limited to only apply to
the cmdline path.
---
 kernel/trace/trace.h             |  3 ++-
 kernel/trace/trace_events.c      | 13 +++++++++----
 kernel/trace/trace_events_test.c | 20 +++++++++++++++++---
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 6bf4f031efa8..9102bf0a45a9 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -2507,5 +2507,6 @@ static inline int rv_init_interface(void)
 #endif /* _LINUX_KERNEL_TRACE_H */
 
 #if IS_ENABLED(CONFIG_KUNIT)
-void ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, char **mod);
+void ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, char **mod,
+			       char **filter);
 #endif
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index c24929d003dd..d4c46b24c382 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1426,10 +1426,12 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
 }
 
 VISIBLE_IF_KUNIT void
-ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, char **mod)
+ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, char **mod,
+			  char **filter)
 {
 	*event = NULL;
 	*sub = NULL;
+	*filter = NULL;
 
 	/* Modules events can be appended with :mod:<module> */
 	*mod = strstr(buf, ":mod:");
@@ -1453,6 +1455,9 @@ ftrace_parse_event_string(char *buf, char **match, char **sub, char **event, cha
 
 	*match = strsep(&buf, ":");
 	if (buf) {
+		*filter = buf;
+		strsep(filter, ":");
+
 		*sub = *match;
 		*event = buf;
 		*match = NULL;
@@ -1471,7 +1476,7 @@ EXPORT_SYMBOL_IF_KUNIT(ftrace_parse_event_string);
 
 int ftrace_set_clr_event(struct trace_array *tr, const char *_buf, int set)
 {
-	char *event, *sub, *match, *mod;
+	char *event, *sub, *match, *mod, *filter;
 
 	if (!tr)
 		return -ENOENT;
@@ -1480,9 +1485,9 @@ int ftrace_set_clr_event(struct trace_array *tr, const char *_buf, int set)
 	if (!buf)
 		return -ENOMEM;
 
-	ftrace_parse_event_string(buf, &match, &sub, &event, &mod);
+	ftrace_parse_event_string(buf, &match, &sub, &event, &mod, &filter);
 
-	return __ftrace_set_clr_event(tr, match, sub, event, set, mod, NULL);
+	return __ftrace_set_clr_event(tr, match, sub, event, set, mod, filter);
 }
 
 /**
diff --git a/kernel/trace/trace_events_test.c b/kernel/trace/trace_events_test.c
index e090a699b8d5..fd54eb03b58f 100644
--- a/kernel/trace/trace_events_test.c
+++ b/kernel/trace/trace_events_test.c
@@ -8,7 +8,7 @@
 struct parse_event_test_case {
 	const char *input;
 
-	const char *match, *sub, *event, *mod;
+	const char *match, *sub, *event, *mod, *filter;
 };
 
 static const struct parse_event_test_case parse_event_test_cases[] = {
@@ -37,6 +37,12 @@ static const struct parse_event_test_case parse_event_test_cases[] = {
 		.sub	= "sub",
 		.event	= "event",
 	},
+	{
+		"sub:event:filter",
+		.sub	= "sub",
+		.event	= "event",
+		.filter	= "filter",
+	},
 	{
 		"match",
 		.match	= "match",
@@ -51,6 +57,13 @@ static const struct parse_event_test_case parse_event_test_cases[] = {
 		.event	= "event",
 		.mod	= "module",
 	},
+	{
+		"sub:event:filter:mod:module",
+		.sub	= "sub",
+		.event	= "event",
+		.mod	= "module",
+		.filter	= "filter",
+	},
 };
 
 static void parse_event_test_desc(const struct parse_event_test_case *params, char *desc)
@@ -71,18 +84,19 @@ KUNIT_ARRAY_PARAM(parse_event, parse_event_test_cases, parse_event_test_desc);
 static void parse_event(struct kunit *test)
 {
 	const struct parse_event_test_case *params = test->param_value;
-	char *input, *match, *sub, *event, *mod;
+	char *input, *match, *sub, *event, *mod, *filter;
 
 	input = kunit_kstrdup(test, params->input, GFP_KERNEL);
 	if (!input)
 		kunit_skip(test, "ENOMEM");
 
-	ftrace_parse_event_string(input, &match, &sub, &event, &mod);
+	ftrace_parse_event_string(input, &match, &sub, &event, &mod, &filter);
 
 	EXPECT_NULL_OR_STR_EQ(test, match, params->match);
 	EXPECT_NULL_OR_STR_EQ(test, sub, params->sub);
 	EXPECT_NULL_OR_STR_EQ(test, event, params->event);
 	EXPECT_NULL_OR_STR_EQ(test, mod, params->mod);
+	EXPECT_NULL_OR_STR_EQ(test, filter, params->filter);
 }
 
 static struct kunit_case trace_events_test_cases[] = {

-- 
2.55.0


  parent reply	other threads:[~2026-08-13 14:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13 14:07 [PATCH RFC 0/7] " Thomas Weißschuh
2026-08-13 14:07 ` [PATCH RFC 1/7] tracing: Restore :mod: trailer after parsing in ftrace_set_clr_event() Thomas Weißschuh
2026-08-13 14:07 ` [PATCH RFC 2/7] tracing: Remove duplicate declaration of ftrace_set_clr_event() Thomas Weißschuh
2026-08-13 14:07 ` [PATCH RFC 3/7] tracing: Stop modifying the input buffer in ftrace_set_clr_event() Thomas Weißschuh
2026-08-13 14:07 ` [PATCH RFC 4/7] tracing: Split the event string parsing logic into a dedicated function Thomas Weißschuh
2026-08-13 14:07 ` [PATCH RFC 5/7] tracing: Add a test for ftrace_parse_event_string() Thomas Weißschuh
2026-08-13 14:07 ` [PATCH RFC 6/7] tracing: Add a filter argument to __ftrace_set_clr_event() Thomas Weißschuh
2026-08-13 14:07 ` Thomas Weißschuh [this message]
2026-08-13 16:22   ` [PATCH RFC 7/7] tracing: Parse filter from event string Masami Hiramatsu

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=20260813-tracing-cli-event-filter-v1-7-57c4e8029c86@linutronix.de \
    --to=thomas.weissschuh@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@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®