diff mbox series

[5/6] kbuffer: Add kbuffer_subbuffer() API

Message ID 20231224191813.1076074-6-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 33bad32779279a68b69f2f78ecdda0bce3a019bf
Headers show
Series libtraceevent/kbuffer: Add more kbuffer APIs | expand

Commit Message

Steven Rostedt Dec. 24, 2023, 7:16 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Add a way to retrieve the last loaded subbuffer to the kbuffer.

The kbuffer_subbuffer() will return a pointer to the last loaded subbuffer or
NULL if none was ever loaded.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 Documentation/libtraceevent-kbuffer-create.txt | 11 ++++++++++-
 Documentation/libtraceevent.txt                |  1 +
 include/traceevent/kbuffer.h                   |  1 +
 src/kbuffer-parse.c                            | 11 +++++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/Documentation/libtraceevent-kbuffer-create.txt b/Documentation/libtraceevent-kbuffer-create.txt
index 7279dbe56b01..0dca31432455 100644
--- a/Documentation/libtraceevent-kbuffer-create.txt
+++ b/Documentation/libtraceevent-kbuffer-create.txt
@@ -3,7 +3,8 @@  libtraceevent(3)
 
 NAME
 ----
-kbuffer_alloc, kbuffer_dup, kbuffer_free, kbuffer_load_subbuffer, kbuffer_subbuffer_size, kbuffer_start_of_data - Creating of kbuffer element to parse
+kbuffer_alloc, kbuffer_dup, kbuffer_free, kbuffer_load_subbuffer, kbuffer_subbuffer,
+kbuffer_subbuffer_size, kbuffer_start_of_data - Creating of kbuffer element to parse
 the Linux kernel tracing ring buffer
 
 SYNOPSIS
@@ -33,6 +34,7 @@  void *kbuffer_free*(struct kbuffer pass:[*]_kbuf_);
 int *kbuffer_load_subbuffer*(struct kbuffer pass:[*]_kbuf_, void pass:[*]_subbuffer_);
 int *kbuffer_subbuffer_size*(struct kbuffer pass:[*]_kbuf);
 int *kbuffer_start_of_data*(struct kbuffer pass:[*]_kbuf_);
+void pass:[*]*kbuffer_subbuffer*(struct kbuffer pass:[*]_kbuf);
 --
 
 DESCRIPTION
@@ -79,6 +81,10 @@  on the sub-buffer. It does not return the size of the sub-buffer itself.
 The *kbuffer_start_of_data()* function returns the offset of where the actual
 data load of the sub-buffer begins.
 
+The *kbuffer_subbuffer()* function returns the pointer to the currently loaded
+subbuffer. That is, the last subbuffer that was loaded by *kbuffer_load_subbuffer()*.
+If no subbuffer was loaded NULL is returned.
+
 RETURN VALUE
 ------------
 *kbuffer_alloc()* returns an allocated kbuffer descriptor or NULL on error.
@@ -92,6 +98,9 @@  of the last event is located.
 *kbuffer_start_of_data()* returns the offset of where the data begins on the
 sub-buffer loaded in _kbuf_.
 
+*kbuffer_subbuffer()* returns the last loaded subbuffer to _kbuf_ that was loaded
+by *kbuffer_load_subbuffer()* or NULL if none was loaded.
+
 EXAMPLE
 -------
 [source,c]
diff --git a/Documentation/libtraceevent.txt b/Documentation/libtraceevent.txt
index 8b63982e541e..253c9ea810aa 100644
--- a/Documentation/libtraceevent.txt
+++ b/Documentation/libtraceevent.txt
@@ -185,6 +185,7 @@  kbuffer parsing:
 	void *kbuffer_free*(struct kbuffer pass:[*]_kbuf_);
 	int *kbuffer_load_subbuffer*(struct kbuffer pass:[*]_kbuf_, void pass:[*]_subbuffer_);
 	int *kbuffer_subbuffer_size*(struct kbuffer pass:[*]_kbuf);
+	void pass:[*]*kbuffer_subbuffer*(struct kbuffer pass:[*]_kbuf);
 	int *kbuffer_start_of_data*(struct kbuffer pass:[*]_kbuf_);
 	unsigned long long *kbuffer_timestamp*(struct kbuffer pass:[*]_kbuf_);
 	unsigned long long *kbuffer_subbuf_timestamp*(struct kbuffer pass:[*]_kbuf_, void pass:[*]_subbuf_);
diff --git a/include/traceevent/kbuffer.h b/include/traceevent/kbuffer.h
index 7086e0303e5c..624517ed334b 100644
--- a/include/traceevent/kbuffer.h
+++ b/include/traceevent/kbuffer.h
@@ -52,6 +52,7 @@  int kbuffer_curr_size(struct kbuffer *kbuf);
 int kbuffer_event_size(struct kbuffer *kbuf);
 int kbuffer_missed_events(struct kbuffer *kbuf);
 int kbuffer_subbuffer_size(struct kbuffer *kbuf);
+void *kbuffer_subbuffer(struct kbuffer *kbuf);
 
 void kbuffer_set_old_format(struct kbuffer *kbuf);
 int kbuffer_start_of_data(struct kbuffer *kbuf);
diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c
index b117094856bc..b218d1fc9679 100644
--- a/src/kbuffer-parse.c
+++ b/src/kbuffer-parse.c
@@ -747,6 +747,17 @@  int kbuffer_subbuffer_size(struct kbuffer *kbuf)
 	return kbuf->size;
 }
 
+/**
+ * kbuffer_subbuffer - the currently loaded subbuffer
+ * @kbuf:	The kbuffer to read from
+ *
+ * Returns the currently loaded subbuffer.
+ */
+void *kbuffer_subbuffer(struct kbuffer *kbuf)
+{
+	return kbuf->subbuffer;
+}
+
 /**
  * kbuffer_curr_index - Return the index of the record
  * @kbuf:	The kbuffer to read from