Skip to contentSkip to conversation

New tracefs APIs

PATCH Superseded Tzvetomir Stoyanov (VMware) 2 participants 8 messages Nov 30, 2021 – Dec 2, 2021 Documentation

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover New tracefs APIs

Two new library APIs are proposed, to provide a missing functionality:
tracefs_dynevent_get_event()
tracefs_event_apply_filter()

Tzvetomir Stoyanov (VMware) (4):
libtracefs: Reuse logic for loading events inside the library
libtracefs: New API for getting dynamic event
libtracefs: Unit test for tracefs_dynevent_get_event()
libtracefs: New API for applying filter on event.

 Documentation/libtracefs-dynevents.txt | 15 ++++++-
 Documentation/libtracefs-filter.txt    | 11 ++++-
 include/tracefs-local.h                |  3 ++
 include/tracefs.h                      |  5 +++
 src/tracefs-dynevents.c                | 29 +++++++++++++
 src/tracefs-events.c                   | 11 +++--
 src/tracefs-filter.c                   | 19 +++++++++
 utest/tracefs-utest.c                  | 58 +++++++++++++++++---------
 8 files changed, 125 insertions(+), 26 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/4 libtracefs: Reuse logic for loading events inside the library

The logic for parsing and loading new tep events could be reused in tracefs library. The function load_events() is exposed as internal API.

---
 include/tracefs-local.h |  3 +++
 src/tracefs-events.c    | 11 +++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)
include/tracefs-local.h +3 -0
index a59e806..0540956 100644
@@ -112,4 +112,7 @@ dynevent_alloc(enum tracefs_dynevent_type type, const char *system,
 	       const char *event, const char *address, const char *format);
 int dynevent_get_count(unsigned int types, const char *system);
 
+int trace_load_events(struct tep_handle *tep,
+		      const char *tracing_dir, const char *system);
+
 #endif /* _TRACE_FS_LOCAL_H */
src/tracefs-events.c +7 -4
index 4679926..e3962e5 100644
@@ -688,8 +688,8 @@ char **tracefs_tracers(const char *tracing_dir)
 	return plugins;
 }
 
