diff mbox series

trace-cmd: Fix kbuffer_start_of_data() to return the first record

Message ID 20200706154714.27566-1-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit 6c18ee3436488802638503fa5d2969af3e20f1f4
Headers show
Series trace-cmd: Fix kbuffer_start_of_data() to return the first record | expand

Commit Message

Tzvetomir Stoyanov (VMware) July 6, 2020, 3:47 p.m. UTC
The first record in a ring buffer page may not allways be at the
beginning of the page. There could be time-extends injected before it.
In this case kbuffer_start_of_data() will not return the first record,
as expected. Additional filed "start" is added in kbuffer struct, to hold
the offset of the first record from the page and kbuffer_start_of_data()
is modified to use it.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/traceevent/kbuffer-parse.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Steven Rostedt July 6, 2020, 3:53 p.m. UTC | #1
On Mon,  6 Jul 2020 18:47:14 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> The first record in a ring buffer page may not allways be at the
> beginning of the page. There could be time-extends injected before it.
> In this case kbuffer_start_of_data() will not return the first record,
> as expected. Additional filed "start" is added in kbuffer struct, to hold
> the offset of the first record from the page and kbuffer_start_of_data()
> is modified to use it.

Thanks Tzvetomir,

I'm going to add a comment that this was originally taken from code I
wrote, and you cleaned it up and made it presentable. That way it
states why there's the two signed-off-bys.

-- Steve


> 
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
>  lib/traceevent/kbuffer-parse.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/traceevent/kbuffer-parse.c b/lib/traceevent/kbuffer-parse.c
> index 2c5f00a9..844db976 100644
> --- a/lib/traceevent/kbuffer-parse.c
> +++ b/lib/traceevent/kbuffer-parse.c
> @@ -35,6 +35,7 @@ enum {
>   * @next		- offset from @data to the start of next event
>   * @size		- The size of data on @data
>   * @start		- The offset from @subbuffer where @data lives
> + * @first		- The offset from @subbuffer where the first non time stamp event lives
>   *
>   * @read_4		- Function to read 4 raw bytes (may swap)
>   * @read_8		- Function to read 8 raw bytes (may swap)
> @@ -51,6 +52,7 @@ struct kbuffer {
>  	unsigned int		next;
>  	unsigned int		size;
>  	unsigned int		start;
> +	unsigned int		first;
>  
>  	unsigned int (*read_4)(void *ptr);
>  	unsigned long long (*read_8)(void *ptr);
> @@ -546,6 +548,9 @@ int kbuffer_load_subbuffer(struct kbuffer *kbuf, void *subbuffer)
>  
>  	next_event(kbuf);
>  
> +	/* save the first record from the page */
> +	kbuf->first = kbuf->curr;
> +
>  	return 0;
>  }
>  
> @@ -755,7 +760,7 @@ void kbuffer_set_old_format(struct kbuffer *kbuf)
>   */
>  int kbuffer_start_of_data(struct kbuffer *kbuf)
>  {
> -	return kbuf->start;
> +	return kbuf->first + kbuf->start;
>  }
>  
>  /**
diff mbox series

Patch

diff --git a/lib/traceevent/kbuffer-parse.c b/lib/traceevent/kbuffer-parse.c
index 2c5f00a9..844db976 100644
--- a/lib/traceevent/kbuffer-parse.c
+++ b/lib/traceevent/kbuffer-parse.c
@@ -35,6 +35,7 @@  enum {
  * @next		- offset from @data to the start of next event
  * @size		- The size of data on @data
  * @start		- The offset from @subbuffer where @data lives
+ * @first		- The offset from @subbuffer where the first non time stamp event lives
  *
  * @read_4		- Function to read 4 raw bytes (may swap)
  * @read_8		- Function to read 8 raw bytes (may swap)
@@ -51,6 +52,7 @@  struct kbuffer {
 	unsigned int		next;
 	unsigned int		size;
 	unsigned int		start;
+	unsigned int		first;
 
 	unsigned int (*read_4)(void *ptr);
 	unsigned long long (*read_8)(void *ptr);
@@ -546,6 +548,9 @@  int kbuffer_load_subbuffer(struct kbuffer *kbuf, void *subbuffer)
 
 	next_event(kbuf);
 
+	/* save the first record from the page */
+	kbuf->first = kbuf->curr;
+
 	return 0;
 }
 
@@ -755,7 +760,7 @@  void kbuffer_set_old_format(struct kbuffer *kbuf)
  */
 int kbuffer_start_of_data(struct kbuffer *kbuf)
 {
-	return kbuf->start;
+	return kbuf->first + kbuf->start;
 }
 
 /**