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",
|
Usage: "tls key file for TURN server",
|
||||||
Sources: cli.EnvVars("LIVEKIT_TURN_KEY"),
|
Sources: cli.EnvVars("LIVEKIT_TURN_KEY"),
|
||||||
},
|
},
|
||||||
// debugging flags
|
&cli.StringFlag{
|
||||||
|
Name: "cpuprofile",
|
||||||
|
Usage: "write CPU profile to `file`",
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "memprofile",
|
Name: "memprofile",
|
||||||
Usage: "write memory profile to `file`",
|
Usage: "write memory profile to `file`",
|
||||||
@@ -255,6 +258,21 @@ func startServer(_ context.Context, c *cli.Command) error {
|
|||||||
return err
|
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 memProfile := c.String("memprofile"); memProfile != "" {
|
||||||
if f, err := os.Create(memProfile); err != nil {
|
if f, err := os.Create(memProfile); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user