diff options
author | Daniel Bristot de Oliveira <bristot@kernel.org> | 2022-03-02 22:01:32 +0300 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-03-15 21:36:49 +0300 |
commit | 336c92b26cf9aee6c5d5907ef49b90d2665e9d70 (patch) | |
tree | 7868cd59827e5969688b18ac59f8b6738a33415c /tools/tracing | |
parent | 51d64c3a181938da8fb56404524e15776e9c6bf8 (diff) | |
download | linux-336c92b26cf9aee6c5d5907ef49b90d2665e9d70.tar.xz |
rtla/trace: Add trace event trigger helpers
Add a set of helper functions to allow rtla tools to trigger event
actions in the trace instance.
Link: https://lkml.kernel.org/r/e0d31abe879a78a5600b64f904d0dfa8f76e4fbb.1646247211.git.bristot@kernel.org
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Clark Williams <williams@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Diffstat (limited to 'tools/tracing')
-rw-r--r-- | tools/tracing/rtla/src/trace.c | 88 | ||||
-rw-r--r-- | tools/tracing/rtla/src/trace.h | 4 |
2 files changed, 91 insertions, 1 deletions
diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 9ad3d8890ec5..7f8661b2724d 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -204,6 +204,8 @@ static void trace_events_free(struct trace_events *events) tevent = tevent->next; + if (free_event->trigger) + free(free_event->trigger); free(free_event->system); free(free_event); } @@ -236,6 +238,48 @@ struct trace_events *trace_event_alloc(const char *event_string) } /* + * trace_event_add_trigger - record an event trigger action + */ +int trace_event_add_trigger(struct trace_events *event, char *trigger) +{ + if (event->trigger) + free(event->trigger); + + event->trigger = strdup(trigger); + if (!event->trigger) + return 1; + + return 0; +} + +/* + * trace_event_disable_trigger - disable an event trigger + */ +static void trace_event_disable_trigger(struct trace_instance *instance, + struct trace_events *tevent) +{ + char trigger[1024]; + int retval; + + if (!tevent->trigger) + return; + + if (!tevent->trigger_enabled) + return; + + debug_msg("Disabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + + snprintf(trigger, 1024, "!%s\n", tevent->trigger); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "trigger", trigger); + if (retval < 0) + err_msg("Error disabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); +} + +/* * trace_events_disable - disable all trace events */ void trace_events_disable(struct trace_instance *instance, @@ -248,8 +292,10 @@ void trace_events_disable(struct trace_instance *instance, while (tevent) { debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); - if (tevent->enabled) + if (tevent->enabled) { + trace_event_disable_trigger(instance, tevent); tracefs_event_disable(instance->inst, tevent->system, tevent->event); + } tevent->enabled = 0; tevent = tevent->next; @@ -257,6 +303,42 @@ void trace_events_disable(struct trace_instance *instance, } /* + * trace_event_enable_trigger - enable an event trigger associated with an event + */ +static int trace_event_enable_trigger(struct trace_instance *instance, + struct trace_events *tevent) +{ + char trigger[1024]; + int retval; + + if (!tevent->trigger) + return 0; + + if (!tevent->event) { + err_msg("Trigger %s applies only for single events, not for all %s:* events\n", + tevent->trigger, tevent->system); + return 1; + } + + snprintf(trigger, 1024, "%s\n", tevent->trigger); + + debug_msg("Enabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "trigger", trigger); + if (retval < 0) { + err_msg("Error enabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + return 1; + } + + tevent->trigger_enabled = 1; + + return 0; +} + +/* * trace_events_enable - enable all events */ int trace_events_enable(struct trace_instance *instance, @@ -275,6 +357,10 @@ int trace_events_enable(struct trace_instance *instance, } + retval = trace_event_enable_trigger(instance, tevent); + if (retval) + return 1; + tevent->enabled = 1; tevent = tevent->next; } diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 9f9751f7ee36..856b26d93064 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -6,7 +6,9 @@ struct trace_events { struct trace_events *next; char *system; char *event; + char *trigger; char enabled; + char trigger_enabled; }; struct trace_instance { @@ -40,3 +42,5 @@ void trace_events_destroy(struct trace_instance *instance, struct trace_events *events); int trace_events_enable(struct trace_instance *instance, struct trace_events *events); + +int trace_event_add_trigger(struct trace_events *event, char *trigger); |