-static int load_events(struct tep_handle *tep,
-		       const char *tracing_dir, const char *system)
+__hidden int trace_load_events(struct tep_handle *tep,
+			       const char *tracing_dir, const char *system)
 {
 	int ret = 0, failure = 0;
 	char **events = NULL;
@@ -697,6 +697,9 @@ static int load_events(struct tep_handle *tep,
 	int len = 0;
 	int i;
 
+	if (!tracing_dir)
+		tracing_dir = tracefs_tracing_dir();
+
 	events = tracefs_system_events(tracing_dir, system);
 	if (!events)
 		return -ENOENT;
@@ -886,14 +889,14 @@ static int fill_local_events_system(const char *tracing_dir,
 	for (i = 0; systems[i]; i++) {
 		if (sys_names && !contains(systems[i], sys_names))
 			continue;
-		ret = load_events(tep, tracing_dir, systems[i]);
+		ret = trace_load_events(tep, tracing_dir, systems[i]);
 		if (ret && parsing_failures)
 			(*parsing_failures)++;
 	}
 
 	/* Include ftrace, as it is excluded for not having "enable" file */
 	if (!sys_names || contains("ftrace", sys_names))
-		load_events(tep, tracing_dir, "ftrace");
+		trace_load_events(tep, tracing_dir, "ftrace");
 
 	load_mappings(tracing_dir, tep);
 
Signature · 1 line
2.33.1
#2 lore raw

PATCH 2/4 libtracefs: New API for getting dynamic event

In reply to Tzvetomir Stoyanov (VMware)

A new API is proposed, to get tep event describing given dynamic event:
tracefs_dynevent_get_event()
The API detects any newly created dynamic events, but does not detect the deletion.

---
 Documentation/libtracefs-dynevents.txt | 14 +++++++++++--
 include/tracefs.h                      |  2 ++
 src/tracefs-dynevents.c                | 29 ++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
Documentation/libtracefs-dynevents.txt +12 -2
index a374651..7de06be 100644
@@ -4,8 +4,8 @@ libtracefs(3)
 NAME
 ----
 tracefs_dynevent_create, tracefs_dynevent_destroy, tracefs_dynevent_destroy_all,
-tracefs_dynevent_free, tracefs_dynevent_list_free, tracefs_dynevent_get_all, tracefs_dynevent_info -
-Create, destroy, free and get dynamic events.
+tracefs_dynevent_free, tracefs_dynevent_list_free, tracefs_dynevent_get_all, tracefs_dynevent_info,
+tracefs_dynevent_get_event - Create, destroy, free and get dynamic events.
 
 SYNOPSIS
 --------
@@ -23,6 +23,7 @@ void *tracefs_dynevent_list_free*(struct tracefs_dynevent pass:[*]pass:[*]_event
 struct tracefs_dynevent pass:[*]*tracefs_dynevent_get*(enum tracefs_dynevent_type _type_, const char pass:[*]_system_, const char pass:[*]_event_);
 struct tracefs_dynevent pass:[*]pass:[*]*tracefs_dynevent_get_all*(unsigned int _types_, const char pass:[*]_system_);
 enum tracefs_dynevent_type *tracefs_dynevent_info*(struct tracefs_dynevent pass:[*]_dynevent_, char pass:[*]pass:[*]_system_, char pass:[*]pass:[*]_event_, char pass:[*]pass:[*]_prefix_, char pass:[*]pass:[*]_addr_, char pass:[*]pass:[*]_format_);
+struct tep_event pass:[*]*tracefs_dynevent_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_dynevent pass:[*]_dynevent_);
 --
 
 DESCRIPTION
@@ -68,6 +69,11 @@ if relevant for this event type. If _format_ is non NULL, it will hold the forma
 dynamic event. Note, that the content in _group_, _event_, _prefix_, _addr_, and _format_ must be
 freed with free(3) if they are set.
 
+The *tracefs_dynevent_get_event*() function returns tep event, describing the given dynamic event.
+If the dynamic event is newly created and not yet loaded in the @tep, the dynamic event system is
+rescanned for any new events. The returned pointer to tep event is controlled by @tep and must not
+be freed.
+
 RETURN VALUE
 ------------
 
@@ -88,6 +94,10 @@ in case of an error or in case there are no events in the system. That array mus
 on error. If _system_, _event_, _prefix_, _addr_, or _format_ are non NULL, they will contain
 allocated strings that must be freed by free(3).
 
+The *tracefs_dynevent_get_event*() function returns pointer to tep event or NULL in case of an error
+or if the requested dynamic event is missing. The returned pointer to tep event is controlled by
+@tep and must not be freed.
+
 ERRORS
 ------
 The following errors are for all the above calls:
include/tracefs.h +2 -0
index 9662603..fbd7d31 100644
@@ -262,6 +262,8 @@ tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system, const
 enum tracefs_dynevent_type
 tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
 		      char **event, char **prefix, char **addr, char **format);
+struct tep_event *
+tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent);
 
 struct tracefs_dynevent *
 tracefs_eprobe_alloc(const char *system, const char *event,
src/tracefs-dynevents.c +29 -0
index ea07d13..2ff3c87 100644
@@ -752,3 +752,32 @@ error:
 
 	return TRACEFS_DYNEVENT_UNKNOWN;
 }
+
+/**
+ * tracefs_dynevent_get_event - return tep event, representing the given dynamic event
+ * @tep: a handle to the trace event parser context, that holds the events
+ * @dynevent: a dynamic event context, describing given dynamic event.
+ *
+ * Returns pointer to tep event, describing the given dynamic event. The pointer
+ * is managed by @tep handle and must not be freed. In case of an error, or in case
+ * the requested dynamic event is missing in the @tep handler - NULL is returned.
+ */
+struct tep_event *
+tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent)
+{
+	struct tep_event *event;
+
+	if (!tep || !dynevent || !dynevent->event)
+		return NULL;
+
+	/* If the dynamic event is already loaded in the tep, return it */
+	event = tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+	if (event)
+		return event;
+
+	/* Try to load any new events from the given system */
+	if (trace_load_events(tep, NULL, dynevent->system))
+		return NULL;
+
+	return tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+}
Signature · 1 line
2.33.1
#3 lore raw

Re: [PATCH 2/4] libtracefs: New API for getting dynamic event

Quoted 1 line · On Tue, 30 Nov 2021 07:00:55 +0200 "Tzvetomir Stoyanov (VMware)"…

A new API is proposed, to get tep event describing given dynamic event:

[blank line]

Quoted 1 line

tracefs_dynevent_get_event()

[blank line]

Quoted 34 lines

The API detects any newly created dynamic events, but does not detect the deletion.

