From 25a3fcf731e61e252f27735689bd1c2779225aac Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Wed, 28 Jun 2017 12:12:24 +0000 Subject: [PATCH] add runtimestats, stack logging to debug --- debug.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/debug.go b/debug.go index bbcab06..683c8e8 100644 --- a/debug.go +++ b/debug.go @@ -3,11 +3,14 @@ package main import ( "fmt" "reflect" + "runtime" "github.com/bcicen/ctop/container" ui "github.com/gizak/termui" ) +var mstats = &runtime.MemStats{} + func logEvent(e ui.Event) { var s string s += fmt.Sprintf("Type=%s", quote(e.Type)) @@ -19,6 +22,22 @@ func logEvent(e ui.Event) { log.Debugf("new event: %s", s) } +func runtimeStats() { + var msg string + msg += fmt.Sprintf("cgo calls=%v", runtime.NumCgoCall()) + msg += fmt.Sprintf(" routines=%v", runtime.NumGoroutine()) + runtime.ReadMemStats(mstats) + msg += fmt.Sprintf(" numgc=%v", mstats.NumGC) + msg += fmt.Sprintf(" alloc=%v", mstats.Alloc) + log.Debugf("runtime: %v", msg) +} + +func runtimeStack() { + buf := make([]byte, 32768) + buf = buf[:runtime.Stack(buf, true)] + log.Infof(fmt.Sprintf("stack:\n%v", string(buf))) +} + // log container, metrics, and widget state func dumpContainer(c *container.Container) { msg := fmt.Sprintf("logging state for container: %s\n", c.Id)