Skip to content

Commit bb0c0bd

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 922238a commit bb0c0bd

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"
@@ -32,6 +33,7 @@ func Init() {
3233
TLSCert string `yaml:"tls_cert"`
3334
TLSKey string `yaml:"tls_key"`
3435
UnixListen string `yaml:"unix_listen"`
36+
Pprof bool `yaml:"pprof"`
3537
} `yaml:"api"`
3638
}
3739

@@ -45,6 +47,9 @@ func Init() {
4547
return
4648
}
4749

50+
// overwrite default mux with new mux to avoid pprof auto registering
51+
http.DefaultServeMux = http.NewServeMux()
52+
4853
basePath = cfg.Mod.BasePath
4954
log = app.GetLogger("api")
5055

@@ -56,6 +61,14 @@ func Init() {
5661
HandleFunc("api/restart", restartHandler)
5762
HandleFunc("api/log", logHandler)
5863

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

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

0 commit comments

Comments
 (0)