package zdebug import ( "fmt" "git.barsukov.pro/barsukov/zgo/zjson" "runtime" "time" ) type Monitor struct { Alloc, TotalAlloc, Sys, LiveObjects uint64 NumGC uint32 NumGoroutine int } func NewMonitor(secs int) { go func() { var m Monitor var rtm runtime.MemStats var interval = time.Duration(secs) * time.Second for { <-time.After(interval) runtime.ReadMemStats(&rtm) m.NumGoroutine = runtime.NumGoroutine() m.Alloc = rtm.Alloc / 1e6 m.TotalAlloc = rtm.TotalAlloc / 1e6 m.Sys = rtm.Sys / 1e6 m.LiveObjects = rtm.Mallocs - rtm.Frees m.NumGC = rtm.NumGC fmt.Println(zjson.MustString(m)) } }() }