debug_test.go 729 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. //runtime.Gosched()
  20. var gcStats debug.GCStats
  21. t0 := time.Now()
  22. debug.ReadGCStats(&gcStats)
  23. t1 := time.Now()
  24. t.Log("i++ during debug.ReadGCStats:", <-ch)
  25. go testDebugGCStatsBlocking(ch)
  26. time.Sleep(t1.Sub(t0))
  27. t.Log("i++ during time.Sleep:", <-ch)
  28. }
  29. func testDebugGCStatsBlocking(ch chan int) {
  30. i := 0
  31. for {
  32. select {
  33. case ch <- i:
  34. return
  35. default:
  36. i++
  37. }
  38. }
  39. }