wit-debian-gui/window-debug-golang.go

87 lines
2.4 KiB
Go

package main
import (
"os"
"runtime"
"runtime/debug"
"runtime/pprof"
"go.wit.com/log"
"go.wit.com/lib/gadgets"
)
var langWin *gadgets.BasicWindow
func golangDebug() {
if langWin != nil {
langWin.Toggle()
return
}
langWin = gadgets.NewBasicWindow(myGui, "golangDebug")
/////////////////////////////// Column DEBUG GOLANG //////////////////////
gNode := langWin.Box().NewGroup("golang")
gNode.NewButton("runtime.Stack() dump", func() {
log.Println("\tSTART")
buf := make([]byte, 1<<16)
runtime.Stack(buf, true)
log.Printf("%s", buf)
log.Println("\tEND")
})
gNode.NewButton("dumpModuleInfo", func() {
log.Println("\tSTART")
dumpModuleInfo()
log.Println("\tEND")
})
gNode.NewButton("debug.PrintStack", func() {
log.Println("\tSTART")
debug.PrintStack()
log.Println("\tEND")
})
gNode.NewButton("pprof.Lookup goroutine", func() {
log.Println("\tSTART")
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
log.Println("\tEND")
})
gNode.NewButton("pprof.Lookup", func() {
log.Println("\tSTART")
pprof.Lookup("heap").WriteTo(os.Stdout, 1)
log.Println("\tEND")
})
gNode.NewButton("pprof.Lookup block", func() {
log.Println("\tSTART")
pprof.Lookup("block").WriteTo(os.Stdout, 1)
log.Println("\tEND")
})
gNode.NewButton("pprof.Lookup threadcreate", func() {
log.Println("\tSTART")
pprof.Lookup("threadcreate").WriteTo(os.Stdout, 1)
log.Println("\tEND")
})
gNode.NewButton("runtime.ReadMemStats", func() {
var s runtime.MemStats
runtime.ReadMemStats(&s)
log.Printf("alloc: %v bytes\n", s.Alloc)
log.Printf("total-alloc: %v bytes\n", s.TotalAlloc)
log.Printf("sys: %v bytes\n", s.Sys)
log.Printf("lookups: %v\n", s.Lookups)
log.Printf("mallocs: %v\n", s.Mallocs)
log.Printf("frees: %v\n", s.Frees)
log.Printf("heap-alloc: %v bytes\n", s.HeapAlloc)
log.Printf("heap-sys: %v bytes\n", s.HeapSys)
log.Printf("heap-idle: %v bytes\n", s.HeapIdle)
log.Printf("heap-in-use: %v bytes\n", s.HeapInuse)
log.Printf("heap-released: %v bytes\n", s.HeapReleased)
log.Printf("heap-objects: %v\n", s.HeapObjects)
log.Printf("stack-in-use: %v bytes\n", s.StackInuse)
log.Printf("stack-sys: %v bytes\n", s.StackSys)
log.Printf("next-gc: when heap-alloc >= %v bytes\n", s.NextGC)
log.Printf("last-gc: %v ns\n", s.LastGC)
log.Printf("gc-pause: %v ns\n", s.PauseTotalNs)
log.Printf("num-gc: %v\n", s.NumGC)
log.Printf("enable-gc: %v\n", s.EnableGC)
log.Printf("debug-gc: %v\n", s.DebugGC)
})
}