---
 Documentation/libtracefs-dynevents.txt | 14 +++++++++++--
 include/tracefs.h                      |  2 ++
 src/tracefs-dynevents.c                | 29 ++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
Documentation/libtracefs-dynevents.txt +3 -2
index a374651..7de06be 100644
@@ -4,8 +4,8 @@ libtracefs(3)
 NAME
 ----
 tracefs_dynevent_create, tracefs_dynevent_destroy, tracefs_dynevent_destroy_all,
-tracefs_dynevent_free, tracefs_dynevent_list_free, tracefs_dynevent_get_all, tracefs_dynevent_info -
-Create, destroy, free and get dynamic events.
+tracefs_dynevent_free, tracefs_dynevent_list_free, tracefs_dynevent_get_all, tracefs_dynevent_info,
+tracefs_dynevent_get_event - Create, destroy, free and get dynamic events.
 
 SYNOPSIS
 --------
@@ -23,6 +23,7 @@ void *tracefs_dynevent_list_free*(struct tracefs_dynevent pass:[*]pass:[*]_event
 struct tracefs_dynevent pass:[*]*tracefs_dynevent_get*(enum tracefs_dynevent_type _type_, const char pass:[*]_system_, const char pass:[*]_event_);
 struct tracefs_dynevent pass:[*]pass:[*]*tracefs_dynevent_get_all*(unsigned int _types_, const char pass:[*]_system_);
 enum tracefs_dynevent_type *tracefs_dynevent_info*(struct tracefs_dynevent pass:[*]_dynevent_, char pass:[*]pass:[*]_system_, char pass:[*]pass:[*]_event_, char pass:[*]pass:[*]_prefix_, char pass:[*]pass:[*]_addr_, char pass:[*]pass:[*]_format_);
+struct tep_event pass:[*]*tracefs_dynevent_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_dynevent pass:[*]_dynevent_);
 --
 
 DESCRIPTION

Documentation/libtracefs-dynevents.txt if relevant for this event type. If _format_ is non NULL, it will hold the forma · line 72

Quoted 4 lines
Documentation/libtracefs-dynevents.txt +1 -0
@@ -68,6 +69,11 @@ if relevant for this event type. If _format_ is non NULL, it will hold the forma
 dynamic event. Note, that the content in _group_, _event_, _prefix_, _addr_, and _format_ must be
 freed with free(3) if they are set.
 
+The *tracefs_dynevent_get_event*() function returns tep event, describing the given dynamic event.

"returns a tep event"

Documentation/libtracefs-dynevents.txt if relevant for this event type. If _format_ is non NULL, it will hold the forma · line 73

Quoted 1 line
Documentation/libtracefs-dynevents.txt +1 -0
+If the dynamic event is newly created and not yet loaded in the @tep, the dynamic event system is

"loaded in @tep"

Documentation/libtracefs-dynevents.txt in case of an error or in case there are no events in the system. That array mus · line 97

Quoted 13 lines
Documentation/libtracefs-dynevents.txt +3 -0
+rescanned for any new events. The returned pointer to tep event is controlled by @tep and must not
+be freed.
 
 
+
 RETURN VALUE

------------

Documentation/libtracefs-dynevents.txt +1 -0
@@ -88,6 +94,10 @@ in case of an error or in case there are no events in the system. That array mus
 on error. If _system_, _event_, _prefix_, _addr_, or _format_ are non NULL, they will contain
 allocated strings that must be freed by free(3).
 
+The *tracefs_dynevent_get_event*() function returns pointer to tep event or NULL in case of an error

"returns a pointer to a tep event'

Quoted 24 lines
Documentation/libtracefs-dynevents.txt +3 -0
+or if the requested dynamic event is missing. The returned pointer to tep event is controlled by
+@tep and must not be freed.
+
 ERRORS
 ------
 The following errors are for all the above calls:
include/tracefs.h +2 -0
index 9662603..fbd7d31 100644
@@ -262,6 +262,8 @@ tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system, const
 enum tracefs_dynevent_type
 tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
 		      char **event, char **prefix, char **addr, char **format);
+struct tep_event *
+tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent);
 
 struct tracefs_dynevent *
 tracefs_eprobe_alloc(const char *system, const char *event,
src/tracefs-dynevents.c +0 -0
index ea07d13..2ff3c87 100644

src/tracefs-dynevents.c error: · line 757

Quoted 6 lines
src/tracefs-dynevents.c +3 -0
@@ -752,3 +752,32 @@ error:
 
 	return TRACEFS_DYNEVENT_UNKNOWN;
 }
