linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 1/4] libtracefs: Reuse logic for loading events inside the library
Date: Thu,  2 Dec 2021 12:59:23 +0200	[thread overview]
Message-ID: <20211202105926.32581-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20211202105926.32581-1-tz.stoyanov@gmail.com>

The logic for parsing and loading new tep events could be reused in
tracefs library. Two new internal APIs are introduced:
	trace_load_events()
	trace_rescan_events()

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs-local.h |  5 +++++
 src/tracefs-events.c    | 26 +++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index a59e806..daea5da 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -112,4 +112,9 @@ dynevent_alloc(enum tracefs_dynevent_type type, const char *system,
 	       const char *event, const char *address, const char *format);
 int dynevent_get_count(unsigned int types, const char *system);
 
+int trace_load_events(struct tep_handle *tep,
+		      const char *tracing_dir, const char *system);
+int trace_rescan_events(struct tep_handle *tep,
+			const char *tracing_dir, const char *system);
+
 #endif /* _TRACE_FS_LOCAL_H */
diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 4679926..067f6e0 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -689,7 +689,7 @@ char **tracefs_tracers(const char *tracing_dir)
 }
 
 static int load_events(struct tep_handle *tep,
-		       const char *tracing_dir, const char *system)
+		       const char *tracing_dir, const char *system, bool check)
 {
 	int ret = 0, failure = 0;
 	char **events = NULL;
@@ -697,6 +697,9 @@ static int load_events(struct tep_handle *tep,
 	int len = 0;
 	int i;
 
+	if (!tracing_dir)
+		tracing_dir = tracefs_tracing_dir();
+
 	events = tracefs_system_events(tracing_dir, system);
 	if (!events)
 		return -ENOENT;
@@ -716,6 +719,10 @@ static int load_events(struct tep_handle *tep,
 		if (ret < 0)
 			goto next_event;
 
+		/* check if event is already added, to avoid duplicates */
+		if (check && tep_find_event_by_name(tep, system, events[i]))
+			goto next_event;
+
 		len = str_read_file(format, &buf, true);
 		if (len <= 0)
 			goto next_event;
@@ -732,6 +739,19 @@ next_event:
 	return failure;
 }
 
+__hidden int trace_rescan_events(struct tep_handle *tep,
+				const char *tracing_dir, const char *system)
+{
+	/* ToDo: add here logic for deleting removed events from tep handle */
+	return load_events(tep, tracing_dir, system, true);
+}
+
+__hidden int trace_load_events(struct tep_handle *tep,
+			       const char *tracing_dir, const char *system)
+{
+	return load_events(tep, tracing_dir, system, false);
+}
+
 static int read_header(struct tep_handle *tep, const char *tracing_dir)
 {
 	struct stat st;
@@ -886,14 +906,14 @@ static int fill_local_events_system(const char *tracing_dir,
 	for (i = 0; systems[i]; i++) {
 		if (sys_names && !contains(systems[i], sys_names))
 			continue;
-		ret = load_events(tep, tracing_dir, systems[i]);
+		ret = trace_load_events(tep, tracing_dir, systems[i]);
 		if (ret && parsing_failures)
 			(*parsing_failures)++;
 	}
 
 	/* Include ftrace, as it is excluded for not having "enable" file */
 	if (!sys_names || contains("ftrace", sys_names))
-		load_events(tep, tracing_dir, "ftrace");
+		trace_load_events(tep, tracing_dir, "ftrace");
 
 	load_mappings(tracing_dir, tep);
 
-- 
2.33.1


  reply	other threads:[~2021-12-02 10:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-02 10:59 [PATCH v2 0/4] New tracefs APIs Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` Tzvetomir Stoyanov (VMware) [this message]
2021-12-02 10:59 ` [PATCH v2 2/4] libtracefs: New API for getting dynamic event Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` [PATCH v2 3/4] libtracefs: Unit test for tracefs_dynevent_get_event() Tzvetomir Stoyanov (VMware)
2021-12-02 10:59 ` [PATCH v2 4/4] libtracefs: New API for applying filter on event Tzvetomir Stoyanov (VMware)

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=20211202105926.32581-2-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --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).