linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd record: Write set_ftrace_filter commands separately
@ 2021-05-05 14:19 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2021-05-05 14:19 UTC (permalink / raw)
  To: Linux Trace Devel

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Using tracefs_function_filter() to enable function filters allowed for
more flexibility on the command line for using regex to enable functions,
but it also broke setting commands like "stacktrace" and "traceoff".

If the filter contains ":" then write it directly into the file instead of
going through the tracefs_function_filter interface.

Fixes: f73378a7b ("trace-cmd record: Use tracefs_filter_function() for function filtering")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 4636475f..9daf4b05 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4354,10 +4354,15 @@ enum filter_type {
 	FUNC_NOTRACE,
 };
 
+static int filter_command(struct tracefs_instance *instance, const char *cmd)
+{
+	return tracefs_instance_file_append(instance, "set_ftrace_filter", cmd);
+}
+
 static int write_func_filter(enum filter_type type, struct buffer_instance *instance,
 			     struct func_list **list)
 {
-	struct func_list *item;
+	struct func_list *item, *cmds = NULL;
 	const char *file;
 	int ret = -1;
 	int (*filter_function)(struct tracefs_instance *instance, const char *filter,
@@ -4385,6 +4390,12 @@ static int write_func_filter(enum filter_type type, struct buffer_instance *inst
 	while (*list) {
 		item = *list;
 		*list = item->next;
+		/* Do commands separately at the end */
+		if (type == FUNC_FILTER && strstr(item->func, ":")) {
+			item->next = cmds;
+			cmds = item;
+			continue;
+		}
 		ret = filter_function(instance->tracefs, item->func, item->mod,
 				      TRACEFS_FL_CONTINUE);
 		if (ret < 0)
@@ -4392,6 +4403,16 @@ static int write_func_filter(enum filter_type type, struct buffer_instance *inst
 		free(item);
 	}
 	ret = filter_function(instance->tracefs, NULL, NULL, 0);
+
+	/* Now add any commands */
+	while (cmds) {
+		item = cmds;
+		cmds = item->next;
+		ret = filter_command(instance->tracefs, item->func);
+		if (ret < 0)
+			goto failed;
+		free(item);
+	}
 	return ret;
  failed:
 	die("Failed to write %s to %s.\n"
-- 
2.29.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-05 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 14:19 [PATCH] trace-cmd record: Write set_ftrace_filter commands separately Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).