+
+/**
+ * tracefs_dynevent_get_event - return tep event, representing the given dynamic event

remove the comma.

src/tracefs-dynevents.c error: · line 758

Quoted 1 line
src/tracefs-dynevents.c +1 -0
+ * @tep: a handle to the trace event parser context, that holds the events

remove the comma.

src/tracefs-dynevents.c error: · line 759

Quoted 1 line
src/tracefs-dynevents.c +1 -0
+ * @dynevent: a dynamic event context, describing given dynamic event.

remove the comma ;-)

src/tracefs-dynevents.c error: · line 761

Quoted 2 lines
src/tracefs-dynevents.c +2 -0
+ *
+ * Returns pointer to tep event, describing the given dynamic event. The pointer

"Returns a pointer to a tep event describing the given dynamic event".

src/tracefs-dynevents.c error: · line 762

Quoted 1 line
src/tracefs-dynevents.c +1 -0
+ * is managed by @tep handle and must not be freed. In case of an error, or in case

"by the @tep handle"

Quoted 7 lines
src/tracefs-dynevents.c +7 -0
+ * the requested dynamic event is missing in the @tep handler - NULL is returned.
+ */
+struct tep_event *
+tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent)
+{
+	struct tep_event *event;
+

src/tracefs-dynevents.c error: · line 779

Quoted 10 lines
src/tracefs-dynevents.c +10 -0
+	if (!tep || !dynevent || !dynevent->event)
+		return NULL;
+
+	/* If the dynamic event is already loaded in the tep, return it */
+	event = tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+	if (event)
+		return event;
+
+	/* Try to load any new events from the given system */
+	if (trace_load_events(tep, NULL, dynevent->system))

Does this refresh, or does just append?

That is, if there are already dynamic events, wouldn't this re-add the existing events that are already there?

Perhaps we need an interface in libtraceevent that rescans, and checks for duplicates.

-- Steve

Quoted 4 lines
src/tracefs-dynevents.c +4 -0
+		return NULL;
+
+	return tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+}
#4 lore raw

Re: [PATCH 2/4] libtracefs: New API for getting dynamic event

Quoted 1 line · Steven Rostedt

[ ... ]

Quoted 12 lines
Quoted 12 lines

+ * the requested dynamic event is missing in the @tep handler - NULL is returned.
+ */

src/tracefs-dynevents.c +9 -0
+struct tep_event *
+tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent)
+{
+     struct tep_event *event;
+
+     if (!tep || !dynevent || !dynevent->event)
+             return NULL;
+
+     /* If the dynamic event is already loaded in the tep, return it */
Quoted 9 lines

src/tracefs-dynevents.c error: · line 779

Quoted 6 lines
src/tracefs-dynevents.c +6 -0
+     event = tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+     if (event)
+             return event;
+
+     /* Try to load any new events from the given system */
+     if (trace_load_events(tep, NULL, dynevent->system))

Does this refresh, or does just append?

This calls tep_parse_event() for all events in the given system, so it only appends.

Quoted 2 lines

That is, if there are already dynamic events, wouldn't this re-add the existing events that are already there?

I just realized that there is a bug, there will be duplicates.

Quoted 3 lines

Perhaps we need an interface in libtraceevent that rescans, and checks for duplicates.

Yes, that logic should be in libtraceevent, there should be new API.

Quoted 10 lines

-- Steve

Quoted 4 lines
src/tracefs-dynevents.c +4 -0
+             return NULL;
+
+     return tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+}
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
#5 lore raw

PATCH 3/4 libtracefs: Unit test for tracefs_dynevent_get_event()

In reply to Tzvetomir Stoyanov (VMware)

Unit tests for dynamic events are extended to test the newly introduced tracefs_dynevent_get_event() API.

---
 Documentation/libtracefs-dynevents.txt |  5 ++-
 utest/tracefs-utest.c                  | 58 +++++++++++++++++---------
 2 files changed, 42 insertions(+), 21 deletions(-)
Documentation/libtracefs-dynevents.txt +3 -2
index 7de06be..bd18f5b 100644
@@ -71,8 +71,9 @@ freed with free(3) if they are set.
 
 The *tracefs_dynevent_get_event*() function returns tep event, describing the given dynamic event.
 If the dynamic event is newly created and not yet loaded in the @tep, the dynamic event system is
