mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add dumpContainer debug method, keybinding
This commit is contained in:
parent
094be99764
commit
6a4b145b1b
20
debug.go
Normal file
20
debug.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
func inspect(i interface{}) (s string) {
|
||||||
|
val := reflect.ValueOf(i)
|
||||||
|
elem := val.Type().Elem()
|
||||||
|
|
||||||
|
eName := elem.String()
|
||||||
|
for i := 0; i < elem.NumField(); i++ {
|
||||||
|
field := elem.Field(i)
|
||||||
|
fieldVal := reflect.Indirect(val).FieldByName(field.Name)
|
||||||
|
s += fmt.Sprintf("%s.%s = ", eName, field.Name)
|
||||||
|
s += fmt.Sprintf("%v (%s)\n", fieldVal, field.Type)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
13
grid.go
13
grid.go
@ -122,6 +122,15 @@ func (g *Grid) redrawRows() {
|
|||||||
ui.Render(cGrid)
|
ui.Render(cGrid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log current container and widget state
|
||||||
|
func (g *Grid) dumpContainer() {
|
||||||
|
c, _ := g.cSource.Get(g.cursorID)
|
||||||
|
msg := fmt.Sprintf("logging state for container: %s\n", c.ShortID())
|
||||||
|
msg += fmt.Sprintf("id = %s\nname = %s\nstate = %s\n", c.id, c.name, c.state)
|
||||||
|
msg += inspect(&c.metrics)
|
||||||
|
log.Infof(msg)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Grid) ExpandView() {
|
func (g *Grid) ExpandView() {
|
||||||
ui.Clear()
|
ui.Clear()
|
||||||
ui.DefaultEvtStream.ResetHandlers()
|
ui.DefaultEvtStream.ResetHandlers()
|
||||||
@ -142,6 +151,7 @@ func (g *Grid) ExpandView() {
|
|||||||
ui.Loop()
|
ui.Loop()
|
||||||
|
|
||||||
container.widgets = curWidgets
|
container.widgets = curWidgets
|
||||||
|
container.widgets.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
func logEvent(e ui.Event) {
|
func logEvent(e ui.Event) {
|
||||||
@ -178,6 +188,9 @@ func Display(g *Grid) bool {
|
|||||||
config.Toggle("allContainers")
|
config.Toggle("allContainers")
|
||||||
g.redrawRows()
|
g.redrawRows()
|
||||||
})
|
})
|
||||||
|
ui.Handle("/sys/kbd/D", func(ui.Event) {
|
||||||
|
g.dumpContainer()
|
||||||
|
})
|
||||||
ui.Handle("/sys/kbd/f", func(ui.Event) {
|
ui.Handle("/sys/kbd/f", func(ui.Event) {
|
||||||
menu = FilterMenu
|
menu = FilterMenu
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
|
Loading…
Reference in New Issue
Block a user