From 29d24a112fbccb49b401f542faf070835c0118dc Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 13 Jul 2026 14:04:51 +0200 Subject: [PATCH] add --debug-goroutines --- cmd/root.go | 6 ++++++ pkg/cfg/config.go | 13 +++++++------ pkg/printer/table.go | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index f0ca434..295ee0a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -119,6 +119,12 @@ func Main() int { Usage: "enable HTTP debugging", Destination: &conf.DebugHTTP, }, + &cli.BoolFlag{ + Name: "debug-goroutines", + Value: false, + Usage: "enable goroutine debugging", + Destination: &conf.DebugGoRoutines, + }, &cli.BoolFlag{ Name: "align-ints", Aliases: []string{"I"}, diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index 0f34827..93855e6 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -89,12 +89,13 @@ type Config struct { Force bool // ccr follower renew: -f - DebugHTTP bool // root: --debug-http - Separator string // role diff: -s - NotDeployed bool // role diff: -n - Undefined bool // role diff: -u - Diff bool // role diff: -D - Hidden bool // ds ls: -H + DebugHTTP bool // root: --debug-http + DebugGoRoutines bool // root: --debug-goroutines + Separator string // role diff: -s + NotDeployed bool // role diff: -n + Undefined bool // role diff: -u + Diff bool // role diff: -D + Hidden bool // ds ls: -H // rollover MaxAge string diff --git a/pkg/printer/table.go b/pkg/printer/table.go index 4be278e..bcb5826 100644 --- a/pkg/printer/table.go +++ b/pkg/printer/table.go @@ -35,15 +35,20 @@ type Table struct { RawHeaders []string Entries [][]any - rows [][]string // representation used for printing - processed bool - lenHeaders []int - alignInts bool - maxwidth int + rows [][]string // representation used for printing + processed bool + lenHeaders []int + alignInts bool + maxwidth int + debugGoRoutines bool } func NewTable(conf *cfg.Config, columns, rows int) *Table { - table := new(Table{Mode: conf.Output, maxwidth: cfg.GetTermWidth()}) + table := new(Table{ + Mode: conf.Output, + maxwidth: cfg.GetTermWidth(), + debugGoRoutines: conf.DebugGoRoutines, + }) table.Headers = make([]string, columns) table.RawHeaders = make([]string, columns) @@ -55,7 +60,11 @@ func NewTable(conf *cfg.Config, columns, rows int) *Table { } func NewTableEmpty(conf *cfg.Config) *Table { - table := new(Table{Mode: conf.Output, maxwidth: cfg.GetTermWidth()}) + table := new(Table{ + Mode: conf.Output, + maxwidth: cfg.GetTermWidth(), + debugGoRoutines: conf.DebugGoRoutines, + }) table.alignInts = conf.AlignInts return table @@ -75,16 +84,24 @@ func (table *Table) WithHeaders(headers ...string) *Table { } func (table *Table) Print() error { + var err error + switch table.Mode { case "json": - return table.PrintJSON() + err = table.PrintJSON() case "yaml": - return table.PrintYAML() + err = table.PrintYAML() case "csv": - return table.PrintCSV() + err = table.PrintCSV() default: - return table.PrintTSV() + err = table.PrintTSV() } + + if table.debugGoRoutines { + printGoRoutineMetrics() + } + + return err } var (