mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add runtimestats, stack logging to debug
This commit is contained in:
19
debug.go
19
debug.go
@@ -3,11 +3,14 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/container"
|
"github.com/bcicen/ctop/container"
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var mstats = &runtime.MemStats{}
|
||||||
|
|
||||||
func logEvent(e ui.Event) {
|
func logEvent(e ui.Event) {
|
||||||
var s string
|
var s string
|
||||||
s += fmt.Sprintf("Type=%s", quote(e.Type))
|
s += fmt.Sprintf("Type=%s", quote(e.Type))
|
||||||
@@ -19,6 +22,22 @@ func logEvent(e ui.Event) {
|
|||||||
log.Debugf("new event: %s", s)
|
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
|
// log container, metrics, and widget state
|
||||||
func dumpContainer(c *container.Container) {
|
func dumpContainer(c *container.Container) {
|
||||||
msg := fmt.Sprintf("logging state for container: %s\n", c.Id)
|
msg := fmt.Sprintf("logging state for container: %s\n", c.Id)
|
||||||
|
|||||||
Reference in New Issue
Block a user