diff mbox series

trace-cmd: Do not print stacks after stacks

Message ID 20240528113141.7a3e8a04@rorschach.local.home (mailing list archive)
State Accepted
Commit 7b8e92ae8a252ba565cc64218e39c6ec4a4025cb
Headers show
Series trace-cmd: Do not print stacks after stacks | expand

Commit Message

Steven Rostedt May 28, 2024, 3:31 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

When a filter is in place, the stack trace for the events that are
printed by the filter should also be printed. Stack traces for events
that are filtered out, should also be filtered out. But there was a bug
in the logic that checked if the last event was printed or not to know
to print the stack, and that is, the stack from the printed event was
considered a printed event itself. So a stack trace coming from another
event could be considered "printed" if two stacks came back to back
(which can happen because of interrupts.

Note, this does mean that logic should be added to test for interrupts.
But that's another story.

Reported-by: Vlastimil Babka <vbabka@suse.cz>
Fixes: 82ed4a937 ("trace-cmd library: Add filtering logic for iterating events")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-filter.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Vlastimil Babka June 4, 2024, 3:12 p.m. UTC | #1
On 5/28/24 5:31 PM, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> When a filter is in place, the stack trace for the events that are
> printed by the filter should also be printed. Stack traces for events
> that are filtered out, should also be filtered out. But there was a bug
> in the logic that checked if the last event was printed or not to know
> to print the stack, and that is, the stack from the printed event was
> considered a printed event itself. So a stack trace coming from another
> event could be considered "printed" if two stacks came back to back
> (which can happen because of interrupts.
> 
> Note, this does mean that logic should be added to test for interrupts.
> But that's another story.
> 
> Reported-by: Vlastimil Babka <vbabka@suse.cz>
> Fixes: 82ed4a937 ("trace-cmd library: Add filtering logic for iterating events")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Seems to work as intended now. Thanks!
Tested-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  lib/trace-cmd/trace-filter.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/trace-cmd/trace-filter.c b/lib/trace-cmd/trace-filter.c
> index 1c8c07fc..99423223 100644
> --- a/lib/trace-cmd/trace-filter.c
> +++ b/lib/trace-cmd/trace-filter.c
> @@ -47,6 +47,7 @@ static bool test_stacktraces(struct tracecmd_filter *filter, struct tep_record *
>  __hidden enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *filter,
>  						     struct tep_record *record)
>  {
> +	bool is_stack = false;
>  	bool found = false;
>  	int ret;
>  	int i;
> @@ -94,6 +95,8 @@ __hidden enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *fil
>  		/* If this is a stack trace and the last event was printed continue */
>  		if (!test_stacktraces(filter, record))
>  			return TRACECMD_FILTER_MISS;
> +
> +		is_stack = true;
>  	}
>  
>  	found = false;
> @@ -110,7 +113,7 @@ __hidden enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *fil
>  	}
>  
>  	if (filter->last_printed)
> -		filter->last_printed[record->cpu] = !found;
> +		filter->last_printed[record->cpu] = !is_stack && !found;
>  
>  	return found ? TRACECMD_FILTER_MISS : TRACECMD_FILTER_MATCH;
>  }
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-filter.c b/lib/trace-cmd/trace-filter.c
index 1c8c07fc..99423223 100644
--- a/lib/trace-cmd/trace-filter.c
+++ b/lib/trace-cmd/trace-filter.c
@@ -47,6 +47,7 @@  static bool test_stacktraces(struct tracecmd_filter *filter, struct tep_record *
 __hidden enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *filter,
 						     struct tep_record *record)
 {
+	bool is_stack = false;
 	bool found = false;
 	int ret;
 	int i;
@@ -94,6 +95,8 @@  __hidden enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *fil
 		/* If this is a stack trace and the last event was printed continue */
 		if (!test_stacktraces(filter, record))
 			return TRACECMD_FILTER_MISS;
+
+		is_stack = true;
 	}
 
 	found = false;
@@ -110,7 +113,7 @@  __hidden enum tracecmd_filters tracecmd_filter_match(struct tracecmd_filter *fil
 	}
 
 	if (filter->last_printed)
-		filter->last_printed[record->cpu] = !found;
+		filter->last_printed[record->cpu] = !is_stack && !found;
 
 	return found ? TRACECMD_FILTER_MISS : TRACECMD_FILTER_MATCH;
 }