libtracefs: Add API for enabling and disabling events
cover libtracefs: Add API for enabling and disabling events
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.
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 | 145 ++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+)
Signature · 1 line
2.29.2
PATCH 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.
--- include/tracefs.h | 3 + src/tracefs-events.c | 145 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+)
include/tracefs.h +3 -0
@@ -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 +145 -0
148 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH 1/2] libtracefs: Add tracefs_event_enable/disable() API
Quoted 51 lines · On Wed, 5 May 2021 09:42:47 -0400 Steven Rostedt <[email protected]> wrote:
src/tracefs-events.c +51
-0+static int event_enable_disable (struct tracefs_instance *instance, +const char *system,const char *event, +bool enable) +{ +regex_t system_re, event_re; +char **systems; +char **events =NULL ; +int ret =-1 ; +int s, e; + +/* Handle all events first */ +if (!system && !event) +return enable_disable_all (instance, enable); + + systems =tracefs_event_systems (NULL ); +if (!systems) + goto out_free; + +if (system) { + ret =regcomp (&system_re, system,REG_ICASE |REG_NOSUB ); +if (ret <0 ) + goto out_free; + } +if (event) { + ret =regcomp (&event_re, event,REG_ICASE |REG_NOSUB ); +if (ret <0 ) { +if (system) +regfree (&system_re); + goto out_free; + } + } + +for (s =0 ; systems[s]; s++) { +if (system && !match (systems[s], &system_re)) +continue ; + +/* Check for the short cut first */ +if (!event) { + ret =enable_disable_system (instance, systems[s], enable); +if (ret <0 ) +break ; + ret =0 ; +continue ; + } + + events =tracefs_system_events (NULL , systems[s]); +if (!events) +continue ;/* Error? */ + +for (e =0 ; events[e]; e++) { +if (!match (events[e], &event_re))
src/tracefs-events.c int tracefs_fill_local_events(const char *tracing_dir, · line 889
Quoted 10 lines
src/tracefs-events.c +10
-0+continue ; + ret =enable_disable_event (instance, systems[s], + events[e], enable); +if (ret <0 ) +break ; + ret =0 ; + } +tracefs_list_free (events); + events =NULL ; + }
Bah, I need to free both the system and event regex here.
Will send v2.
-- Steve
Quoted 6 lines
src/tracefs-events.c +6
-0+ + out_free: +tracefs_list_free (systems); +tracefs_list_free (events); +return ret; +}
PATCH 2/2 libtracefs: Update the man page for tracefs_event_enable/disable() APIs
In reply to Steven RostedtFrom: "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
@@ -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