Parcourir la source

Expose a copy of a Histogram's Sample.

This will allow internally consistent reporting in the near future.
Richard Crowley il y a 12 ans
Parent
commit
1fe60a51a2
1 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 10 1
      histogram.go

+ 10 - 1
histogram.go

@@ -19,6 +19,7 @@ type Histogram interface {
 	Min() int64
 	Percentile(float64) float64
 	Percentiles([]float64) []float64
+	Sample() Sample
 	StdDev() float64
 	Update(int64)
 	Variance() float64
@@ -83,6 +84,9 @@ func (NilHistogram) Percentiles(ps []float64) []float64 {
 	return make([]float64, len(ps))
 }
 
+// No-op.
+func (NilHistogram) Sample() Sample { return NilSample{} }
+
 // No-op.
 func (NilHistogram) StdDev() float64 { return 0.0 }
 
@@ -110,7 +114,7 @@ func (h *StandardHistogram) Clear() {
 	h.min = math.MaxInt64
 	h.s.Clear()
 	h.sum = 0
-	h.variance = [...]float64{-1.0, 0.0}
+	h.variance = [2]float64{-1.0, 0.0}
 }
 
 // Return the count of inputs since the histogram was last cleared.
@@ -178,6 +182,11 @@ func (h *StandardHistogram) Percentiles(ps []float64) []float64 {
 	return scores
 }
 
+// Sample returns a copy of the Sample underlying the Histogram.
+func (h *StandardHistogram) Sample() Sample {
+	return h.s.Dup()
+}
+
 // Return the standard deviation of all values seen since the histogram was
 // last cleared.
 func (h *StandardHistogram) StdDev() float64 {