diff options
author | Yordan Karadzhov <ykaradzhov@vmware.com> | 2019-02-13 18:12:09 +0200 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2019-02-13 12:10:53 -0500 |
commit | d760045c609097a2cc94eab62837172cdf1c0318 (patch) | |
tree | 92b3df41bfd3f9e5ef2b2a9dd883981a6f2feea4 | |
parent | ed60f0b6f6d40d674b3b868dfc006328ab95e985 (diff) | |
download | trace-cmd-d760045c609097a2cc94eab62837172cdf1c0318.tar.gz |
kernel-shark: Add more sanity checks for model misbehavior detection
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).
Link: http://lore.kernel.org/linux-trace-devel/20190213161216.14438-2-ykaradzhov@vmware.com
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | kernel-shark/src/libkshark-model.c | 28 | ||||
-rw-r--r-- | 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 20947958..a4041c37 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 5033e47f..9a41945a 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)) { /* |