feat: add runtime stats monitor (#1496)

This commit is contained in:
Kevin Wan
2022-02-01 01:34:25 +08:00
committed by GitHub
parent 6c2abe7474
commit 5f9d101bc6
2 changed files with 32 additions and 1 deletions

3
.gitignore vendored
View File

@@ -16,7 +16,8 @@
**/logs
# for test purpose
adhoc
**/adhoc
**/testdata
# gitlab ci
.cache

30
core/prof/runtime.go Normal file
View File

@@ -0,0 +1,30 @@
package prof
import (
"fmt"
"runtime"
"time"
)
const (
defaultInterval = time.Second * 5
mega = 1024 * 1024
)
func DisplayStats(interval ...time.Duration) {
duration := defaultInterval
for _, val := range interval {
duration = val
}
go func() {
ticker := time.NewTicker(duration)
defer ticker.Stop()
for range ticker.C {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Goroutines: %d, Alloc: %vm, TotalAlloc: %vm, Sys: %vm, NumGC: %v\n",
runtime.NumGoroutine(), m.Alloc/mega, m.TotalAlloc/mega, m.Sys/mega, m.NumGC)
}
}()
}