Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ppof fixes #192

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading