Skip to content

Commit 8aec225

Browse files
committed
feat(api): add pprof endpoint
This will help debug running go2rtc instances. By default the pprof endpoint is off. It can be enabled via the api.pprof setting.
1 parent 7b77e41 commit 8aec225

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/api/api.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net"
88
"net/http"
9+
"net/http/pprof"
910
"os"
1011
"strconv"
1112
"strings"
@@ -30,6 +31,7 @@ func Init() {
3031
TLSCert string `yaml:"tls_cert"`
3132
TLSKey string `yaml:"tls_key"`
3233
UnixListen string `yaml:"unix_listen"`
34+
Pprof bool `yaml:"pprof"`
3335
} `yaml:"api"`
3436
}
3537

@@ -43,6 +45,9 @@ func Init() {
4345
return
4446
}
4547

48+
// overwrite default mux with new mux to avoid pprof auto registering
49+
http.DefaultServeMux = http.NewServeMux()
50+
4651
basePath = cfg.Mod.BasePath
4752
log = app.GetLogger("api")
4853

@@ -54,6 +59,14 @@ func Init() {
5459
HandleFunc("api/restart", restartHandler)
5560
HandleFunc("api/log", logHandler)
5661

62+
if cfg.Mod.Pprof {
63+
HandleFunc("/debug/pprof/", pprof.Index)
64+
HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
65+
HandleFunc("/debug/pprof/profile", pprof.Profile)
66+
HandleFunc("/debug/pprof/symbol", pprof.Symbol)
67+
HandleFunc("/debug/pprof/trace", pprof.Trace)
68+
}
69+
5770
Handler = http.DefaultServeMux // 4th
5871

5972
if cfg.Mod.Origin == "*" {

0 commit comments

Comments
 (0)