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 (Google)" <rostedt@goodmis.org>
Subject: [PATCH 16/23] libtracefs: Add tracefs_load_headers() API
Date: Thu, 28 Dec 2023 15:35:38 -0500	[thread overview]
Message-ID: <20231228203714.53294-17-rostedt@goodmis.org> (raw)
In-Reply-To: <20231228203714.53294-1-rostedt@goodmis.org>

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

Sometimes the only thing that is needed from the tracefs directory is how to
parse the sub-buffers. The tracefs_fill_local_events() has a lot of overhead
as it reads pretty much everything. But if the only thing needed is the
header file parsing, add this helper function to do it.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 Documentation/libtracefs-events-tep.txt |  7 ++++++-
 Documentation/libtracefs.txt            |  1 +
 include/tracefs.h                       |  2 ++
 src/tracefs-events.c                    | 22 ++++++++++++++++++++++
 src/tracefs-record.c                    |  9 +--------
 5 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/Documentation/libtracefs-events-tep.txt b/Documentation/libtracefs-events-tep.txt
index 22d3dd5fdfd0..ba46532a8db1 100644
--- a/Documentation/libtracefs-events-tep.txt
+++ b/Documentation/libtracefs-events-tep.txt
@@ -4,7 +4,7 @@ libtracefs(3)
 NAME
 ----
 tracefs_local_events, tracefs_local_events_system, tracefs_fill_local_events,
-tracefs_load_cmdlines -
+tracefs_load_cmdlines, tracefs_load_headers -
 Initialize a tep handler with trace events from the local system.
 
 SYNOPSIS
@@ -17,6 +17,7 @@ struct tep_handle pass:[*]*tracefs_local_events*(const char pass:[*]_tracing_dir
 struct tep_handle pass:[*]*tracefs_local_events_system*(const char pass:[*]_tracing_dir_, const char pass:[*] const pass:[*]_sys_names_);
 int *tracefs_fill_local_events*(const char pass:[*]_tracing_dir_, struct tep_handle pass:[*]_tep_, int pass:[*]_parsing_failures_);
 int *tracefs_load_cmdlines*(const char pass:[*]_tracing_dir_, struct tep_handle pass:[*]_tep_);
+int *tracefs_load_headers*(const char pass:[*]_tracing_dir_, struct tep_handle pass:[*]_tep_);
 --
 
 DESCRIPTION
@@ -55,6 +56,10 @@ The *tracefs_load_cmdlines()* does just that. The _tracing_dir_ is
 the directory of the mount point to load from, or NULL to use the
 mount point of the tracefs file system.
 
+The *tracefs_load_headers()* will reade the "header_page" of the events
+directory that will update the _tep_ handle with information on how to parse the
+tracing ring buffer sub-buffer.
+
 RETURN VALUE
 ------------
 The *tracefs_local_events()* and *tracefs_local_events_system()* functions
diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt
index 273423cecf4a..70bd8116b2b1 100644
--- a/Documentation/libtracefs.txt
+++ b/Documentation/libtracefs.txt
@@ -80,6 +80,7 @@ Trace events:
 	struct tep_handle pass:[*]*tracefs_local_events_system*(const char pass:[*]_tracing_dir_, const char pass:[*] const pass:[*]_sys_names_);
 	int *tracefs_fill_local_events*(const char pass:[*]_tracing_dir_, struct tep_handle pass:[*]_tep_, int pass:[*]_parsing_failures_);
 	int *tracefs_load_cmdlines*(const char pass:[*]_tracing_dir_, struct tep_handle pass:[*]_tep_);
+	int *tracefs_load_headers*(const char pass:[*]_tracing_dir_, struct tep_handle pass:[*]_tep_);
 	char pass:[*]*tracefs_event_get_file*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_system_, const char pass:[*]_event_,
 			     const char pass:[*]_file_);
 	char pass:[*]*tracefs_event_file_read*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_system_, const char pass:[*]_event_,
