From 9ccc0dd9880349b1281acb8e62e5b571c28024ed Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Fri, 6 May 2016 14:15:49 -0700 Subject: [PATCH] Add histogram Merge function --- benchmark/stats/histogram.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/benchmark/stats/histogram.go b/benchmark/stats/histogram.go index c6ff6080..a77b51da 100644 --- a/benchmark/stats/histogram.go +++ b/benchmark/stats/histogram.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "log" "math" "strconv" "strings" @@ -174,3 +175,21 @@ func (h *Histogram) findBucket(value int64) (int, error) { } return b, nil } + +func (h *Histogram) Merge(h2 *Histogram) { + if len(h.Buckets) != len(h2.Buckets) { + log.Fatalf("failed to merge histograms, inequivalent buckets length") + } + h.Count += h2.Count + h.Sum += h2.Sum + h.SumOfSquares += h2.SumOfSquares + if h2.Min < h.Min { + h.Min = h2.Min + } + if h2.Max > h.Max { + h.Max = h2.Max + } + for i, b := range h2.Buckets { + h.Buckets[i].Count += b.Count + } +}