-rescanned for any new events. The returned pointer to tep event is controlled by @tep and must not
-be freed.
+rescanned for any new events. If the dynamic event is deleted from the system, any subsequent calls
+to *tracefs_dynevent_get_event*() may return a tep event, as the deletion is not detected by the API.
+The returned pointer to tep event is controlled by @tep and must not be freed.
 
 RETURN VALUE
 ------------
utest/tracefs-utest.c +39 -19

179 lines not on this page · raw message

Signature · 1 line
2.33.1
#6 lore raw

PATCH 4/4 libtracefs: New API for applying filter on event.

In reply to Tzvetomir Stoyanov (VMware)

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_apply_filter()

---
 Documentation/libtracefs-filter.txt | 11 ++++++++++-
 include/tracefs.h                   |  3 +++
 src/tracefs-filter.c                | 19 +++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
Documentation/libtracefs-filter.txt +10 -1
index 7e167bc..7532c96 100644
@@ -3,7 +3,8 @@ libtracefs(3)
 
 NAME
 ----
-tracefs_event_append_filter, tracefs_event_verify_filter - Add and verify event filters
+tracefs_event_append_filter, tracefs_event_verify_filter tracefs_event_apply_filter -
+Add, verify and apply event filters
 
 SYNOPSIS
 --------
@@ -15,6 +16,7 @@ int tracefs_event_append_filter(struct tep_event pass:[*]event, char pass:[**] f
 				 struct tracefs_filter type, const char pass:[*]field,
 				 enum tracefs_synth_compare compare, const char pass:[*]val);
 int tracefs_event_verify_filter(struct tep_event pass:[*]event, const char pass:[*]filter, char pass:[**]err);
+int tracefs_event_apply_filter(struct tracefs_instance pass:[*]instance, struct tep_event pass:[*]event, const char pass:[*]filter);
 
 --
 
@@ -66,6 +68,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_apply_filter*() applies given _filter_ string on _event_ in given _instance_.
+
 RETURN VALUE
 ------------
 *tracefs_event_append_filter*() returns 0 on success and -1 on error.
@@ -75,6 +79,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_apply_filter*() returns 0 on success and -1 on error.
+
 EXAMPLE
 -------
 [source,c]
@@ -269,6 +275,9 @@ int main (int argc, char **argv)
 		}
 	}
 
+	if (tracefs_event_apply_filter(NULL, event, new_filter))
+		fprintf(stderr, "Failed to apply filter on event");
+
 	tep_free(tep);
 
 	printf("Created new filter: '%s'\n", new_filter);
include/tracefs.h +3 -0
index fbd7d31..8ac9694 100644
@@ -475,6 +475,9 @@ int tracefs_event_append_filter(struct tep_event *event, char **filter,
 				const char *val);
 int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
 				char **err);
+int tracefs_event_apply_filter(struct tracefs_instance *instance,
+			       struct tep_event *event, const char *filter);
+
 
 #define TRACEFS_TIMESTAMP "common_timestamp"
 #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs"
src/tracefs-filter.c +19 -0
index def8f68..43683d0 100644
@@ -745,3 +745,22 @@ int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
 	free(str);
 	return 0;
 }
+
+/**
+ * tracefs_event_apply_filter - 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_event_append_filter().
+ *
+ * Returns 0 on succes and -1 on error.
+ */
+int tracefs_event_apply_filter(struct tracefs_instance *instance,
+			       struct tep_event *event, const char *filter)
+{
+	return tracefs_event_file_append(instance, event->system, event->name,
+					 "filter", filter);
+}
+
Signature · 1 line
2.33.1
#7 lore raw

Re: [PATCH 4/4] libtracefs: New API for applying filter on event.

Note, the subject should not have a period.

Quoted 1 line · On Tue, 30 Nov 2021 07:00:57 +0200 "Tzvetomir Stoyanov (VMware)"…

There is no API for applying a filter string on event. Existing APIs

"on an event."

Quoted 1 line

only constructs and verifies the filter string. Even though the actual

"only construct and verify"

Quoted 2 lines

applying is just writing into the event's filter file, it is good to have a dedicated API for that:

[ add empty line here ]

Quoted 14 lines

tracefs_event_apply_filter()

---
 Documentation/libtracefs-filter.txt | 11 ++++++++++-
 include/tracefs.h                   |  3 +++
 src/tracefs-filter.c                | 19 +++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
