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

internal/cli: add skiptrace flag for profiling #715

Merged
merged 2 commits into from
Feb 2, 2023
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
6 changes: 4 additions & 2 deletions docs/cli/debug_pprof.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The ```debug pprof <enode>``` command will create an archive containing bor ppro

- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131)

- ```seconds```: seconds to trace (default: 2)
- ```seconds```: seconds to profile (default: 2)

- ```output```: Output directory
- ```output```: Output directory

- ```skiptrace```: Skip running the trace (default: false)
27 changes: 21 additions & 6 deletions internal/cli/debug_pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
type DebugPprofCommand struct {
*Meta2

seconds uint64
output string
seconds uint64
output string
skiptrace bool
}

func (p *DebugPprofCommand) MarkDown() string {
Expand All @@ -44,7 +45,7 @@ func (d *DebugPprofCommand) Flags() *flagset.Flagset {

flags.Uint64Flag(&flagset.Uint64Flag{
Name: "seconds",
Usage: "seconds to trace",
Usage: "seconds to profile",
Value: &d.seconds,
Default: 2,
})
Expand All @@ -54,6 +55,15 @@ func (d *DebugPprofCommand) Flags() *flagset.Flagset {
Usage: "Output directory",
})

// Trace profiles can be expensive and take too much size (for grpc).
// This flag will help in making it optional.
flags.BoolFlag(&flagset.BoolFlag{
Name: "skiptrace",
Value: &d.skiptrace,
Usage: "Skip running the trace",
Default: false,
})

return flags
}

Expand Down Expand Up @@ -119,11 +129,16 @@ func (d *DebugPprofCommand) Run(args []string) int {
ctx, cancelFn := context.WithCancel(context.Background())
trapSignal(cancelFn)

// Only take cpu and heap profiles by default
profiles := map[string]string{
"heap": "heap",
"cpu": "cpu",
"trace": "trace",
"heap": "heap",
"cpu": "cpu",
}

if !d.skiptrace {
profiles["trace"] = "trace"
}

for profile, filename := range profiles {
if err := pprofProfile(ctx, profile, filename); err != nil {
d.UI.Error(fmt.Sprintf("Error creating profile '%s': %v", profile, err))
Expand Down