diff --git a/include/tracefs.h b/include/tracefs.h
index 31aba92d9a16..95bff1f244f9 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -180,6 +180,8 @@ int tracefs_fill_local_events(const char *tracing_dir,
 
 int tracefs_load_cmdlines(const char *tracing_dir, struct tep_handle *tep);
 
+int tracefs_load_headers(const char *tracing_dir, struct tep_handle *tep);
+
 char *tracefs_get_clock(struct tracefs_instance *instance);
 
 enum tracefs_option_id {
diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 2e87f9aa3af7..413c2df19998 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -1216,6 +1216,28 @@ int tracefs_load_cmdlines(const char *tracing_dir, struct tep_handle *tep)
 	return load_saved_cmdlines(tracing_dir, tep, true);
 }
 
+/**
+ * tracefs_load_headers - load just the headers into a tep handle
+ * @tracing_dir: The directory to load from (NULL to figure it out)
+ * @tep: The tep handle to load the headers into.
+ *
+ * Updates the @tep handle with the event and sub-buffer header
+ * information.
+ *
+ * Returns 0 on success and -1 on error.
+ */
+int tracefs_load_headers(const char *tracing_dir, struct tep_handle *tep)
+{
+	int ret;
+
+	if (!tracing_dir)
+		tracing_dir = tracefs_tracing_dir();
+
+	ret = read_header(tep, tracing_dir);
+
+	return ret < 0 ? -1 : 0;
+}
+
 static int fill_local_events_system(const char *tracing_dir,
 				    struct tep_handle *tep,
 				    const char * const *sys_names,
diff --git a/src/tracefs-record.c b/src/tracefs-record.c
index bfeae18fd77f..1eede996631d 100644
--- a/src/tracefs-record.c
+++ b/src/tracefs-record.c
@@ -110,10 +110,8 @@ tracefs_cpu_open(struct tracefs_instance *instance, int cpu, bool nonblock)
 	struct tep_handle *tep;
 	struct kbuffer *kbuf;
 	char path[128];
-	char *buf;
 	int mode = O_RDONLY;
 	int subbuf_size;
-	int len;
 	int ret;
 	int fd;
 
@@ -131,12 +129,7 @@ tracefs_cpu_open(struct tracefs_instance *instance, int cpu, bool nonblock)
 		goto fail;
 
 	/* Get the size of the page */
-	buf = tracefs_instance_file_read(NULL, "events/header_page", &len);
-	if (!buf)
-		goto fail;
-
-	ret = tep_parse_header_page(tep, buf, len, sizeof(long));
-	free(buf);
+	ret = tracefs_load_headers(NULL, tep);
 	if (ret < 0)
 		goto fail;
 
-- 
2.42.0


  parent reply	other threads:[~2023-12-28 20:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28 20:35 [PATCH 00/23] libtracefs: Several updates Steven Rostedt
2023-12-28 20:35 ` [PATCH 01/23] libtracefs Documentation: Fix tracefs_event_file_exists() issues Steven Rostedt
2023-12-28 20:35 ` [PATCH 02/23] libtracefs testing: Use one tep handle for most tests Steven Rostedt
2023-12-28 20:35 ` [PATCH 03/23] libtracefs: Free "missed_followers" of instance Steven Rostedt
2023-12-28 20:35 ` [PATCH 04/23] libtracefs: Free buf in clear_func_filter() Steven Rostedt
2023-12-28 20:35 ` [PATCH 05/23] libtracefs: Free tracing_dir in case of remount Steven Rostedt
2023-12-28 20:35 ` [PATCH 06/23] libtracefs: Free dynamic event list in utest Steven Rostedt
2023-12-28 20:35 ` [PATCH 07/23] libtracefs: Reset tracing before and after unit tests Steven Rostedt
2023-12-28 20:35 ` [PATCH 08/23] libtracefs: Add API to remove followers from an instance or toplevel Steven Rostedt
2023-12-28 20:35 ` [PATCH 09/23] libtracefs: Increase splice to use pipe max size Steven Rostedt
2023-12-28 20:35 ` [PATCH 10/23] libtracefs: Add tracefs_instance_file_write_number() Steven Rostedt
2023-12-28 20:35 ` [PATCH 11/23] libtracefs: Add API to read tracefs_cpu and return a kbuffer Steven Rostedt
2023-12-28 20:35 ` [PATCH 12/23] libtracefs: Add tracefs_instance_get/set_buffer_percent() Steven Rostedt
2023-12-28 20:35 ` [PATCH 13/23] libtracefs: Add tracefs_instance_clear() API Steven Rostedt
2023-12-28 20:35 ` [PATCH 14/23] libtracefs utest: Add test to test tracefs_instance_set/get_buffer_percent() Steven Rostedt
2023-12-28 20:35 ` [PATCH 15/23] libtracefs: Add kerneldoc comments to tracefs_instance_set_buffer_size() Steven Rostedt
2023-12-28 20:35 ` Steven Rostedt [this message]
2023-12-28 20:35 ` [PATCH 17/23] libtracefs: Add API to extract ring buffer statistics Steven Rostedt
2023-12-28 20:35 ` [PATCH 18/23] libtracefs: Add tracefs_instance_set/get_subbuf_size() Steven Rostedt
2023-12-28 20:35 ` [PATCH 19/23] libtracefs: Add ring buffer memory mapping APIs Steven Rostedt
2023-12-28 20:35 ` [PATCH 20/23] libtracefs: Add TIMESTAMP_USECS_DELTA to simplify SQL timestamp compares Steven Rostedt
2023-12-28 20:35 ` [PATCH 21/23] libtracefs: Also clear max_graph_depth on reset Steven Rostedt
2023-12-28 20:35 ` [PATCH 22/23] libtracefs: Add PID filtering API Steven Rostedt
2023-12-28 20:35 ` [PATCH 23/23] libtracefs: Add updating and reading snapshot buffers 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=20231228203714.53294-17-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.