diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2023-12-24 14:16:01 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2023-12-24 14:28:01 -0500 |
commit | f6bdff749f1e942f91952a9366f9be769d4e50ca (patch) | |
tree | cfe96f6c5d84cc37a74813551d9cfecd191fc3ba | |
parent | 058211897ea394311801335a3bc6d6679b9cf39e (diff) | |
download | libtraceevent-f6bdff749f1e942f91952a9366f9be769d4e50ca.tar.gz |
kbuffer: Add kbuffer_dup()
Add the function kbuffer_dup() that will duplicate a current kbuffer structure
that can be used separately on the same subbuffer or load a new buffer on it.
Link: https://lore.kernel.org/linux-trace-devel/20231224191813.1076074-5-rostedt@goodmis.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | Documentation/libtraceevent-kbuffer-create.txt | 8 | ||||
-rw-r--r-- | Documentation/libtraceevent.txt | 1 | ||||
-rw-r--r-- | include/traceevent/kbuffer.h | 1 | ||||
-rw-r--r-- | src/kbuffer-parse.c | 20 |
4 files changed, 29 insertions, 1 deletions
diff --git a/Documentation/libtraceevent-kbuffer-create.txt b/Documentation/libtraceevent-kbuffer-create.txt index 12e5d6c..7279dbe 100644 --- a/Documentation/libtraceevent-kbuffer-create.txt +++ b/Documentation/libtraceevent-kbuffer-create.txt @@ -3,7 +3,7 @@ libtraceevent(3) NAME ---- -kbuffer_alloc, 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_size, kbuffer_start_of_data - Creating of kbuffer element to parse the Linux kernel tracing ring buffer SYNOPSIS @@ -28,6 +28,7 @@ struct kbuffer; struct tep_handle; struct kbuffer pass:[*]*kbuffer_alloc*(enum kbuffer_long_size _size_, enum kbuffer_endian _endian_); +struct kbuffer pass:[*]*kbuffer_dup*(struct kbuffer pass:[*]_kbuf_); 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); @@ -59,6 +60,11 @@ will then perform a *uname(2)* call, and if the _machine_ field has the string " in it, it will be set to 8 byte long size and not 4 byte. This is because the ring buffer long size is dependent on the kernel and not user space. +The *kbuffer_dup()* function will duplicate an existing kbuffer structure with +an allocated new one. It will have all the properties of the passed in _kbuf_, +including pointing to the same subbuffer that was loaded in the _kbuf_. +It must be freed with *kbuffer_free()*. + The *kbuffer_free()* function will free the resources created by *kbuffer_alloc()*. The *kbuffer_load_subbuffer()* will take a _subbuffer_ which is a raw data blob diff --git a/Documentation/libtraceevent.txt b/Documentation/libtraceevent.txt index 407c068..8b63982 100644 --- a/Documentation/libtraceevent.txt +++ b/Documentation/libtraceevent.txt @@ -181,6 +181,7 @@ Trace sequences: kbuffer parsing: #include <kbuffer.h> struct kbuffer pass:[*]*kbuffer_alloc*(enum kbuffer_long_size _size_, enum kbuffer_endian _endian_); + struct kbuffer pass:[*]*kbuffer_dup*(struct kbuffer pass:[*]_kbuf_); 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); diff --git a/include/traceevent/kbuffer.h b/include/traceevent/kbuffer.h index e5d377b..7086e03 100644 --- a/include/traceevent/kbuffer.h +++ b/include/traceevent/kbuffer.h @@ -31,6 +31,7 @@ enum { struct kbuffer; struct kbuffer *kbuffer_alloc(enum kbuffer_long_size size, enum kbuffer_endian endian); +struct kbuffer *kbuffer_dup(struct kbuffer *kbuf); void kbuffer_free(struct kbuffer *kbuf); int kbuffer_load_subbuffer(struct kbuffer *kbuf, void *subbuffer); void *kbuffer_read_event(struct kbuffer *kbuf, unsigned long long *ts); diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c index b86c8f0..b117094 100644 --- a/src/kbuffer-parse.c +++ b/src/kbuffer-parse.c @@ -269,6 +269,26 @@ kbuffer_alloc(enum kbuffer_long_size size, enum kbuffer_endian endian) return kbuf; } +/** + * kbuffer_dup - duplicate a given kbuffer + * @kbuf_orig; The kbuffer to duplicate + * + * Allocates a new kbuffer based off of anothe kbuffer. + * Returns the duplicate on success or NULL on error. + */ +struct kbuffer *kbuffer_dup(struct kbuffer *kbuf_orig) +{ + struct kbuffer *kbuf; + + kbuf = malloc(sizeof(*kbuf)); + if (!kbuf) + return NULL; + + *kbuf = *kbuf_orig; + + return kbuf; +} + /** kbuffer_free - free an allocated kbuffer * @kbuf: The kbuffer to free * |