Currently each sampling is counted as a unit increment of the relevant
bucket. The total sum of sampled values is needed to compute averages
but it is not possible to derive from current kept measures.

Add a field in the histogram structure to store the aggregate sum of
sampled values.

Signed-off-by: Gaetan Rivet <[email protected]>
---
 lib/histogram.c | 1 +
 lib/histogram.h | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/lib/histogram.c b/lib/histogram.c
index 85bb3661c3..f066a25905 100644
--- a/lib/histogram.c
+++ b/lib/histogram.c
@@ -91,4 +91,5 @@ histogram_clear(struct histogram *hist)
     for (i = 0; i < HISTOGRAM_N_BINS; i++) {
         hist->bin[i] = 0;
     }
+    hist->sum = 0;
 }
diff --git a/lib/histogram.h b/lib/histogram.h
index 8c2a9ea5c7..c07707cb77 100644
--- a/lib/histogram.h
+++ b/lib/histogram.h
@@ -35,11 +35,13 @@ extern "C" {
 struct histogram {
     uint32_t wall[HISTOGRAM_N_BINS];
     uint64_t bin[HISTOGRAM_N_BINS];
+    uint64_t sum;
 };
 
 static inline void
 histogram_add_sample(struct histogram *hist, uint32_t val)
 {
+    hist->sum += val;
     /* TODO: Can do better with binary search? */
     for (int i = 0; i < HISTOGRAM_N_BINS - 1; i++) {
         if (val <= hist->wall[i]) {
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to