(t *testing.T)
| 38 | } |
| 39 | |
| 40 | func (s) TestProfiling(t *testing.T) { |
| 41 | cb, err := buffer.NewCircularBuffer(128) |
| 42 | if err != nil { |
| 43 | t.Fatalf("error creating circular buffer: %v", err) |
| 44 | } |
| 45 | |
| 46 | stat := NewStat("foo") |
| 47 | cb.Push(stat) |
| 48 | bar := func(n int) { |
| 49 | if n%2 == 0 { |
| 50 | defer stat.NewTimer(strconv.Itoa(n)).Egress() |
| 51 | } else { |
| 52 | timer := NewTimer(strconv.Itoa(n)) |
| 53 | stat.AppendTimer(timer) |
| 54 | defer timer.Egress() |
| 55 | } |
| 56 | time.Sleep(1 * time.Microsecond) |
| 57 | } |
| 58 | |
| 59 | numTimers := int(8 * defaultStatAllocatedTimers) |
| 60 | for i := 0; i < numTimers; i++ { |
| 61 | bar(i) |
| 62 | } |
| 63 | |
| 64 | results := cb.Drain() |
| 65 | if len(results) != 1 { |
| 66 | t.Fatalf("len(results) = %d; want 1", len(results)) |
| 67 | } |
| 68 | |
| 69 | statReturned := results[0].(*Stat) |
| 70 | if stat.Tags != "foo" { |
| 71 | t.Fatalf("stat.Tags = %s; want foo", stat.Tags) |
| 72 | } |
| 73 | |
| 74 | if len(stat.Timers) != numTimers { |
| 75 | t.Fatalf("len(stat.Timers) = %d; want %d", len(stat.Timers), numTimers) |
| 76 | } |
| 77 | |
| 78 | lastIdx := 0 |
| 79 | for i, timer := range statReturned.Timers { |
| 80 | // Check that they're in the order of append. |
| 81 | if n, err := strconv.Atoi(timer.Tags); err != nil && n != lastIdx { |
| 82 | t.Fatalf("stat.Timers[%d].Tags = %s; wanted %d", i, timer.Tags, lastIdx) |
| 83 | } |
| 84 | |
| 85 | // Check that the timestamps are consistent. |
| 86 | if diff := timer.End.Sub(timer.Begin); diff.Nanoseconds() < 1000 { |
| 87 | t.Fatalf("stat.Timers[%d].End - stat.Timers[%d].Begin = %v; want >= 1000ns", i, i, diff) |
| 88 | } |
| 89 | |
| 90 | lastIdx++ |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | func (s) TestProfilingRace(t *testing.T) { |
| 95 | stat := NewStat("foo") |
nothing calls this directly
no test coverage detected