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

fix: close cpu profile #1894

Open
wants to merge 1 commit into
base: release-next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions common/profiler/cpu_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
package profiler

import (
"github.com/michaelquigley/pfxlog"
"os"
"os/signal"
"runtime/pprof"
"syscall"

"github.com/michaelquigley/pfxlog"
)

type CPU struct {
path string
shutdownC <-chan struct{}
profile *os.File
}

func NewCPU(path string) (*CPU, error) {
Expand All @@ -44,7 +46,7 @@ func NewCPUWithShutdown(path string, shutdownC <-chan struct{}) (*CPU, error) {
return nil, err
}
pfxlog.Logger().Infof("cpu profiling to [%s]", path)
return &CPU{path: path, shutdownC: shutdownC}, nil
return &CPU{path: path, shutdownC: shutdownC, profile: f}, nil
}

func (cpu *CPU) Run() {
Expand All @@ -55,7 +57,7 @@ func (cpu *CPU) Run() {
case <-signalChan:
case <-cpu.shutdownC:
}

defer cpu.profile.Close()
pprof.StopCPUProfile()
pfxlog.Logger().Info("stopped profiling cpu")
}