add back in missing DebugInfo
continuous-integration/drone/pr Build was killed Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dan Ballard 2023-04-13 12:38:54 -05:00
parent b7a4bc2a18
commit afed5c3703
1 changed files with 43 additions and 0 deletions

View File

@ -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}}