Skip to content

Commit

Permalink
cmd/geth, mobile: add memsize to pprof server (ethereum#16532)
Browse files Browse the repository at this point in the history
* cmd/geth, mobile: add memsize to pprof server

This is a temporary change, to be reverted before the next release.

* cmd/geth: fix variable name
  • Loading branch information
fjl authored and mariameda committed Aug 19, 2018
1 parent 8ef547d commit c573ccd
Show file tree
Hide file tree
Showing 13 changed files with 834 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cmd/gilu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func geth(ctx *cli.Context) error {
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner.
func startNode(ctx *cli.Context, stack *node.Node) {
debug.Memsize.Add("node", stack)

// Start up the node itself
utils.StartNode(stack)

Expand Down
27 changes: 17 additions & 10 deletions internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ import (
"github.com/ethereum/go-ethereum/log/term"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/exp"
"github.com/fjl/memsize/memsizeui"
colorable "github.com/mattn/go-colorable"
"gopkg.in/urfave/cli.v1"
)

var Memsize memsizeui.Handler

var (
verbosityFlag = cli.IntFlag{
Name: "verbosity",
Expand Down Expand Up @@ -129,21 +132,25 @@ func Setup(ctx *cli.Context) error {

// pprof server
if ctx.GlobalBool(pprofFlag.Name) {
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
// from the registry into expvar, and execute regular expvar handler.
exp.Exp(metrics.DefaultRegistry)

address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name))
go func() {
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
if err := http.ListenAndServe(address, nil); err != nil {
log.Error("Failure in running pprof server", "err", err)
}
}()
StartPProf(address)
}
return nil
}

func StartPProf(address string) {
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
// from the registry into expvar, and execute regular expvar handler.
exp.Exp(metrics.DefaultRegistry)
http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize))
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
go func() {
if err := http.ListenAndServe(address, nil); err != nil {
log.Error("Failure in running pprof server", "err", err)
}
}()
}

// Exit stops all running profiles, flushing their output to the
// respective file.
func Exit() {
Expand Down
11 changes: 11 additions & 0 deletions mobile/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethstats"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
Expand Down Expand Up @@ -72,6 +73,9 @@ type NodeConfig struct {

// WhisperEnabled specifies whether the node should run the Whisper protocol.
WhisperEnabled bool

// Listening address of pprof server.
PprofAddress string
}

// defaultNodeConfig contains the default node configuration values to use if all
Expand Down Expand Up @@ -107,6 +111,11 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
if config.BootstrapNodes == nil || config.BootstrapNodes.Size() == 0 {
config.BootstrapNodes = defaultNodeConfig.BootstrapNodes
}

if config.PprofAddress != "" {
debug.StartPProf(config.PprofAddress)
}

// Create the empty networking stack
nodeConf := &node.Config{
Name: clientIdentifier,
Expand All @@ -127,6 +136,8 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
return nil, err
}

debug.Memsize.Add("node", rawStack)

var genesis *core.Genesis
if config.EthereumGenesis != "" {
// Parse the user supplied genesis spec if not mainnet
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/fjl/memsize/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions vendor/github.com/fjl/memsize/bitmap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/github.com/fjl/memsize/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c573ccd

Please sign in to comment.