优化代码

This commit is contained in:
GoEdgeLab
2022-03-20 10:48:11 +08:00
parent b6a82a27a8
commit 5aa0ede8a9
2 changed files with 51 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ import (
"time"
)
func StartMemoryStats(t *testing.T) {
func StartMemoryStatsGC(t *testing.T) {
var ticker = time.NewTicker(1 * time.Second)
go func() {
var stat = &runtime.MemStats{}
@@ -31,3 +31,21 @@ func StartMemoryStats(t *testing.T) {
}
}()
}
func StartMemoryStats(t *testing.T) {
var ticker = time.NewTicker(1 * time.Second)
go func() {
var stat = &runtime.MemStats{}
var lastHeapInUse uint64
for range ticker.C {
runtime.ReadMemStats(stat)
if stat.HeapInuse == lastHeapInUse {
return
}
lastHeapInUse = stat.HeapInuse
t.Log(timeutil.Format("H:i:s"), "HeapInuse:", fmt.Sprintf("%.2fM", float64(stat.HeapInuse)/1024/1024), "NumGC:", stat.NumGC)
}
}()
}