测试用内存统计增加回调函数

This commit is contained in:
GoEdgeLab
2023-10-05 09:15:17 +08:00
parent 7fb050fc80
commit 4cebb4d876

View File

@@ -32,7 +32,7 @@ func StartMemoryStatsGC(t *testing.T) {
}()
}
func StartMemoryStats(t *testing.T) {
func StartMemoryStats(t *testing.T, callbacks ...func()) {
var ticker = time.NewTicker(1 * time.Second)
go func() {
var stat = &runtime.MemStats{}
@@ -46,6 +46,12 @@ func StartMemoryStats(t *testing.T) {
lastHeapInUse = stat.HeapInuse
t.Log(timeutil.Format("H:i:s"), "HeapInuse:", fmt.Sprintf("%.2fM", float64(stat.HeapInuse)/1024/1024), "NumGC:", stat.NumGC)
if len(callbacks) > 0 {
for _, callback := range callbacks {
callback()
}
}
}
}()
}