Skip to content

Commit

Permalink
Ppof fixes (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Jul 4, 2023
1 parent 9af80bf commit 501a88f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ var runCmd = &cobra.Command{
defer cancelCtx()

var pprofFile *os.File

spqrlog.Logger.Printf(spqrlog.FATAL, "cpu prof save prof %t", saveProfie)

if saveProfie {
pprofFile, err = os.Create(profileFile)
if err != nil {
spqrlog.Logger.Printf(spqrlog.FATAL, "starting cpu prof error %v", err)
return err
}
spqrlog.Logger.Printf(spqrlog.LOG, "starting cpu prof with %s", profileFile)
spqrlog.Logger.Printf(spqrlog.FATAL, "starting cpu prof with %s", profileFile)
if err := pprof.StartCPUProfile(pprofFile); err != nil {
spqrlog.Logger.Printf(spqrlog.FATAL, "starting cpu prof error %v", err)
return err
}
}
Expand All @@ -116,11 +121,14 @@ var runCmd = &cobra.Command{
case syscall.SIGUSR1:
spqrlog.RebornLogger(rcfg.LogFileName)
case syscall.SIGUSR2:
// write profile
pprof.StopCPUProfile()

if err := pprofFile.Close(); err != nil {
spqrlog.Logger.PrintError(err)
if saveProfie {
// write profile
pprof.StopCPUProfile()
spqrlog.Logger.Printf(spqrlog.FATAL, "writing cpu prof")

if err := pprofFile.Close(); err != nil {
spqrlog.Logger.PrintError(err)
}
}
return
case syscall.SIGHUP:
Expand All @@ -131,6 +139,15 @@ var runCmd = &cobra.Command{
}
spqrlog.RebornLogger(rcfg.LogFileName)
case syscall.SIGINT, syscall.SIGTERM:
if saveProfie {
// write profile
pprof.StopCPUProfile()

spqrlog.Logger.Printf(spqrlog.FATAL, "writing cpu prof")
if err := pprofFile.Close(); err != nil {
spqrlog.Logger.PrintError(err)
}
}
return
default:
return
Expand Down

0 comments on commit 501a88f

Please sign in to comment.