From 452a9f1927a1403770f54e11e4bac5c39d4052f7 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 28 Oct 2025 14:06:34 -0700 Subject: [PATCH 1/2] add env var to start pprof server --- cmd/server/main-server.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index 9a1314012c..1438c71bed 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "os" + "strconv" "runtime" "sync" @@ -40,6 +41,9 @@ import ( "github.com/wavetermdev/waveterm/pkg/wshutil" "github.com/wavetermdev/waveterm/pkg/wslconn" "github.com/wavetermdev/waveterm/pkg/wstore" + + "net/http" + _ "net/http/pprof" ) // these are set at build time @@ -315,13 +319,41 @@ func clearTempFiles() error { return nil } +func maybeStartPprofServer() error { + pprofPortStr := os.Getenv("WAVETERM_PPROFPORT") + if pprofPortStr == "" { + return nil + } + pprofPort, err := strconv.Atoi(pprofPortStr) + if err != nil { + return fmt.Errorf("invalid WAVETERM_PPROFPORT value '%s': %v", pprofPortStr, err) + } + if pprofPort < 1 || pprofPort > 65535 { + return fmt.Errorf("WAVETERM_PPROFPORT must be between 1 and 65535, got %d", pprofPort) + } + go func() { + addr := fmt.Sprintf("localhost:%d", pprofPort) + log.Printf("starting pprof server on %s\n", addr) + if err := http.ListenAndServe(addr, nil); err != nil { + log.Printf("[error] pprof server failed: %v\n", err) + } + }() + return nil +} + func main() { + err := maybeStartPprofServer() + if err != nil { + log.Printf("[error] %v\n", err) + return + } + log.SetFlags(log.LstdFlags | log.Lmicroseconds) log.SetPrefix("[wavesrv] ") wavebase.WaveVersion = WaveVersion wavebase.BuildTime = BuildTime - err := grabAndRemoveEnvVars() + err = grabAndRemoveEnvVars() if err != nil { log.Printf("[error] %v\n", err) return From 26e24a97b769c0b9a73b53980d5531fc58af5d62 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Tue, 28 Oct 2025 14:23:20 -0700 Subject: [PATCH 2/2] Unset WAVETERM_PPROFPORT after usage --- cmd/server/main-server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index 1438c71bed..bc6abae479 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -324,6 +324,7 @@ func maybeStartPprofServer() error { if pprofPortStr == "" { return nil } + defer os.Unsetenv("WAVETERM_PPROFPORT") pprofPort, err := strconv.Atoi(pprofPortStr) if err != nil { return fmt.Errorf("invalid WAVETERM_PPROFPORT value '%s': %v", pprofPortStr, err)