Documentation/libtracefs-filter.txt +0 -0
index 7e167bc..7532c96 100644

Documentation/libtracefs-filter.txt libtracefs(3) · line 6

Quoted 5 lines
Documentation/libtracefs-filter.txt +1 -1
@@ -3,7 +3,8 @@ libtracefs(3)
 
 NAME
 ----
-tracefs_event_append_filter, tracefs_event_verify_filter - Add and verify event filters
+tracefs_event_append_filter, tracefs_event_verify_filter tracefs_event_apply_filter -

Missing comma (and you also need to rebase with the updates).

Documentation/libtracefs-filter.txt int tracefs_event_append_filter(struct tep_event pass:[*]event, char pass:[**] f · line 18

Quoted 8 lines
Documentation/libtracefs-filter.txt +1 -0
+Add, verify and apply event filters
 
 SYNOPSIS
 --------
@@ -15,6 +16,7 @@ int tracefs_event_append_filter(struct tep_event pass:[*]event, char pass:[**] f
 				 struct tracefs_filter type, const char pass:[*]field,
 				 enum tracefs_synth_compare compare, const char pass:[*]val);
 int tracefs_event_verify_filter(struct tep_event pass:[*]event, const char pass:[*]filter, char pass:[**]err);

I renamed the above, because it doesn't really affect the event.

Documentation/libtracefs-filter.txt int tracefs_event_append_filter(struct tep_event pass:[*]event, char pass:[**] f · line 19

Quoted 1 line
Documentation/libtracefs-filter.txt +1 -0
+int tracefs_event_apply_filter(struct tracefs_instance pass:[*]instance, struct tep_event pass:[*]event, const char pass:[*]filter);

But you can keep this name, as it makes sense to call this "tracefs_event_.."

Quoted 52 lines
Documentation/libtracefs-filter.txt +7 -0
 --
 
@@ -66,6 +68,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_apply_filter*() applies given _filter_ string on _event_ in given _instance_.
+
 RETURN VALUE
 ------------
 *tracefs_event_append_filter*() returns 0 on success and -1 on error.
@@ -75,6 +79,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_apply_filter*() returns 0 on success and -1 on error.
+
 EXAMPLE
 -------
 [source,c]
@@ -269,6 +275,9 @@ int main (int argc, char **argv)
 		}
 	}
 
+	if (tracefs_event_apply_filter(NULL, event, new_filter))
+		fprintf(stderr, "Failed to apply filter on event");
+
 	tep_free(tep);
 
 	printf("Created new filter: '%s'\n", new_filter);
include/tracefs.h +3 -0
index fbd7d31..8ac9694 100644
@@ -475,6 +475,9 @@ int tracefs_event_append_filter(struct tep_event *event, char **filter,
 				const char *val);
 int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
 				char **err);
+int tracefs_event_apply_filter(struct tracefs_instance *instance,
+			       struct tep_event *event, const char *filter);
+
 
 #define TRACEFS_TIMESTAMP "common_timestamp"
 #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs"
src/tracefs-filter.c +0 -0
index def8f68..43683d0 100644
@@ -745,3 +745,22 @@ int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
 	free(str);
 	return 0;

src/tracefs-filter.c int tracefs_event_verify_filter(struct tep_event *event, const char *filter, · line 756

Quoted 10 lines
src/tracefs-filter.c +9 -0
 }
+
+/**
+ * tracefs_event_apply_filter - 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_event_append_filter().

The name of the function has been renamed.

src/tracefs-filter.c int tracefs_event_verify_filter(struct tep_event *event, const char *filter, · line 764

Quoted 8 lines
src/tracefs-filter.c +8 -0
+ *
+ * Returns 0 on succes and -1 on error.
+ */
+int tracefs_event_apply_filter(struct tracefs_instance *instance,
+			       struct tep_event *event, const char *filter)
+{
+	return tracefs_event_file_append(instance, event->system, event->name,
+					 "filter", filter);

I think we want this to be tracefs_event_file_write(), as it should replace the filter, not add on to it.

src/tracefs-filter.c int tracefs_event_verify_filter(struct tep_event *event, const char *filter, · line 766

Quoted 2 lines
src/tracefs-filter.c +2 -0
+}
+

Note, I moved the old deprecated names at the end of the file. Make sure they stay at the end. In other words, this goes before them.

-- Steve