Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
cmd/swarm: add pprof custom profiles through flags
Browse files Browse the repository at this point in the history
  • Loading branch information
acud committed Nov 18, 2019
1 parent 9b0c910 commit 50bf2e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/swarm/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,12 @@ var (
Name: "verbose",
Usage: "Display more verbose output",
}
SwarmMutexProfileFlag = cli.BoolFlag{
Name: "mutex-profile",
Usage: "Enable pprof mutex profile",
}
SwarmBlockProfileFlag = cli.BoolFlag{
Name: "block-profile",
Usage: "Enable pprof block profile",
}
)
18 changes: 18 additions & 0 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func init() {
defaultNodeConfig.IPCPath = "bzzd.ipc"
// Set flag defaults for --help display.
utils.ListenPortFlag.Value = 30399

runtime.SetMutexProfileFraction(5)
}

var app = utils.NewApp("", "", "Ethereum Swarm")
Expand Down Expand Up @@ -213,6 +215,9 @@ func init() {
SwarmStoreCapacity,
SwarmStoreCacheCapacity,
SwarmGlobalStoreAPIFlag,
// debugging
SwarmMutexProfileFlag,
SwarmBlockProfileFlag,
}
rpcFlags := []cli.Flag{
utils.WSEnabledFlag,
Expand Down Expand Up @@ -295,6 +300,9 @@ func bzzd(ctx *cli.Context) error {
cfg.DataDir = bzzconfig.Path
}

// start any custom pprof profiles
pprofProfiles(ctx)

//optionally set the bootnodes before configuring the node
setSwarmBootstrapNodes(ctx, &cfg)
//setup the ethereum node
Expand Down Expand Up @@ -567,3 +575,13 @@ func setSwarmNATFromInterface(ctx *cli.Context, cfg *node.Config) {
}
cfg.P2P.NAT = nat.ExtIP(ip)
}

func pprofProfiles(ctx *cli.Context) {
if ctx.GlobalBool(SwarmMutexProfileFlag.Name) {
runtime.SetMutexProfileFraction(1)
}

if ctx.GlobalBool(SwarmBlockProfileFlag.Name) {
runtime.SetBlockProfileRate(1)
}
}

0 comments on commit 50bf2e4

Please sign in to comment.