linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernel-shark: Fix bug in filter clearing
@ 2021-05-11 13:36 Yordan Karadzhov (VMware)
  0 siblings, 0 replies; only message in thread
From: Yordan Karadzhov (VMware) @ 2021-05-11 13:36 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware), Steven Rostedt

Applying a filter to the loaded tracing data requires looping over
the entire data-set of entries. On large data-set this can be very
expensive operation. To coop with this, a number of checks are putted
in place to making sure that a loop is not performed in a case when
it is not really needed. However, there is a mistake in the logic of
these checks. So far we considered that calling filter_entries() with
no filter being set does not require looping over the data. But this
is not correct because if a filter had been applied already, calling
the function with an empty filter is equivalent of clearing the
existing filter, hence  it is a legitimate operation and indeed we
need to loop over the data.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=206131
Reported-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/libkshark.c | 20 ++++++++++++++++++--
 src/libkshark.h |  5 +++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/libkshark.c b/src/libkshark.c
index dc58dcf..1222a81 100644
--- a/src/libkshark.c
+++ b/src/libkshark.c
@@ -166,6 +166,7 @@ static struct kshark_data_stream *kshark_stream_alloc()
 		    goto fail;
 	}
 
+	stream->filter_is_applied = false;
 	kshark_set_data_format(stream->data_format, KS_INVALID_DATA);
 	stream->name = strdup(KS_UNNAMED);
 
@@ -1271,8 +1272,11 @@ static void filter_entries(struct kshark_context *kshark_ctx, int sd,
 			return;
 		}
 
-		if (!kshark_filter_is_set(kshark_ctx, sd))
+		if (!kshark_filter_is_set(kshark_ctx, sd) &&
+		    !stream->filter_is_applied) {
+			/* Nothing to be done. */
 			return;
+		}
 	}
 
 	/* Apply only the Id filters. */
@@ -1294,6 +1298,9 @@ static void filter_entries(struct kshark_context *kshark_ctx, int sd,
 
 		/* Apply Id filtering. */
 		kshark_apply_filters(kshark_ctx, stream, data[i]);
+
+		stream->filter_is_applied =
+			kshark_filter_is_set(kshark_ctx, sd)? true : false;
 	}
 }
 
@@ -1356,10 +1363,19 @@ void kshark_clear_all_filters(struct kshark_context *kshark_ctx,
 			      struct kshark_entry **data,
 			      size_t n_entries)
 {
-	int i;
+	struct kshark_data_stream *stream;
+	int *stream_ids, i;
 
 	for (i = 0; i < n_entries; ++i)
 		set_all_visible(&data[i]->visible);
+
+	stream_ids = kshark_all_streams(kshark_ctx);
+	for (i = 0; i < kshark_ctx->n_streams; i++) {
+		stream = kshark_get_data_stream(kshark_ctx, stream_ids[i]);
+		stream->filter_is_applied = false;
+	}
+
+	free(stream_ids);
 }
 
 /**
diff --git a/src/libkshark.h b/src/libkshark.h
index ee3a1d3..23e3b49 100644
--- a/src/libkshark.h
+++ b/src/libkshark.h
@@ -324,6 +324,11 @@ struct kshark_data_stream {
 	/** Hash of CPUs to not display. */
 	struct kshark_hash_id	*hide_cpu_filter;
 
+	/**
+	 * Flag showing if some entries are filtered out (marked as invisible).
+	 */
+	bool			filter_is_applied;
+
 	/** The type of the data. */
 	char			data_format[KS_DATA_FORMAT_SIZE];
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-11 13:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 13:36 [PATCH] kernel-shark: Fix bug in filter clearing Yordan Karadzhov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).