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

dcrwallet: Add --cpuprofile option #2195

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type config struct {
NoFileLogging bool `long:"nofilelogging" description:"Disable file logging"`
Profile []string `long:"profile" description:"Enable HTTP profiling this interface/port"`
MemProfile string `long:"memprofile" description:"Write mem profile to the specified file"`
CPUProfile string `long:"cpuprofile" description:"Write cpu profile to the specified file"`

// Wallet options
WalletPass string `long:"walletpass" default-mask:"-" description:"Public wallet password; required when created with one"`
Expand Down
23 changes: 19 additions & 4 deletions dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ func run(ctx context.Context) error {
}
}

// Write cpu profile if requested.
if cfg.CPUProfile != "" {
if done(ctx) {
return ctx.Err()
}

f, err := os.Create(cfg.CPUProfile)
if err != nil {
log.Errorf("Unable to create cpu profile: %v", err.Error())
return err

}
pprof.StartCPUProfile(f)
defer f.Close()
defer pprof.StopCPUProfile()
}

// Write mem profile if requested.
if cfg.MemProfile != "" {
if done(ctx) {
Expand All @@ -136,12 +153,10 @@ func run(ctx context.Context) error {

f, err := os.Create(cfg.MemProfile)
if err != nil {
log.Errorf("Unable to create cpu profile: %v", err)
log.Errorf("Unable to create mem profile: %v", err)
return err
}
timer := time.NewTimer(time.Minute * 5) // 5 minutes
go func() {
<-timer.C
defer func() {
pprof.WriteHeapProfile(f)
f.Close()
}()
Expand Down