diff mbox series

[v7,13/15] libtracefs: Introduce eprobe API

Message ID 20211115104556.121359-14-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit c3479b608be43e47a93bc5f82c1569f859907ec2
Headers show
Series libtracefs dynamic events support | expand

Commit Message

Tzvetomir Stoyanov (VMware) Nov. 15, 2021, 10:45 a.m. UTC
Recently a new type of dynamic trace events was added in the Linux
kernel - event probes. Tracefs library should have APIs to work with
that event. As this is a dynamic event, all tracefs_dynevent_* APIs can
be used to control event probes. Only one new API is proposed:
 tracefs_eprobe_alloc()

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs.h     |  4 ++++
 src/Makefile          |  1 +
 src/tracefs-eprobes.c | 56 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 src/tracefs-eprobes.c
diff mbox series

Patch

diff --git a/include/tracefs.h b/include/tracefs.h
index 7b3f92b..4431ec7 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -261,6 +261,10 @@  enum tracefs_dynevent_type
 tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
 		      char **event, char **prefix, char **addr, char **format);
 
+struct tracefs_dynevent *
+tracefs_eprobe_alloc(const char *system, const char *event,
+		     const char *target_system, const char *target_event, const char *fetchargs);
+
 struct tracefs_dynevent *
 tracefs_kprobe_alloc(const char *system, const char *event, const char *addr, const char *format);
 struct tracefs_dynevent *
diff --git a/src/Makefile b/src/Makefile
index 99cd7da..cda0a0c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,6 +12,7 @@  OBJS += tracefs-kprobes.o
 OBJS += tracefs-hist.o
 OBJS += tracefs-filter.o
 OBJS += tracefs-dynevents.o
+OBJS += tracefs-eprobes.o
 
 # Order matters for the the three below
 OBJS += sqlhist-lex.o
diff --git a/src/tracefs-eprobes.c b/src/tracefs-eprobes.c
new file mode 100644
index 0000000..cc25f8e
--- /dev/null
+++ b/src/tracefs-eprobes.c
@@ -0,0 +1,56 @@ 
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * Copyright (C) 2021, VMware, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
+ *
+ */
+#include <stdlib.h>
+#include <errno.h>
+
+#include "tracefs.h"
+#include "tracefs-local.h"
+
+#define EPROBE_DEFAULT_GROUP "eprobes"
+
+/**
+ * tracefs_eprobe_alloc - Allocate new eprobe
+ * @system: The system name (NULL for the default eprobes)
+ * @event: The name of the event to create
+ * @target_system: The system of the target event
+ * @target_event: The name of the target event
+ * @fetchargs: String with arguments, that will be fetched from @target_event
+ *
+ * Allocate an eprobe context that will be in the @system group (or eprobes if
+ * @system is NULL). Have the name of @event. The new eprobe will be attached to
+ * given @target_event which is in the given @target_system. The arguments
+ * described in @fetchargs will fetched from the @target_event.
+ *
+ * The eprobe is not created in the system.
+ *
+ * Return a pointer to a eprobe context on success, or NULL on error.
+ * The returned pointer must be freed with tracefs_dynevent_free()
+ *
+ */
+struct tracefs_dynevent *
+tracefs_eprobe_alloc(const char *system, const char *event,
+		     const char *target_system, const char *target_event, const char *fetchargs)
+{
+	struct tracefs_dynevent *kp;
+	char *target;
+
+	if (!event || !target_system || !target_event) {
+		errno = EINVAL;
+		return NULL;
+	}
+
+	if (!system)
+		system = EPROBE_DEFAULT_GROUP;
+
+	if (asprintf(&target, "%s.%s", target_system, target_event) < 0)
+		return NULL;
+
+	kp = dynevent_alloc(TRACEFS_DYNEVENT_EPROBE, system, event, target, fetchargs);
+	free(target);
+
+	return kp;
+}
+