linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH v2] trace-cmd record: Write set_ftrace_filter commands separately
Date: Thu, 6 May 2021 11:10:53 -0400	[thread overview]
Message-ID: <20210506111053.7fba9df5@gandalf.local.home> (raw)

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>
---

Changes since v1:

 - Open coded the tracefs_instance_file_append(), as that is not part
   of libtracefs 1.1, and I did not want to up the required library
   to 1.2.

 tracecmd/trace-record.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index fd03a605..3ce35d76 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4356,10 +4356,28 @@ enum filter_type {
 	FUNC_NOTRACE,
 };
 
+static int filter_command(struct tracefs_instance *instance, const char *cmd)
+{
+	char *path;
+	int ret;
+	int fd;
+
+	path = tracefs_instance_get_file(instance, "set_ftrace_filter");
+	if (!path)
+		return -1;
+	fd = open(path, O_WRONLY);
+	tracefs_put_tracing_file(path);
+	if (fd < 0)
+		return -1;
+	ret = write(fd, cmd, strlen(cmd));
+	close(fd);
+	return ret;
+}
+
 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,
@@ -4387,6 +4405,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)
@@ -4394,6 +4418,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


                 reply	other threads:[~2021-05-06 15:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210506111053.7fba9df5@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).