All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: Sameeruddin shaik <sameeross1994@gmail.com>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 1/4] libtracefs: Add custom tracer to tracefs_tracer_set()
Date: Fri, 25 Jun 2021 18:17:36 -0400	[thread overview]
Message-ID: <20210625221739.1215557-2-rostedt@goodmis.org> (raw)
In-Reply-To: <20210625221739.1215557-1-rostedt@goodmis.org>

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

Allow the user to enter their own string to define a tracer using
TRACEFS_TRACER_CUSTOM. This way if there's a tracer that is not yet
supported by libtracefs, the user could still enable the tracer with the
tracefs_tracer_set() functionality, as well as use the enums to set
tracers.

 For example:

   tracefs_tracer_set(NULL, TRACEFS_TRACER_CUSTOM, "osnoise");

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs.h   |  3 ++-
 src/tracefs-tools.c | 28 +++++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/include/tracefs.h b/include/tracefs.h
index 50873f3..75905ec 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -186,6 +186,7 @@ void tracefs_set_loglevel(enum tep_loglevel level);
 
 enum tracefs_tracers {
 	TRACEFS_TRACER_NOP = 0,
+	TRACEFS_TRACER_CUSTOM,
 	TRACEFS_TRACER_FUNCTION,
 	TRACEFS_TRACER_FUNCTION_GRAPH,
 	TRACEFS_TRACER_IRQSOFF,
@@ -200,7 +201,7 @@ enum tracefs_tracers {
 	TRACEFS_TRACER_BLOCK,
 };
 
-int tracefs_tracer_set(struct tracefs_instance *instance, enum tracefs_tracers tracer);
+int tracefs_tracer_set(struct tracefs_instance *instance, enum tracefs_tracers tracer, ...);
 
 int tracefs_tracer_clear(struct tracefs_instance *instance);
 #endif /* _TRACE_FS_H */
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index 21efa6e..fb243d8 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -7,6 +7,7 @@
  *
  */
 #include <stdlib.h>
+#include <stdarg.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
@@ -29,6 +30,7 @@ __hidden pthread_mutex_t toplevel_lock = PTHREAD_MUTEX_INITIALIZER;
 
 #define TRACERS \
 	C(NOP,                  "nop"),			\
+	C(CUSTOM,		"CUSTOM"),		\
 	C(FUNCTION,             "function"),            \
 	C(FUNCTION_GRAPH,       "function_graph"),      \
 	C(IRQSOFF,              "irqsoff"),             \
@@ -950,11 +952,20 @@ int write_tracer(int fd, const char *tracer)
 /**
  * tracefs_set_tracer - function to set the tracer
  * @instance: ftrace instance, can be NULL for top tracing instance
- * @tracer: Tracer that has to be set, which can be integer from 0 - 12
- * or enum value
+ * @tracer: The tracer enum that defines the tracer to be set
+ * @t: A tracer name if TRACEFS_TRACER_CUSTOM is passed in for @tracer
+ *
+ * Set the tracer for the instance based on the tracefs_tracer enums.
+ * If the user wishes to enable a tracer that is not defined by
+ * the enum (new or custom kernel), the tracer can be set to
+ * TRACEFS_TRACER_CUSTOM, and pass in a const char * name for
+ * the tracer to set.
+ *
+ * Returns 0 on succes, negative on error.
  */
 
-int tracefs_tracer_set(struct tracefs_instance *instance, enum tracefs_tracers tracer)
+int tracefs_tracer_set(struct tracefs_instance *instance,
+		       enum tracefs_tracers tracer, ...)
 {
 	char *tracer_path = NULL;
 	const char *t = NULL;
@@ -976,9 +987,16 @@ int tracefs_tracer_set(struct tracefs_instance *instance, enum tracefs_tracers t
 		errno = -ENODEV;
 		goto out;
 	}
-	if (tracer == tracer_enums[tracer])
+
+	if (tracer == TRACEFS_TRACER_CUSTOM) {
+		va_list ap;
+
+		va_start(ap, tracer);
+		t = va_arg(ap, const char *);
+		va_end(ap);
+	} else if (tracer == tracer_enums[tracer]) {
 		t = tracers[tracer];
-	else {
+	} else {
 		for (i = 0; i < ARRAY_SIZE(tracer_enums); i++) {
 			if (tracer == tracer_enums[i]) {
 				t = tracers[i];
-- 
2.30.2


  reply	other threads:[~2021-06-25 22:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-25 22:17 [PATCH 0/4] libtracefs: Updates to tracefs_tracer_set() Steven Rostedt
2021-06-25 22:17 ` Steven Rostedt [this message]
2021-06-25 22:17 ` [PATCH 2/4] libtracefs: Fix the errno values of tracefs_tracer_set() Steven Rostedt
2021-06-25 22:17 ` [PATCH 3/4] libtracefs: Check tracer parameter first in tracefs_tracer_set() Steven Rostedt
2021-06-25 22:17 ` [PATCH 4/4] libtracefs: Add documentation for tracefs_tracer_set/clear() 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=20210625221739.1215557-2-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=sameeross1994@gmail.com \
    /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.