debug_test.go 726 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package metrics
  2. import (
  3. // "runtime"
  4. "runtime/debug"
  5. "testing"
  6. "time"
  7. )
  8. func BenchmarkDebugGCStats(b *testing.B) {
  9. r := NewRegistry()
  10. RegisterDebugGCStats(r)
  11. b.ResetTimer()
  12. for i := 0; i < b.N; i++ {
  13. CaptureDebugGCStatsOnce(r)
  14. }
  15. }
  16. func TestDebugGCStatsBlocking(t *testing.T) {
  17. ch := make(chan int)
  18. go testDebugGCStatsBlocking(ch)
  19. var gcStats debug.GCStats
  20. t0 := time.Now()
  21. debug.ReadGCStats(&gcStats)
  22. t1 := time.Now()
  23. t.Log("i++ during debug.ReadGCStats:", <-ch)
  24. go testDebugGCStatsBlocking(ch)
  25. d := t1.Sub(t0)
  26. t.Log(d)
  27. time.Sleep(d)
  28. t.Log("i++ during time.Sleep:", <-ch)
  29. }
  30. func testDebugGCStatsBlocking(ch chan int) {
  31. i := 0
  32. for {
  33. select {
  34. case ch <- i:
  35. return
  36. default:
  37. i++
  38. }
  39. }
  40. }