Skip to content

Commit ccbabd9

Browse files
authored
Add pprof support for Relay server (#4203)
1 parent a942e4a commit ccbabd9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

relay/cmd/pprof.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//go:build pprof
2+
// +build pprof
3+
4+
package cmd
5+
6+
import (
7+
"net/http"
8+
_ "net/http/pprof"
9+
"os"
10+
11+
log "github.com/sirupsen/logrus"
12+
)
13+
14+
func init() {
15+
addr := pprofAddr()
16+
go pprof(addr)
17+
}
18+
19+
func pprofAddr() string {
20+
listenAddr := os.Getenv("NB_PPROF_ADDR")
21+
if listenAddr == "" {
22+
return "localhost:6969"
23+
}
24+
25+
return listenAddr
26+
}
27+
28+
func pprof(listenAddr string) {
29+
log.Infof("listening pprof on: %s\n", listenAddr)
30+
if err := http.ListenAndServe(listenAddr, nil); err != nil {
31+
log.Fatalf("Failed to start pprof: %v", err)
32+
}
33+
}

0 commit comments

Comments
 (0)