All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 4/4] libtracefs: New API for applying filter on event
Date: Thu,  2 Dec 2021 12:59:26 +0200	[thread overview]
Message-ID: <20211202105926.32581-5-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20211202105926.32581-1-tz.stoyanov@gmail.com>

There is no API for applying a filter string on event. Existing APIs
only constructs and verifies the filter string. Even though the actual
applying is just writing into the event's filter file, it is good to
have a dedicated API for that:
	tracefs_event_filter_apply()

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 Documentation/libtracefs-filter.txt | 12 ++++++++++--
 include/tracefs.h                   |  5 +++++
 src/tracefs-filter.c                | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Documentation/libtracefs-filter.txt b/Documentation/libtracefs-filter.txt
index 23a2abf..7db3d60 100644
--- a/Documentation/libtracefs-filter.txt
+++ b/Documentation/libtracefs-filter.txt
@@ -3,7 +3,8 @@ libtracefs(3)
 
 NAME
 ----
-tracefs_filter_string_append, tracefs_filter_string_verify - Add and verify event filters
+tracefs_filter_string_append, tracefs_filter_string_verify, tracefs_event_apply_filter -
+Add, verify and apply event filters
 
 SYNOPSIS
 --------
@@ -15,7 +16,7 @@ int tracefs_filter_string_append(struct tep_event pass:[*]event, char pass:[**]
 				 struct tracefs_filter type, const char pass:[*]field,
 				 enum tracefs_synth_compare compare, const char pass:[*]val);
 int tracefs_filter_string_verify(struct tep_event pass:[*]event, const char pass:[*]filter, char pass:[**]err);
-
+int tracefs_event_filter_apply(struct tracefs_instance pass:[*]instance, struct tep_event pass:[*]event, const char pass:[*]filter);
 --
 
 DESCRIPTION
@@ -66,6 +67,8 @@ error in the syntax, and _err_ is not NULL, then it will be allocated with an
 error message stating what was found wrong with the filter. _err_ must be freed
 with *free*().
 
+*tracefs_event_filter_apply*() applies given _filter_ string on _event_ in given _instance_.
+
 RETURN VALUE
 ------------
 *tracefs_filter_string_append*() returns 0 on success and -1 on error.
@@ -75,6 +78,8 @@ is an error, and _errno_ is not *ENOMEM*, then _err_ is allocated and will
 contain a string describing what was found wrong with _filter_. _err_ must be
 freed with *free*().
 
+*tracefs_event_filter_apply*() returns 0 on success and -1 on error.
+
 EXAMPLE
 -------
 [source,c]
@@ -269,6 +274,9 @@ int main (int argc, char **argv)
 		}
 	}
 
+	if (tracefs_event_filter_apply(NULL, event, new_filter))
+		fprintf(stderr, "Failed to apply filter on event");
+
 	tep_free(tep);
 
 	printf("Created new filter: '%s'\n", new_filter);
diff --git a/include/tracefs.h b/include/tracefs.h
index 383974b..ac92dca 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -476,6 +476,10 @@ int tracefs_filter_string_append(struct tep_event *event, char **filter,
 int tracefs_filter_string_verify(struct tep_event *event, const char *filter,
 				 char **err);
 
+int tracefs_event_filter_apply(struct tracefs_instance *instance,
+			       struct tep_event *event, const char *filter);
+
+
 /** Deprecated do not use: Instead use tracefs_filter_string_append() **/
 int tracefs_event_append_filter(struct tep_event *event, char **filter,
 				enum tracefs_filter type,
@@ -486,6 +490,7 @@ int tracefs_event_append_filter(struct tep_event *event, char **filter,
 int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
 				char **err);
 
+
 #define TRACEFS_TIMESTAMP "common_timestamp"
 #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs"
 
diff --git a/src/tracefs-filter.c b/src/tracefs-filter.c
index e65fd94..7bc36fe 100644
--- a/src/tracefs-filter.c
+++ b/src/tracefs-filter.c
@@ -746,6 +746,24 @@ int tracefs_filter_string_verify(struct tep_event *event, const char *filter,
 	return 0;
 }
 
+/**
+ * tracefs_event_filter_apply - apply given filter on event in given instance
+ * @instance: The instance in which the filter will be applied (NULL for toplevel).
+ * @event: The event to apply the filter on.
+ * @filter: The filter to apply.
+ *
+ * Apply the @filter to given @event in givem @instance. The @filter string
+ * should be created with tracefs_filter_string_append().
+ *
+ * Returns 0 on succes and -1 on error.
+ */
+int tracefs_event_filter_apply(struct tracefs_instance *instance,
+			       struct tep_event *event, const char *filter)
+{
+	return tracefs_event_file_write(instance, event->system, event->name,
+					"filter", filter);
+}
+
 /** Deprecated **/
 int tracefs_event_append_filter(struct tep_event *event, char **filter,
 				enum tracefs_filter type,
-- 
2.33.1


      parent reply	other threads:[~2021-12-02 10:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-02 10:59 [PATCH v2 0/4] New tracefs APIs Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` [PATCH v2 1/4] libtracefs: Reuse logic for loading events inside the library Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` [PATCH v2 2/4] libtracefs: New API for getting dynamic event Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` [PATCH v2 3/4] libtracefs: Unit test for tracefs_dynevent_get_event() Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` Tzvetomir Stoyanov (VMware) [this message]

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=20211202105926.32581-5-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@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.