From: Daniel Bristot de Oliveira <bristot@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
linux-trace-devel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] rtla/trace: Add trace events helpers
Date: Fri, 18 Feb 2022 12:09:17 +0100 [thread overview]
Message-ID: <fc83e3162dd01df0b1635099fbf1f5b08b069834.1645182327.git.bristot@kernel.org> (raw)
In-Reply-To: <cover.1645182327.git.bristot@kernel.org>
Add a set of helper functions to allow the rtla tools to enable
additional tracepoints in the trace instance.
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-trace-devel@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
---
tools/tracing/rtla/src/trace.c | 105 +++++++++++++++++++++++++++++++++
tools/tracing/rtla/src/trace.h | 15 +++++
2 files changed, 120 insertions(+)
diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c
index 83de259abcc1..1a3e346c6b17 100644
--- a/tools/tracing/rtla/src/trace.c
+++ b/tools/tracing/rtla/src/trace.c
@@ -190,3 +190,108 @@ int trace_instance_start(struct trace_instance *trace)
{
return tracefs_trace_on(trace->inst);
}
+
+/*
+ * free_trace_events - free a list of trace events
+ */
+static void free_trace_events(struct trace_events *events)
+{
+ struct trace_events *tevent = events;
+ struct trace_events *free_event;
+
+ while (tevent) {
+ free_event = tevent;
+
+ tevent = tevent->next;
+
+ free(free_event->system);
+ free(free_event);
+ }
+}
+
+/*
+ * alloc_trace_event - alloc and parse a single trace event
+ */
+struct trace_events *alloc_trace_event(const char *event_string)
+{
+ struct trace_events *tevent;
+
+ tevent = calloc(1, sizeof(*tevent));
+ if (!tevent)
+ return NULL;
+
+ tevent->system = strdup(event_string);
+ if (!tevent->system) {
+ free(tevent);
+ return NULL;
+ }
+
+ tevent->event = strstr(tevent->system, ":");
+ if (tevent->event) {
+ *tevent->event = '\0';
+ tevent->event = &tevent->event[1];
+ }
+
+ return tevent;
+}
+
+/*
+ * disable_trace_events - disable all trace events
+ */
+void disable_trace_events(struct trace_instance *instance,
+ struct trace_events *events)
+{
+ struct trace_events *tevent = events;
+
+ if (!events)
+ return;
+
+ while (tevent) {
+ if (tevent->enabled)
+ tracefs_event_disable(instance->inst, tevent->system, tevent->event);
+
+ tevent->enabled = 0;
+ tevent = tevent->next;
+ }
+}
+
+/*
+ * enable_trace_events - enable all events
+ */
+int enable_trace_events(struct trace_instance *instance,
+ struct trace_events *events)
+{
+ struct trace_events *tevent = events;
+ int retval;
+
+ while (tevent) {
+ retval = tracefs_event_enable(instance->inst, tevent->system, tevent->event);
+ if (retval < 0) {
+ if (tevent->event)
+ err_msg("Error enabling event %s:%s\n",
+ tevent->system, tevent->event);
+ else
+ err_msg("Error enabling events %s:*\n",
+ tevent->system);
+ return 1;
+ }
+
+ tevent->enabled = 1;
+ tevent = tevent->next;
+ }
+
+ return 0;
+}
+
+/*
+ * destroy_trace_events - disable and free all trace events
+ */
+void destroy_trace_events(struct trace_instance *instance,
+ struct trace_events *events)
+{
+ if (!events)
+ return;
+
+ disable_trace_events(instance, events);
+ free_trace_events(events);
+}
diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h
index 0ea1df0ad9a7..762a04667c51 100644
--- a/tools/tracing/rtla/src/trace.h
+++ b/tools/tracing/rtla/src/trace.h
@@ -2,6 +2,13 @@
#include <tracefs.h>
#include <stddef.h>
+struct trace_events {
+ struct trace_events *next;
+ char *system;
+ char *event;
+ int enabled;
+};
+
struct trace_instance {
struct tracefs_instance *inst;
struct tep_handle *tep;
@@ -25,3 +32,11 @@ void destroy_instance(struct tracefs_instance *inst);
int save_trace_to_file(struct tracefs_instance *inst, const char *filename);
int collect_registered_events(struct tep_event *tep, struct tep_record *record,
int cpu, void *context);
+
+struct trace_events *alloc_trace_event(const char *event_string);
+void disable_trace_events(struct trace_instance *instance,
+ struct trace_events *events);
+void destroy_trace_events(struct trace_instance *instance,
+ struct trace_events *events);
+int enable_trace_events(struct trace_instance *instance,
+ struct trace_events *events);
--
2.34.1
next prev parent reply other threads:[~2022-02-18 11:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-18 11:09 [PATCH 0/7] Some rtla features Daniel Bristot de Oliveira
2022-02-18 11:09 ` [PATCH 1/7] rtla/osnoise: Add support to adjust the tracing_thresh Daniel Bristot de Oliveira
2022-02-18 11:09 ` [PATCH 2/7] rtla/osnoise: Add an option to set the threshold Daniel Bristot de Oliveira
2022-02-18 11:09 ` [PATCH 3/7] rtla/osnoise: Add the automatic trace option Daniel Bristot de Oliveira
2022-02-18 11:09 ` [PATCH 4/7] rtla/timerlat: " Daniel Bristot de Oliveira
2022-02-18 11:09 ` Daniel Bristot de Oliveira [this message]
2022-02-18 11:09 ` [PATCH 6/7] rtla/osnoise: Add -e/--event option Daniel Bristot de Oliveira
2022-02-18 11:09 ` [PATCH 7/7] rtla/timerlat: " Daniel Bristot de Oliveira
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=fc83e3162dd01df0b1635099fbf1f5b08b069834.1645182327.git.bristot@kernel.org \
--to=bristot@kernel.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).