MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / StartMemoryStatsGC

Function StartMemoryStatsGC

internal/utils/testutils/memory.go:13–33  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func StartMemoryStatsGC(t *testing.T) {
14 var ticker = time.NewTicker(1 * time.Second)
15 go func() {
16 var stat = &runtime.MemStats{}
17 var lastHeapInUse uint64
18
19 for range ticker.C {
20 runtime.ReadMemStats(stat)
21 if stat.HeapInuse == lastHeapInUse {
22 return
23 }
24 lastHeapInUse = stat.HeapInuse
25
26 var before = time.Now()
27 runtime.GC()
28 var cost = time.Since(before).Seconds()
29
30 t.Log(timeutil.Format("H:i:s"), "HeapInuse:", fmt.Sprintf("%.2fM", float64(stat.HeapInuse)/1024/1024), "NumGC:", stat.NumGC, "Cost:", fmt.Sprintf("%.4f", cost*1000), "ms")
31 }
32 }()
33}
34
35func StartMemoryStats(t *testing.T, callbacks ...func()) {
36 var ticker = time.NewTicker(1 * time.Second)

Callers

nothing calls this directly

Calls 3

LogMethod · 0.80
GCMethod · 0.65
FormatMethod · 0.65

Tested by

no test coverage detected