aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/histogram_test.go
diff options
context:
space:
mode:
authorCarlos Amedee <carlos@golang.org>2022-03-07 12:32:05 -0500
committerCarlos Amedee <carlos@golang.org>2022-03-07 12:32:05 -0500
commit649671b08fbd49bcf65578b18d188d55779e6eca (patch)
tree14c9e6c56ddedcb47ae9d44668144f2367638afa /src/runtime/histogram_test.go
parent7e420ce576031db5c4562010254f9c8c4c5eb03e (diff)
parent7de0c90a1771146bcba5663fb257c52acffe6161 (diff)
downloadgo-649671b08fbd49bcf65578b18d188d55779e6eca.tar.gz
go-649671b08fbd49bcf65578b18d188d55779e6eca.zip
[dev.boringcrypto.go1.16] all: merge go1.16.15 into dev.boringcrypto.go1.16dev.boringcrypto.go1.16
Change-Id: I574f47761ceb4e224a2a31b5096e27126f171238
Diffstat (limited to 'src/runtime/histogram_test.go')
-rw-r--r--src/runtime/histogram_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/runtime/histogram_test.go b/src/runtime/histogram_test.go
index dbc64fa5592..b12b65a41e3 100644
--- a/src/runtime/histogram_test.go
+++ b/src/runtime/histogram_test.go
@@ -68,3 +68,43 @@ func TestTimeHistogram(t *testing.T) {
dummyTimeHistogram = TimeHistogram{}
}
+
+func TestTimeHistogramMetricsBuckets(t *testing.T) {
+ buckets := TimeHistogramMetricsBuckets()
+
+ nonInfBucketsLen := TimeHistNumSubBuckets * TimeHistNumSuperBuckets
+ expBucketsLen := nonInfBucketsLen + 2 // Count -Inf and +Inf.
+ if len(buckets) != expBucketsLen {
+ t.Fatalf("unexpected length of buckets: got %d, want %d", len(buckets), expBucketsLen)
+ }
+ // Check the first non-Inf 2*TimeHistNumSubBuckets buckets in order, skipping the
+ // first bucket which should be -Inf (checked later).
+ //
+ // Because of the way this scheme works, the bottom TimeHistNumSubBuckets
+ // buckets are fully populated, and then the next TimeHistNumSubBuckets
+ // have the TimeHistSubBucketBits'th bit set, while the bottom are once
+ // again fully populated.
+ for i := 1; i <= 2*TimeHistNumSubBuckets+1; i++ {
+ if got, want := buckets[i], float64(i-1)/1e9; got != want {
+ t.Errorf("expected bucket %d to have value %e, got %e", i, want, got)
+ }
+ }
+ // Check some values.
+ idxToBucket := map[int]float64{
+ 0: math.Inf(-1),
+ 33: float64(0x10<<1) / 1e9,
+ 34: float64(0x11<<1) / 1e9,
+ 49: float64(0x10<<2) / 1e9,
+ 58: float64(0x19<<2) / 1e9,
+ 65: float64(0x10<<3) / 1e9,
+ 513: float64(0x10<<31) / 1e9,
+ 519: float64(0x16<<31) / 1e9,
+ expBucketsLen - 2: float64(0x1f<<43) / 1e9,
+ expBucketsLen - 1: math.Inf(1),
+ }
+ for idx, bucket := range idxToBucket {
+ if got, want := buckets[idx], bucket; got != want {
+ t.Errorf("expected bucket %d to have value %e, got %e", idx, want, got)
+ }
+ }
+}