aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYordan Karadzhov (VMware) <y.karadz@gmail.com>2020-12-11 17:07:46 +0200
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2020-12-21 19:11:05 -0500
commite30b406e9f1ce99658c542970dae60e2ed8a913e (patch)
tree39c59d6f3993a99857aa76fdb1f4d02b255d0089
parent75230293932c29c979ca471e564d0b27eeab9dbb (diff)
downloadkernel-shark-e30b406e9f1ce99658c542970dae60e2ed8a913e.tar.gz
kernel-shark: Add ksmodel_get_bin()
The method retrieves the Id of the bin of the model that contains given entry. Link: https://lore.kernel.org/linux-trace-devel/20201211150756.577366-23-y.karadz@gmail.com Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--src/libkshark-model.c27
-rw-r--r--src/libkshark-model.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/src/libkshark-model.c b/src/libkshark-model.c
index f3864bfd..2301b069 100644
--- a/src/libkshark-model.c
+++ b/src/libkshark-model.c
@@ -1325,3 +1325,30 @@ ksmodel_get_task_missed_events(struct kshark_trace_histo *histo,
match_pid_missed_events, sd, &pid,
col, index);
}
+
+/**
+ * @brief Find the bin Id of a give entry.
+ *
+ * @param histo: Input location for the model descriptor.
+ * @param entry: Input location for entry.
+ *
+ * @returns If the timestamp of the entry is inside the range of the model the
+ * function returns the Id of the bin it belongs to.
+ * If the timestamp of the entry is outside of the range of the model
+ * the function returns UPPER_OVERFLOW_BIN or LOWER_OVERFLOW_BIN
+ * (negative values).
+ */
+int ksmodel_get_bin(struct kshark_trace_histo *histo,
+ const struct kshark_entry *entry)
+{
+ if (entry->ts < histo->min)
+ return UPPER_OVERFLOW_BIN;
+
+ if (entry->ts > histo->max)
+ return LOWER_OVERFLOW_BIN;
+
+ if (entry->ts == histo->max)
+ return histo->n_bins - 1;
+
+ return (entry->ts - histo->min) / histo->bin_size;
+}
diff --git a/src/libkshark-model.h b/src/libkshark-model.h
index b8624809..8989ee0e 100644
--- a/src/libkshark-model.h
+++ b/src/libkshark-model.h
@@ -175,6 +175,9 @@ static inline double ksmodel_bin_time(struct kshark_trace_histo *histo,
return ksmodel_bin_ts(histo, bin) * 1e-9;
}
+int ksmodel_get_bin(struct kshark_trace_histo *histo,
+ const struct kshark_entry *entry);
+
#ifdef __cplusplus
}
#endif // __cplusplus