All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	Sameeruddin shaik <sameeruddin.shaik8@gmail.com>
Subject: [PATCH] libtracefs: New API to trace only specific functions by instance
Date: Mon, 22 Feb 2021 17:54:21 +0530	[thread overview]
Message-ID: <1613996661-6525-1-git-send-email-sameeruddin.shaik8@gmail.com> (raw)
In-Reply-To: <[PATCH][WIP]libtracefs:New API to enable the filtering of functions>

This new API can be used to set the specific functions to be traced.

tracefs_function_filter

Signed-off-by: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>

diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index 187870e..e8ad1f9 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -20,6 +20,7 @@ void warning(const char *fmt, ...);
 int str_read_file(const char *file, char **buffer);
 char *trace_append_file(const char *dir, const char *name);
 char *trace_find_tracing_dir(void);
+int controlled_write(const char *path, const char* const *filter, bool reset);
 
 #ifndef ACCESSPERMS
 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
diff --git a/include/tracefs.h b/include/tracefs.h
index f3eec62..37eab87 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -50,6 +50,7 @@ int tracefs_trace_on(struct tracefs_instance *instance);
 int tracefs_trace_off(struct tracefs_instance *instance);
 int tracefs_trace_on_fd(int fd);
 int tracefs_trace_off_fd(int fd);
+int tracefs_function_filter(struct tracefs_instance *instance, const char* const *filter, bool reset);
 
 /**
  * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index e2dfc7b..709f1e7 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -18,6 +18,7 @@
 #include "tracefs-local.h"
 
 #define TRACE_CTRL	"tracing_on"
+#define TRACE_FILTER      "set_ftrace_filter"
 
 static const char * const options_map[] = {
 	"unknown",
@@ -387,3 +388,28 @@ void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt
 	if (options && id > TRACEFS_OPTION_INVALID)
 		options->mask &= ~(1ULL << (id - 1));
 }
+
+/**
+ * tracefs_function_filter - write to set_ftrace_filter file to trace particular functions
+ * @instance: ftrace instance, can be NULL for top tracing instnace
+ * @filter: const pointer to an array of const function names
+ * @reset: Boolean value to reset the file
+ */
+int tracefs_function_filter(struct tracefs_instance *instance, const char * const *filters, bool reset)
+{
+	char *ftrace_filter_path;
+	int ret;
+
+	if (!filters)
+		return -1;
+	ftrace_filter_path = tracefs_instance_get_file(instance, TRACE_FILTER);
+
+	if (!ftrace_filter_path)
+		goto gracefully_free;
+
+	ret = controlled_write(ftrace_filter_path, filters, reset);
+
+ gracefully_free:
+	tracefs_put_tracing_file(ftrace_filter_path);
+	return ret;
+}
diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c
index 0e96f8e..1cd98a2 100644
--- a/src/tracefs-utils.c
+++ b/src/tracefs-utils.c
@@ -228,3 +228,23 @@ __hidden int str_read_file(const char *file, char **buffer)
 
 	return size;
 }
+
+__hidden int controlled_write(const char *filter_path, const char * const *filters, bool reset)
+{
+	int size = 0;
+	int fd;
+	int i;
+
+	if (!filters)
+		return -1;
+	if (reset)
+		fd = open(filter_path, O_WRONLY | O_APPEND | O_TRUNC);
+	else
+		fd = open(filter_path, O_WRONLY | O_APPEND);
+	if (fd < 0)
+		return -1;
+	for (i = 0; filters[i] != NULL ; i++)
+		size += write(fd, *(filters + i), strlen(*(filters + i)));
+	close(fd);
+	return size;
+}
-- 
2.7.4


       reply	other threads:[~2021-02-21 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <[PATCH][WIP]libtracefs:New API to enable the filtering of functions>
2021-02-22 12:24 ` Sameeruddin shaik [this message]
2021-02-22 12:40   ` [PATCH] libtracefs: New API to trace only specific functions by instance Sameeruddin Shaik
2021-02-21 15:28     ` Steven Rostedt
2021-02-22 14:52   ` Steven Rostedt

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=1613996661-6525-1-git-send-email-sameeruddin.shaik8@gmail.com \
    --to=sameeruddin.shaik8@gmail.com \
    --cc=linux-trace-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.