Skip to content

Commit 077f875

Browse files
committed
fix: GUM_DEBUG and pprof
Used this in #827 and found it quite useful. Should we ship this to help both we and our users to see mem/cpu usage etc?
1 parent e7c916c commit 077f875

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"net/http"
67
"os"
78
"runtime/debug"
89

10+
_ "net/http/pprof"
11+
912
"github.com/alecthomas/kong"
1013
tea "github.com/charmbracelet/bubbletea"
1114
"github.com/charmbracelet/gum/internal/exit"
1215
"github.com/charmbracelet/lipgloss"
16+
"github.com/charmbracelet/log"
1317
"github.com/muesli/termenv"
1418
)
1519

@@ -30,6 +34,15 @@ var bubbleGumPink = lipgloss.NewStyle().Foreground(lipgloss.Color("212"))
3034
func main() {
3135
lipgloss.SetColorProfile(termenv.NewOutput(os.Stderr).Profile)
3236

37+
if os.Getenv("GUM_DEBUG") != "" {
38+
go func() {
39+
log.Info("serving pprof at localhost:6060")
40+
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
41+
log.Error("failed to pprof listen", "err", err)
42+
}
43+
}()
44+
}
45+
3346
if Version == "" {
3447
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
3548
Version = info.Main.Version

0 commit comments

Comments
 (0)