Source file
src/runtime/histogram_test.go
Documentation: runtime
1
2
3
4
5 package runtime_test
6
7 import (
8 "math"
9 . "runtime"
10 "testing"
11 )
12
13 var dummyTimeHistogram TimeHistogram
14
15 func TestTimeHistogram(t *testing.T) {
16
17
18
19
20 h := &dummyTimeHistogram
21
22
23 for i := 0; i < TimeHistNumSuperBuckets; i++ {
24 var base int64
25 if i > 0 {
26 base = int64(1) << (i + TimeHistSubBucketBits - 1)
27 }
28 for j := 0; j < TimeHistNumSubBuckets; j++ {
29 v := int64(j)
30 if i > 0 {
31 v <<= i - 1
32 }
33 h.Record(base + v)
34 }
35 }
36
37 h.Record(int64(-1))
38
39
40
41 for i := uint(0); i < TimeHistNumSuperBuckets; i++ {
42 for j := uint(0); j < TimeHistNumSubBuckets; j++ {
43 c, ok := h.Count(i, j)
44 if !ok {
45 t.Errorf("hit underflow bucket unexpectedly: (%d, %d)", i, j)
46 } else if c != 1 {
47 t.Errorf("bucket (%d, %d) has count that is not 1: %d", i, j, c)
48 }
49 }
50 }
51 c, ok := h.Count(TimeHistNumSuperBuckets, 0)
52 if ok {
53 t.Errorf("expected to hit underflow bucket: (%d, %d)", TimeHistNumSuperBuckets, 0)
54 }
55 if c != 1 {
56 t.Errorf("underflow bucket has count that is not 1: %d", c)
57 }
58
59
60
61 h.Record(math.MaxInt64)
62 c, ok = h.Count(TimeHistNumSuperBuckets-1, TimeHistNumSubBuckets-1)
63 if !ok {
64 t.Error("hit underflow bucket in highest bucket unexpectedly")
65 } else if c != 2 {
66 t.Errorf("highest has count that is not 2: %d", c)
67 }
68
69 dummyTimeHistogram = TimeHistogram{}
70 }
71
View as plain text