mirror of
https://github.com/livekit/livekit.git
synced 2026-07-20 17:51:15 +00:00
feat(cli-flags): add option for cpu profiling (#3765)
This commit is contained in:
+19
-1
@@ -96,7 +96,10 @@ var baseFlags = []cli.Flag{
|
||||
Usage: "tls key file for TURN server",
|
||||
Sources: cli.EnvVars("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`",
|
||||
@@ -255,6 +258,21 @@ func startServer(_ context.Context, c *cli.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if cpuProfile := c.String("cpuprofile"); cpuProfile != "" {
|
||||
if f, err := os.Create(cpuProfile); err != nil {
|
||||
return err
|
||||
} else {
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
f.Close()
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
pprof.StopCPUProfile()
|
||||
f.Close()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
if memProfile := c.String("memprofile"); memProfile != "" {
|
||||
if f, err := os.Create(memProfile); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user