From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: [PATCH] kernel-shark: Fix bug in filter clearing
Date: Tue, 11 May 2021 16:36:19 +0300 [thread overview]
Message-ID: <20210511133619.287496-1-y.karadz@gmail.com> (raw)
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
reply other threads:[~2021-05-11 13:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210511133619.287496-1-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).