Add pprof endpoint when running in dev mode (#708)

This commit is contained in:
David Zhao
2022-05-23 00:34:16 -07:00
committed by GitHub
parent 96b095504b
commit a933f1513f
5 changed files with 15 additions and 29 deletions
+1 -18
View File
@@ -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