Histogram: allow for samples > 1 << 63 (#3650)

This commit is contained in:
Rafael Weinstein
2017-08-30 11:20:20 -07:00
committed by GitHub
parent 864f1a8fae
commit 86dfd49efc
2 changed files with 11 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ func identToString(v uint64) string {
return fmt.Sprintf("%d", v)
}
const bucketCount = 63
const bucketCount = 64
// Sample adds a uint64 data point to the histogram
func (h *Histogram) Sample(v uint64) {
@@ -76,8 +76,8 @@ func (h Histogram) bucketVal(bucket int) uint64 {
return 1 << (uint64(bucket))
}
// Sum return the sum of sampled values, given that each sample is clamped to
// the mid-point value of the bucket in which it is recorded.
// Sum return the sum of sampled values, note that Sum can be overflowed without
// overflowing the histogram buckets.
func (h Histogram) Sum() uint64 {
return h.sum
}

View File

@@ -49,6 +49,14 @@ func TestHistogramBasic(t *testing.T) {
assert.Equal(uint64(144), h.Mean())
}
func TestHistogramLarge(t *testing.T) {
assert := assert.New(t)
h := Histogram{}
h.Sample(0xfffffffffffffe30)
assert.Equal(uint64(1), h.Samples())
assert.Equal(uint64(0xfffffffffffffe30), h.Sum())
}
func TestHistogramAdd(t *testing.T) {
assert := assert.New(t)