All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 06/11] libtracefs: Add new API tracefs_dynevent_get()
Date: Mon, 22 Nov 2021 18:49:51 -0500	[thread overview]
Message-ID: <20211122234956.788401-7-rostedt@goodmis.org> (raw)
In-Reply-To: <20211122234956.788401-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add tracefs_dynevent_get() that allows the user to look for a single
event, and not have to get all events in the system.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-dynevents.txt | 10 ++++++
 include/tracefs.h                      |  2 ++
 src/tracefs-dynevents.c                | 45 ++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/Documentation/libtracefs-dynevents.txt b/Documentation/libtracefs-dynevents.txt
index 89b2e92..a374651 100644
--- a/Documentation/libtracefs-dynevents.txt
+++ b/Documentation/libtracefs-dynevents.txt
@@ -20,6 +20,7 @@ int *tracefs_dynevent_destroy*(struct tracefs_dynevent pass:[*]_devent_, bool _f
 int *tracefs_dynevent_destroy_all*(unsigned int _types_, bool _force_);
 void *tracefs_dynevent_free*(struct tracefs_dynevent pass:[*]_devent_);
 void *tracefs_dynevent_list_free*(struct tracefs_dynevent pass:[*]pass:[*]_events_);
+struct tracefs_dynevent pass:[*]*tracefs_dynevent_get*(enum tracefs_dynevent_type _type_, const char pass:[*]_system_, const char pass:[*]_event_);
 struct tracefs_dynevent pass:[*]pass:[*]*tracefs_dynevent_get_all*(unsigned int _types_, const char pass:[*]_system_);
 enum tracefs_dynevent_type *tracefs_dynevent_info*(struct tracefs_dynevent pass:[*]_dynevent_, char pass:[*]pass:[*]_system_, char pass:[*]pass:[*]_event_, char pass:[*]pass:[*]_prefix_, char pass:[*]pass:[*]_addr_, char pass:[*]pass:[*]_format_);
 --
@@ -39,6 +40,12 @@ types *tracefs_dynevent_type*, that will be removed. If _types_ is 0, dynamic ev
 will be removed.  If _force_ is true, the function will attempt to disable all events in all trace
 instances, before removing the dynamic events.
 
+The *tracefs_dynevent_get*() function allocates and returns a single instance of a dynamic
+event that matches the given *type*, *system* and *event* that is passed to it. NULL is returned
+if there is no match. The returned event is what is found in the system, and must be freed
+with *tracefs_dynevent_free*(). If *system* is NULL, then the first *event* of any system
+of the given type that has the name of *event* will be returned.
+
 The *tracefs_dynevent_get_all*() function allocates and returns an array of pointers to dynamic
 events of given types that exist in the system. The last element of the array is a NULL pointer.
 The array must be freed with *tracefs_dynevent_list_free*(). If there are no events a NULL pointer is
@@ -70,6 +77,9 @@ RETURN VALUE
 *tracefs_dynevent_destroy*() and *tracefs_dynevent_destroy_all*() return 0 on success, or -1 on
 error. If _force_ is enabled, the functions may fail on disabling the events.
 
+*tracefs_dynevent_get*() function returns an allocated dynamic event from the system that matches
+the type, system and event given.
+
 *tracefs_dynevent_get_all*() function returns allocated array of pointers to dynamic events, or NULL
 in case of an error or in case there are no events in the system. That array must be freed by
 *tracefs_dynevent_list_free*().
diff --git a/include/tracefs.h b/include/tracefs.h
index 81efe87..2ced45c 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -257,6 +257,8 @@ void tracefs_dynevent_free(struct tracefs_dynevent *devent);
 void tracefs_dynevent_list_free(struct tracefs_dynevent **events);
 struct tracefs_dynevent **
 tracefs_dynevent_get_all(unsigned int types, const char *system);
+struct tracefs_dynevent *
+tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system, const char *event);
 enum tracefs_dynevent_type
 tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
 		      char **event, char **prefix, char **addr, char **format);
diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
index 0f7cccd..ea07d13 100644
--- a/src/tracefs-dynevents.c
+++ b/src/tracefs-dynevents.c
@@ -596,6 +596,51 @@ error:
 	return NULL;
 }
 
+/**
+ * tracefs_dynevent_get - return a single dynamic event if it exists
+ * @type; Dynamic event type
+ * @system: Get events from that system only. May be NULL.
+ * @event: Get event of the system type (may not be NULL)
+ *
+ * Returns the dynamic event of the given @type and @system for with the @event
+ * name. If @system is NULL, it will return the first dynamic event that it finds
+ * that matches the @event name.
+ *
+ * The returned event must be freed with tracefs_dynevent_free().
+ * NULL is returned if no event match is found, or other error.
+ */
+struct tracefs_dynevent *
+tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system,
+		     const char *event)
+{
+	struct tracefs_dynevent **events;
+	struct tracefs_dynevent *devent = NULL;
+	int count;
+	int i;
+
+	if (!event) {
+		errno = -EINVAL;
+		return NULL;
+	}
+
+	count = get_all_dynevents(type, system, &events);
+	if (count <= 0)
+		return NULL;
+
+	for (i = 0; i < count; i++) {
+		if (strcmp(events[i]->event, event) == 0)
+			break;
+	}
+	if (i < count) {
+		devent = events[i];
+		events[i] = NULL;
+	}
+
+	tracefs_dynevent_list_free(events);
+
+	return devent;
+}
+
 /**
  * tracefs_dynevent_destroy_all - removes all dynamic events of given types from the system
  * @types: Dynamic event type, or bitmask of dynamic event types. If 0 is passed, all types
-- 
2.31.1


  parent reply	other threads:[~2021-11-22 23:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
2021-11-22 23:49 ` [PATCH 01/11] libtracefs: Move creation of sqlhist into new samples directory Steven Rostedt
2021-11-22 23:49 ` [PATCH 02/11] libtracefs: Fix example in the dynamic events man page to compile Steven Rostedt
2021-11-22 23:49 ` [PATCH 03/11] libtracefs/Documentation: Fix man page examples to include the proper header Steven Rostedt
2021-11-22 23:49 ` [PATCH 04/11] tracefs/Documentation: Fix example in libtracefs-eprobes.txt to compile Steven Rostedt
2021-11-22 23:49 ` [PATCH 05/11] libtracefs: Make samples easily extract man page example programs Steven Rostedt
2021-11-22 23:49 ` Steven Rostedt [this message]
2021-11-22 23:49 ` [PATCH 07/11] libtracefs/Documentation: Fix example in libtracefs-error.txt Steven Rostedt
2021-11-22 23:49 ` [PATCH 08/11] libtracefs/Documentation: Fix function-filter call to tracefs_list_free() Steven Rostedt
2021-11-22 23:49 ` [PATCH 09/11] libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API Steven Rostedt
2021-11-22 23:49 ` [PATCH 10/11] libtracefs: Add all working man page examples to samples Steven Rostedt
2021-11-22 23:49 ` [PATCH 11/11] libtracefs/Documentation: Update stream example to have a parameter Steven Rostedt

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=20211122234956.788401-7-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.