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

cmd/swarm: add pprof custom profiles through flags #1960

Merged
merged 1 commit into from
Nov 18, 2019
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
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",
}
)
16 changes: 16 additions & 0 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ func init() {
SwarmStoreCapacity,
SwarmStoreCacheCapacity,
SwarmGlobalStoreAPIFlag,
// debugging
SwarmMutexProfileFlag,
SwarmBlockProfileFlag,
}
rpcFlags := []cli.Flag{
utils.WSEnabledFlag,
Expand Down Expand Up @@ -295,6 +298,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 +573,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)
}
}