2018-02-23 09:56:08 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2022-05-19 04:48:07 +00:00
|
|
|
|
2022-12-03 05:23:01 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
2018-02-23 09:56:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRuntimeMemStatsBlocking(t *testing.T) {
|
|
|
|
if g := runtime.GOMAXPROCS(0); g < 2 {
|
|
|
|
t.Skipf("skipping TestRuntimeMemStatsBlocking with GOMAXPROCS=%d\n", g)
|
|
|
|
}
|
|
|
|
ch := make(chan int)
|
|
|
|
go testRuntimeMemStatsBlocking(ch)
|
|
|
|
var memStats runtime.MemStats
|
|
|
|
t0 := time.Now()
|
2022-12-03 05:23:01 +00:00
|
|
|
dbg.ReadMemStats(&memStats)
|
2018-02-23 09:56:08 +00:00
|
|
|
t1 := time.Now()
|
|
|
|
t.Log("i++ during runtime.ReadMemStats:", <-ch)
|
|
|
|
go testRuntimeMemStatsBlocking(ch)
|
|
|
|
d := t1.Sub(t0)
|
|
|
|
t.Log(d)
|
|
|
|
time.Sleep(d)
|
|
|
|
t.Log("i++ during time.Sleep:", <-ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRuntimeMemStatsBlocking(ch chan int) {
|
|
|
|
i := 0
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case ch <- i:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|