[PATCH] trace-cmd record: Mention '-l' if '-f' is used with function tracer and without events
Steven Rostedt <[email protected]> Thu, 5 Feb 2026 16:12:42 -0500
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
From: "Steven Rostedt (Google)" <[email protected]> A question was asked on stackoverflow on how to use filtering with function tracer. The user was using '-f' instead of '-l'. This could be a common mistake. Print a message referencing the '-l' command if '-f' is used without an event but with function or function graph tracing. Link: https://stackoverflow.com/questions/79862514/how-to-function-trace-a-custom-linux-kernel-module-with-trace-cmd Signed-off-by: Steven Rostedt (Google) <[email protected]> --- tracecmd/trace-record.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 9fbd60a9..1966ec14 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -6439,6 +6439,15 @@ bool trace_tsc2nsec_is_supported(void) return get_tsc_nsec(NULL, NULL) == 0; } +static bool is_function(const char *tracer) +{ + if (!tracer) + return false; + + return strcmp(tracer, "function") == 0 || + strcmp(tracer, "function_graph"); +} + static void parse_record_options(int argc, char **argv, enum trace_cmd curr_cmd, @@ -6550,8 +6559,14 @@ static void parse_record_options(int argc, list_event(optarg); break; case 'f': - if (!last_event) - die("filter must come after event"); + if (!last_event) { + const char *s = ""; + + if (is_function(ctx->instance->plugin)) + s = "\n Did you mean to filter functions? Then use: -l <filter>"; + die("filter must come after event%s", s); + } + if (last_event->filter) { last_event->filter = realloc(last_event->filter, -- 2.50.1