Add pprof endpoint when running in dev mode (#708)
This commit is contained in:
+1
-18
@@ -86,17 +86,13 @@ func main() {
|
||||
EnvVars: []string{"LIVEKIT_TURN_KEY"},
|
||||
},
|
||||
// debugging flags
|
||||
&cli.StringFlag{
|
||||
Name: "cpuprofile",
|
||||
Usage: "write cpu profile to `file`",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "memprofile",
|
||||
Usage: "write memory profile to `file`",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dev",
|
||||
Usage: "sets log-level to debug, and console formatter",
|
||||
Usage: "sets log-level to debug, console formatter, and /debug/pprof",
|
||||
},
|
||||
},
|
||||
Action: startServer,
|
||||
@@ -159,7 +155,6 @@ func getConfig(c *cli.Context) (*config.Config, error) {
|
||||
func startServer(c *cli.Context) error {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
cpuProfile := c.String("cpuprofile")
|
||||
memProfile := c.String("memprofile")
|
||||
|
||||
conf, err := getConfig(c)
|
||||
@@ -169,18 +164,6 @@ func startServer(c *cli.Context) error {
|
||||
|
||||
serverlogger.InitFromConfig(conf.Logging)
|
||||
|
||||
if cpuProfile != "" {
|
||||
if f, err := os.Create(cpuProfile); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer f.Close()
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
return err
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
}
|
||||
|
||||
if memProfile != "" {
|
||||
if f, err := os.Create(memProfile); err != nil {
|
||||
return err
|
||||
|
||||
+10
-8
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
|
||||
@@ -16,13 +17,12 @@ import (
|
||||
"github.com/urfave/negroni"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/version"
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
type LivekitServer struct {
|
||||
@@ -85,16 +85,18 @@ func NewLivekitServer(conf *config.Config,
|
||||
recServer := livekit.NewRecordingServiceServer(recService)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
if conf.Development {
|
||||
// pprof handlers are registered onto DefaultServeMux
|
||||
mux = http.DefaultServeMux
|
||||
mux.HandleFunc("/debug/goroutine", s.debugGoroutines)
|
||||
mux.HandleFunc("/debug/rooms", s.debugInfo)
|
||||
}
|
||||
mux.Handle(roomServer.PathPrefix(), roomServer)
|
||||
mux.Handle(egressServer.PathPrefix(), egressServer)
|
||||
mux.Handle(recServer.PathPrefix(), recServer)
|
||||
mux.Handle("/rtc", rtcService)
|
||||
mux.HandleFunc("/rtc/validate", rtcService.Validate)
|
||||
mux.HandleFunc("/", s.healthCheck)
|
||||
if conf.Development {
|
||||
mux.HandleFunc("/debug/goroutine", s.debugGoroutines)
|
||||
mux.HandleFunc("/debug/rooms", s.debugInfo)
|
||||
}
|
||||
|
||||
s.httpServer = &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", conf.Port),
|
||||
|
||||
@@ -24,6 +24,10 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
import (
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {
|
||||
|
||||
@@ -140,7 +140,6 @@ func createSingleNodeServer(configUpdater func(*config.Config)) *service.Livekit
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("could not create config: %v", err))
|
||||
}
|
||||
conf.Development = true
|
||||
conf.Keys = map[string]string{testApiKey: testApiSecret}
|
||||
if configUpdater != nil {
|
||||
configUpdater(conf)
|
||||
@@ -171,7 +170,6 @@ func createMultiNodeServer(nodeID string, port uint32) *service.LivekitServer {
|
||||
conf.RTC.UDPPort = port + 1
|
||||
conf.RTC.TCPPort = port + 2
|
||||
conf.Redis.Address = "localhost:6379"
|
||||
conf.Development = true
|
||||
conf.Keys = map[string]string{testApiKey: testApiSecret}
|
||||
|
||||
currentNode, err := routing.NewLocalNode(conf)
|
||||
|
||||
@@ -111,7 +111,6 @@ func setupServerWithWebhook() (server *service.LivekitServer, testServer *webhoo
|
||||
}
|
||||
conf.WebHook.URLs = []string{"http://localhost:7890"}
|
||||
conf.WebHook.APIKey = testApiKey
|
||||
conf.Development = true
|
||||
conf.Keys = map[string]string{testApiKey: testApiSecret}
|
||||
|
||||
testServer = newTestServer(":7890")
|
||||
|
||||
Reference in New Issue
Block a user