Commit 7378a986 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

zdebug

parent e53f6d70
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))
}
}()
}
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
_ "git.barsukov.pro/barsukov/zgo/zcache" _ "git.barsukov.pro/barsukov/zgo/zcache"
_ "git.barsukov.pro/barsukov/zgo/zcron" _ "git.barsukov.pro/barsukov/zgo/zcron"
_ "git.barsukov.pro/barsukov/zgo/zdb" _ "git.barsukov.pro/barsukov/zgo/zdb"
_ "git.barsukov.pro/barsukov/zgo/zdebug"
_ "git.barsukov.pro/barsukov/zgo/zgin" _ "git.barsukov.pro/barsukov/zgo/zgin"
_ "git.barsukov.pro/barsukov/zgo/zjson" _ "git.barsukov.pro/barsukov/zgo/zjson"
_ "git.barsukov.pro/barsukov/zgo/zq" _ "git.barsukov.pro/barsukov/zgo/zq"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment