feat(cli-flags): add option for cpu profiling (#3765)

This commit is contained in:
Anunay Maheshwari
2025-06-26 23:49:55 +05:30
committed by GitHub
parent 9fc4ddbe47
commit d6d2b6d833
+19 -1
View File
@@ -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