Skip to content

Commit

Permalink
internal/cli: add skiptrace flag for profiling (#715)
Browse files Browse the repository at this point in the history
* internal/cli: add skiptrace flag

* docs: update docs for skiptrace flag
  • Loading branch information
manav2401 authored Feb 2, 2023
1 parent d6899d7 commit a1871ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
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

0 comments on commit a1871ad

Please sign in to comment.