erigon-pulse/common/debug/memstats.go
2022-12-03 12:23:01 +07:00

24 lines
607 B
Go

package debug
import (
"fmt"
"runtime"
"github.com/ledgerwatch/erigon-lib/common/dbg"
)
func PrintMemStats(short bool) {
var m runtime.MemStats
dbg.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
if short {
fmt.Printf("HeapInuse: %vMb\n", ByteToMb(m.HeapInuse))
} else {
fmt.Printf("HeapInuse: %vMb, Alloc: %vMb, TotalAlloc: %vMb, Sys: %vMb, NumGC: %v, PauseNs: %d\n", ByteToMb(m.HeapInuse), ByteToMb(m.Alloc), ByteToMb(m.TotalAlloc), ByteToMb(m.Sys), m.NumGC, m.PauseNs[(m.NumGC+255)%256])
}
}
func ByteToMb(b uint64) uint64 {
return b / 1024 / 1024
}