From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
Yordan Karadzhov <ykaradzhov@vmware.com>
Subject: [PATCH 1/8] kernel-shark: Add more sanity checks for model misbehavior detection
Date: Wed, 13 Feb 2019 18:12:09 +0200 [thread overview]
Message-ID: <20190213161216.14438-2-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20190213161216.14438-1-ykaradzhov@vmware.com>
I found that those checks are very useful for early detection of
misbehavior (bugs) of the visualization model. In particular those
checks helped me a lot when developing the multi-stream branch of
KernelShark (future version 2.0).
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
kernel-shark/src/libkshark-model.c | 28 +++++++++++++++++++---------
kernel-shark/src/libkshark.c | 7 ++++++-
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/kernel-shark/src/libkshark-model.c b/kernel-shark/src/libkshark-model.c
index 2094795..a4041c3 100644
--- a/kernel-shark/src/libkshark-model.c
+++ b/kernel-shark/src/libkshark-model.c
@@ -299,6 +299,7 @@ static void ksmodel_set_next_bin_edge(struct kshark_trace_histo *histo,
static void ksmodel_set_bin_counts(struct kshark_trace_histo *histo)
{
int i = 0, prev_not_empty;
+ ssize_t count_tmp;
histo->tot_count = 0;
memset(&histo->bin_count[0], 0,
@@ -329,12 +330,18 @@ static void ksmodel_set_bin_counts(struct kshark_trace_histo *histo)
* empty bin, which will give us the number of data
* rows in the "prev_not_empty" bin.
*/
- histo->bin_count[prev_not_empty] =
- histo->map[i] - histo->map[prev_not_empty];
+ count_tmp = histo->map[i] - histo->map[prev_not_empty];
+
+ /*
+ * We will do a sanity check. The number of data rows
+ * in the previous not empty bin must be greater than
+ * zero.
+ */
+ assert(count_tmp > 0);
+ histo->bin_count[prev_not_empty] = count_tmp;
if (prev_not_empty != LOB(histo))
- histo->tot_count +=
- histo->bin_count[prev_not_empty];
+ histo->tot_count += count_tmp;
prev_not_empty = i;
}
@@ -346,19 +353,22 @@ static void ksmodel_set_bin_counts(struct kshark_trace_histo *histo)
* The Upper Overflow bin is empty. Use the size of the dataset
* to calculate the content of the previouse not empty bin.
*/
- histo->bin_count[prev_not_empty] = histo->data_size -
- histo->map[prev_not_empty];
+ count_tmp = histo->data_size - histo->map[prev_not_empty];
} else {
/*
* Use the index of the first entry inside the Upper Overflow
* bin to calculate the content of the previouse not empty
* bin.
*/
- histo->bin_count[prev_not_empty] = histo->map[UOB(histo)] -
- histo->map[prev_not_empty];
+ count_tmp = histo->map[UOB(histo)] - histo->map[prev_not_empty];
}
- histo->tot_count += histo->bin_count[prev_not_empty];
+ /*
+ * We will do a sanity check. The number of data rows in the last not
+ * empty bin must be greater than zero.
+ */
+ assert(count_tmp > 0);
+ histo->tot_count += histo->bin_count[prev_not_empty] = count_tmp;
}
/**
diff --git a/kernel-shark/src/libkshark.c b/kernel-shark/src/libkshark.c
index 5033e47..9a41945 100644
--- a/kernel-shark/src/libkshark.c
+++ b/kernel-shark/src/libkshark.c
@@ -1552,7 +1552,7 @@ const struct kshark_entry dummy_entry = {
static const struct kshark_entry *
get_entry(const struct kshark_entry_request *req,
struct kshark_entry **data,
- ssize_t *index, size_t start, ssize_t end, int inc)
+ ssize_t *index, ssize_t start, ssize_t end, int inc)
{
struct kshark_context *kshark_ctx = NULL;
const struct kshark_entry *e = NULL;
@@ -1564,6 +1564,11 @@ get_entry(const struct kshark_entry_request *req,
if (!kshark_instance(&kshark_ctx))
return e;
+ /*
+ * We will do a sanity check in order to protect against infinite
+ * loops.
+ */
+ assert((inc > 0 && start < end) || (inc < 0 && start > end));
for (i = start; i != end; i += inc) {
if (req->cond(kshark_ctx, data[i], req->val)) {
/*
--
2.17.1
next prev parent reply other threads:[~2019-02-13 16:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-13 16:12 [PATCH 0/8] Various modifications toward KS 1.0 Yordan Karadzhov
2019-02-13 16:12 ` Yordan Karadzhov [this message]
2019-02-13 16:12 ` [PATCH 2/8] kernel-shark: Do not copy the Upper Overflow bin when shifting forward Yordan Karadzhov
2019-02-13 16:12 ` [PATCH 3/8] kernel-shark: Check bin 0 for sched_switch event when plotting task graphs Yordan Karadzhov
2019-02-13 16:12 ` [PATCH 4/8] kernel-shark: Don't use Data collection when checking if the bin is empty Yordan Karadzhov
2019-02-13 16:12 ` [PATCH 5/8] kernel-shark: Make the time labels of the marker more readable Yordan Karadzhov
2019-02-13 16:12 ` [PATCH 6/8] kernel-shark: Fix the compile warnings about _GNU_SOURCE being redefined Yordan Karadzhov
2019-02-13 16:12 ` [PATCH 7/8] trace-cmd: Fix the printout of the KernelShark executable path Yordan Karadzhov
2019-02-13 16:12 ` [PATCH 8/8] kernel-shark: Version 1.0.0 Yordan Karadzhov
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=20190213161216.14438-2-ykaradzhov@vmware.com \
--to=ykaradzhov@vmware.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).