All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH v2 13/22] libtracefs: Add tracefs_instance_clear() API
Date: Thu, 28 Dec 2023 16:52:08 -0500	[thread overview]
Message-ID: <20231228215433.54854-14-rostedt@goodmis.org> (raw)
In-Reply-To: <20231228215433.54854-1-rostedt@goodmis.org>

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

Add tracefs_instance_clear() that will clear the ring buffer of a given
instance or the top level ring buffer if NULL is passed to it.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 Documentation/libtracefs-instances-manage.txt |  9 ++++++++-
 Documentation/libtracefs.txt                  |  1 +
 include/tracefs.h                             |  1 +
 src/tracefs-instance.c                        | 11 +++++++++++
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/Documentation/libtracefs-instances-manage.txt b/Documentation/libtracefs-instances-manage.txt
index 1e0735ee153c..4e5c64588772 100644
--- a/Documentation/libtracefs-instances-manage.txt
+++ b/Documentation/libtracefs-instances-manage.txt
@@ -4,7 +4,7 @@ libtracefs(3)
 NAME
 ----
 tracefs_instance_create, tracefs_instance_destroy, tracefs_instance_alloc, tracefs_instance_free,
-tracefs_instance_is_new, tracefs_instances, tracefs_instance_reset - Manage trace instances.
+tracefs_instance_is_new, tracefs_instances, tracefs_instance_clear, tracefs_instance_reset - Manage trace instances.
 
 SYNOPSIS
 --------
@@ -18,6 +18,7 @@ struct tracefs_instance pass:[*]*tracefs_instance_alloc*(const char pass:[*]_tra
 void *tracefs_instance_free*(struct tracefs_instance pass:[*]_instance_);
 bool *tracefs_instance_is_new*(struct tracefs_instance pass:[*]_instance_);
 char pass:[**]*tracefs_instances*(const char pass:[*]_regex_);
+void *tracefs_instance_clear*(struct tracefs_instance pass:[*]_instance_);
 void *tracefs_instance_reset*(struct tracefs_instance pass:[*]_instance_);
 
 --
@@ -61,6 +62,9 @@ it will match all instances that exist. The returned list must be freed with
 *tracefs_list_free*(3). Note, if no instances are found an empty list is returned
 and that too needs to be free with *tracefs_list_free*(3).
 
+The *tracefs_instance_clear()* function clears the ring buffer of the given _instance_
+or the top level ring buffer if _instance_ is NULL.
+
 The *tracefs_instance_reset*() function resets the given _instance_ to its default state.
 
 RETURN VALUE
@@ -83,6 +87,9 @@ The list must be freed with *tracefs_list_free*(3). An empty list is returned if
 no instance exists that matches _regex_, and this needs to be freed with
 *tracefs_list_free*(3) as well. NULL is returned on error.
 
+The *tracefs_instance_clear()* returns 0 if it successfully cleared the ring buffer,
+or -1 on error.
+
 EXAMPLE
 -------
 [source,c]
diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt
index 529922580f8d..273423cecf4a 100644
--- a/Documentation/libtracefs.txt
+++ b/Documentation/libtracefs.txt
@@ -25,6 +25,7 @@ Trace instances:
 	struct tracefs_instance pass:[*]*tracefs_instance_alloc*(const char pass:[*]_tracing_dir_, const char pass:[*]_name_);
 	void *tracefs_instance_free*(struct tracefs_instance pass:[*]_instance_);
 	char pass:[**]*tracefs_instances*(const char pass:[*]_regex_);
+	void *tracefs_instance_clear*(struct tracefs_instance pass:[*]_instance_);
 	void *tracefs_instance_reset*(struct tracefs_instance pass:[*]_instance_);
 	bool *tracefs_instance_is_new*(struct tracefs_instance pass:[*]_instance_);
 	bool *tracefs_file_exists*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_name_);
diff --git a/include/tracefs.h b/include/tracefs.h
index 4be66b488536..31aba92d9a16 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -25,6 +25,7 @@ struct tracefs_instance;
 
 void tracefs_instance_free(struct tracefs_instance *instance);
 void tracefs_instance_reset(struct tracefs_instance *instance);
+int tracefs_instance_clear(struct tracefs_instance *instance);
 struct tracefs_instance *tracefs_instance_create(const char *name);
 struct tracefs_instance *tracefs_instance_alloc(const char *tracing_dir,
 						const char *name);
diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index b019836333a3..4e7434157109 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -1409,6 +1409,17 @@ static void clear_func_filters(struct tracefs_instance *instance)
 		clear_func_filter(instance, files[i]);
 }
 
+/**
+ * tracefs_instance_clear - clear the trace buffer
+ * @instance: The instance to clear the trace for.
+ *
+ * Returns 0 on succes, -1 on error
+ */
+int tracefs_instance_clear(struct tracefs_instance *instance)
+{
+	return tracefs_instance_file_clear(instance, "trace");
+}
+
 /**
  * tracefs_instance_reset - Reset a ftrace instance to its default state
  * @instance - a ftrace instance to be reseted
-- 
2.42.0


  parent reply	other threads:[~2023-12-28 21:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28 21:51 [PATCH v2 00/22] libtracefs: Several updates Steven Rostedt
2023-12-28 21:51 ` [PATCH v2 01/22] libtracefs Documentation: Fix tracefs_event_file_exists() issues Steven Rostedt
2023-12-28 21:51 ` [PATCH v2 02/22] libtracefs testing: Use one tep handle for most tests Steven Rostedt
2023-12-28 21:51 ` [PATCH v2 03/22] libtracefs: Free "missed_followers" of instance Steven Rostedt
2023-12-28 21:51 ` [PATCH v2 04/22] libtracefs: Free buf in clear_func_filter() Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 05/22] libtracefs: Free tracing_dir in case of remount Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 06/22] libtracefs: Free dynamic event list in utest Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 07/22] libtracefs: Reset tracing before and after unit tests Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 08/22] libtracefs: Add API to remove followers from an instance or toplevel Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 09/22] libtracefs: Increase splice to use pipe max size Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 10/22] libtracefs: Add tracefs_instance_file_write_number() Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 11/22] libtracefs: Add API to read tracefs_cpu and return a kbuffer Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 12/22] libtracefs: Add tracefs_instance_get/set_buffer_percent() Steven Rostedt
2023-12-28 21:52 ` Steven Rostedt [this message]
2023-12-28 21:52 ` [PATCH v2 14/22] libtracefs utest: Add test to test tracefs_instance_set/get_buffer_percent() Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 15/22] libtracefs: Add kerneldoc comments to tracefs_instance_set_buffer_size() Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 16/22] libtracefs: Add tracefs_load_headers() API Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 17/22] libtracefs: Add API to extract ring buffer statistics Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 18/22] libtracefs: Add tracefs_instance_set/get_subbuf_size() Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 19/22] libtracefs: Add TIMESTAMP_USECS_DELTA to simplify SQL timestamp compares Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 20/22] libtracefs: Also clear max_graph_depth on reset Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 21/22] libtracefs: Add PID filtering API Steven Rostedt
2023-12-28 21:52 ` [PATCH v2 22/22] libtracefs: Add updating and reading snapshot buffers 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=20231228215433.54854-14-rostedt@goodmis.org \
    --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 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.