Skip to contentSkip to conversation

[PATCH v2 0/2]

PATCH In review Steven Rostedt 1 participant 4 messages May 5, 2021 Documentation

lore
Share & tools
lore
#0 lore raw

v2 cover [PATCH v2 0/2]

From: "Steven Rostedt (VMware)" <[email protected]>

When writing code with libtracefs, I found that it would be very convenient to have an easy way to enable and disable events.

This patch set adds:

tracefs_event_enable()
tracefs_event_disable()

to allow users to easily enable and disable events in their code.

Changes since v1:

- free the regex of system and event if they are created.

Steven Rostedt (VMware) (2):
libtracefs: Add tracefs_event_enable/disable() API
libtracefs: Update the man page for tracefs_event_enable/disable()
APIs

 Documentation/libtracefs-events.txt |  36 +++++++
 include/tracefs.h                   |   3 +
 src/tracefs-events.c                | 149 ++++++++++++++++++++++++++++
 3 files changed, 188 insertions(+)
Signature · 1 line
2.29.2
#1 lore raw

PATCH v2 1/2 libtracefs: Add tracefs_event_enable/disable() API

From: "Steven Rostedt (VMware)" <[email protected]>

Add the API of the following functions:

tracefs_event_enable()
tracefs_event_disable()

That takes a system string and an event string and enables the events that match. Where a NULL system means (all systems) and a NULL event means all events in the system.

---
Changes since v1:

- free the regex of system and event if they are created.

 include/tracefs.h    |   3 +
 src/tracefs-events.c | 149 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+)
include/tracefs.h +3 -0
index 551c37c..73ee42b 100644
@@ -55,6 +55,9 @@ int tracefs_trace_off(struct tracefs_instance *instance);
 int tracefs_trace_on_fd(int fd);
 int tracefs_trace_off_fd(int fd);
 
+int tracefs_event_enable(struct tracefs_instance *instance, const char *system, const char *event);
+int tracefs_event_disable(struct tracefs_instance *instance, const char *system, const char *event);
+
 /**
  * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance
  * @instance: ftrace instance, can be NULL for the top instance
src/tracefs-events.c +149 -0

152 lines not on this page · raw message

Signature · 1 line
2.29.2
#2 lore raw

PATCH v2 2/2 libtracefs: Update the man page for tracefs_event_enable/disable() APIs

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Include descriptions for

tracefs_event_enable()
tracefs_event_disable()

in the tracefs events man page.

---
 Documentation/libtracefs-events.txt | 36 +++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
Documentation/libtracefs-events.txt +36 -0
index 78c9834..3fe9199 100644
@@ -14,6 +14,8 @@ SYNOPSIS
 
 char pass:[*]pass:[*]*tracefs_event_systems*(const char pass:[*]_tracing_dir_);
 char pass:[*]pass:[*]*tracefs_system_events*(const char pass:[*]_tracing_dir_, const char pass:[*]_system_);
+int *tracefs_event_enable*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_system_, const char pass:[*]_event_);
+int *tracefs_event_disable*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_system_, const char pass:[*]_event_);
 int *tracefs_iterate_raw_events*(struct tep_handle pass:[*]_tep_, struct tracefs_instance pass:[*]_instance_, cpu_set_t pass:[*]_cpus_, int _cpu_size_, int (pass:[*]_callback_)(struct tep_event pass:[*], struct tep_record pass:[*], int, void pass:[*]), void pass:[*]_callback_context_);
 
 --
@@ -37,6 +39,22 @@ local machine, or it may be a path to a copy of the tracefs directory
 from another machine. The last entry in the array as a NULL pointer.
 The array must be freed with _tracefs_list_free()_ API.
 
+The _tracefs_event_enable()_ function enables a given event based on
+the _system_ and _event_ passed in for the given _instance_. If _instance_
+is NULL, then the top level tracing directory is used. If _system_
+and _event_ are both NULL, then all events are enabled for the  _instance_.
+If _event_ is NULL then all events within the _system_ are enabled.
+If _system_ is NULL, then all systems are searched and any event within
+a system that matches _event_ is enabled. Both _system_ and _event_ may
+be regular expressions as defined by *regex*(3).
+
+The _tracefs_event_disable()_ function disables the events that match
+the _system_ and _event_ parameters for the given _instance_. What events
+are disable follow the same rules as _tracefs_event_enable()_ for matching
+events. That is, if _instance_ is NULL, then the top level tracing directory
+is used. If both _system_ and _event_ are NULL then all events are disabled
+for the given _instance_, and so on.
+
 The _tracefs_iterate_raw_events()_ function will read the tracefs raw
 data buffers and call the specified _callback_ function for every event it
 encounters. Events are iterated in sorted order: oldest first. An initialized
@@ -59,6 +77,14 @@ The _tracefs_event_systems()_ and __tracefs_system_events()_ functions return
 an array of strings. The last element in that array is a NULL pointer. The array
 must be freed with _tracefs_list_free()_ API. In case of an error, NULL is returned.
 
+Both _tracefs_event_enable()_ and _tracefs_event_disable()_ return 0 if they found
+any matching events (Note it does not check the previous status of the event. If
+_tracefs_event_enable()_ finds an event that is already enabled, and there are no
+other errors, then it will return 0). If an error occurs, even if other events were
+found, it will return -1 and errno will be set. If no errors occur, but no events
+are found that match the _system_ and _event_ parameters, then -1 is returned
+and errno is not set.
+
 The _tracefs_iterate_raw_events()_ function returns -1 in case of an error or
 0 otherwise.
 
@@ -102,9 +128,19 @@ struct tep_event *tep = tracefs_local_events(NULL);
 		/* Failed to initialise tep handler with local events */
 		...
 	}
+
+	errno = 0;
+	ret = tracefs_event_enable(NULL, "sched", NULL);
+	if (ret < 0 && !errno)
+		printf("Could not find 'sched' events\n");
+	tracefs_event_enable(NULL, "irq", "irq_handler_\(enter\|exit\)");
+
 	if (tracefs_iterate_raw_events(tep, NULL, NULL, 0, records_walk, NULL) < 0) {
 		/* Error walking through the recorded raw events */
 	}
+
+	/* Disable all events */
+	tracefs_event_disable(NULL, NULL, NULL);
 	tep_free(tep);
 --
 FILES
Signature · 1 line
2.29.2