Skip to content

Commit

Permalink
feat(api): add pprof endpoint
Browse files Browse the repository at this point in the history
This will help debug running go2rtc instances.

By default the pprof endpoint is off.
It can be enabled via the api.pprof setting.
  • Loading branch information
jrcichra committed Sep 24, 2024
1 parent 922238a commit bb0c0bd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
"strconv"
"strings"
Expand All @@ -32,6 +33,7 @@ func Init() {
TLSCert string `yaml:"tls_cert"`
TLSKey string `yaml:"tls_key"`
UnixListen string `yaml:"unix_listen"`
Pprof bool `yaml:"pprof"`
} `yaml:"api"`
}

Expand All @@ -45,6 +47,9 @@ func Init() {
return
}

// overwrite default mux with new mux to avoid pprof auto registering
http.DefaultServeMux = http.NewServeMux()

basePath = cfg.Mod.BasePath
log = app.GetLogger("api")

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

if cfg.Mod.Pprof {
HandleFunc("/debug/pprof/", pprof.Index)
HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
HandleFunc("/debug/pprof/profile", pprof.Profile)
HandleFunc("/debug/pprof/symbol", pprof.Symbol)
HandleFunc("/debug/pprof/trace", pprof.Trace)
}

Handler = http.DefaultServeMux // 4th

if cfg.Mod.Origin == "*" {
Expand Down

0 comments on commit bb0c0bd

Please sign in to comment.