diff --git a/cmd/tetra/debug/progs.go b/cmd/tetra/debug/progs.go index 33a5d3a5cd9..d56fc787503 100644 --- a/cmd/tetra/debug/progs.go +++ b/cmd/tetra/debug/progs.go @@ -26,6 +26,7 @@ import ( "github.com/cilium/ebpf/link" "github.com/spf13/cobra" "golang.org/x/sys/unix" + "golang.org/x/term" ) type prog struct { @@ -233,13 +234,31 @@ func round(state map[uint32]*prog) error { writer := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', tabwriter.AlignRight) fmt.Fprintln(writer, "Ovh(%)\tId\tCnt\tTime\tName\tPin") + cnt := 0 + lines := 0 + + if !cfg.noclr && !cfg.once { + // We have 3 header lines, so terminal smaller than that is too + // small to print anything meaningful + _, lines, _ = term.GetSize(0) + if lines < 4 { + return nil + } + lines = lines - 4 + } + for _, ovh := range overheads { p := ovh.p - fmt.Fprintf(writer, "%6.2f\t%d\t%d\t%d\t%s\t%s\n", + fmt.Fprintf(writer, "%6.2f\t%d\t%d\t%d\t%s\t%s", ovh.pct, p.id, ovh.cnt, ovh.time, p.name, p.pin) + + if lines != 0 && cnt == lines { + break + } + cnt++ + fmt.Fprintf(writer, "\n") } - fmt.Fprintln(writer) writer.Flush() // Remove stale programs from state map diff --git a/go.mod b/go.mod index 909cf6b4cb6..75875b4526a 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,7 @@ require ( go.uber.org/multierr v1.11.0 golang.org/x/sync v0.10.0 golang.org/x/sys v0.28.0 + golang.org/x/term v0.27.0 golang.org/x/time v0.8.0 google.golang.org/grpc v1.69.0 google.golang.org/protobuf v1.35.2 @@ -155,7 +156,6 @@ require ( golang.org/x/mod v0.22.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect - golang.org/x/term v0.27.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/tools v0.27.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect