add back in missing DebugInfo
This commit is contained in:
parent
b7a4bc2a18
commit
afed5c3703
|
@ -20,6 +20,7 @@ import (
|
|||
"os/user"
|
||||
path "path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
mrand "math/rand"
|
||||
|
@ -510,6 +511,48 @@ func UpdateSettings(settingsJson string) {
|
|||
{{EXPERIMENT_UPDATESETTINGS}}
|
||||
}
|
||||
|
||||
//export c_GetDebugInfo
|
||||
func c_GetDebugInfo() *C.char {
|
||||
return C.CString(GetDebugInfo())
|
||||
}
|
||||
|
||||
type DebugInfo struct {
|
||||
BuildVersion string
|
||||
BuildDate string
|
||||
HeapAllocated float64
|
||||
HeapInUse float64
|
||||
HeapReleased float64
|
||||
HeapObjects uint64
|
||||
NumThreads uint64
|
||||
SystemMemory float64
|
||||
}
|
||||
|
||||
func GetDebugInfo() string {
|
||||
|
||||
var memstats runtime.MemStats
|
||||
runtime.ReadMemStats(&memstats)
|
||||
|
||||
const MegaByte = 1024.0 * 1024.0
|
||||
|
||||
debugInfo := new(DebugInfo)
|
||||
debugInfo.BuildVersion = buildVer
|
||||
debugInfo.BuildDate = buildDate
|
||||
debugInfo.HeapAllocated = float64(memstats.HeapAlloc) / MegaByte
|
||||
debugInfo.HeapObjects = memstats.HeapObjects
|
||||
debugInfo.NumThreads = uint64(runtime.NumGoroutine())
|
||||
debugInfo.HeapReleased = float64(memstats.HeapReleased) / MegaByte
|
||||
debugInfo.HeapInUse = float64(memstats.HeapInuse) / MegaByte
|
||||
debugInfo.SystemMemory = float64(memstats.Sys) / MegaByte
|
||||
|
||||
if os.Getenv("CWTCH_PROFILE") == "1" {
|
||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||
f, _ := os.Create("mem.prof")
|
||||
pprof.WriteHeapProfile(f)
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(debugInfo)
|
||||
return string(data)
|
||||
}
|
||||
|
||||
{{BINDINGS}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue