Skip to content

Commit c573ccd

Browse files
fjlmariameda
authored andcommitted
cmd/geth, mobile: add memsize to pprof server (ethereum#16532)
* 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
1 parent 8ef547d commit c573ccd

File tree

13 files changed

+834
-10
lines changed

13 files changed

+834
-10
lines changed

cmd/gilu/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ func geth(ctx *cli.Context) error {
223223
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
224224
// miner.
225225
func startNode(ctx *cli.Context, stack *node.Node) {
226+
debug.Memsize.Add("node", stack)
227+
226228
// Start up the node itself
227229
utils.StartNode(stack)
228230

internal/debug/flags.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ import (
2828
"github.com/ethereum/go-ethereum/log/term"
2929
"github.com/ethereum/go-ethereum/metrics"
3030
"github.com/ethereum/go-ethereum/metrics/exp"
31+
"github.com/fjl/memsize/memsizeui"
3132
colorable "github.com/mattn/go-colorable"
3233
"gopkg.in/urfave/cli.v1"
3334
)
3435

36+
var Memsize memsizeui.Handler
37+
3538
var (
3639
verbosityFlag = cli.IntFlag{
3740
Name: "verbosity",
@@ -129,21 +132,25 @@ func Setup(ctx *cli.Context) error {
129132

130133
// pprof server
131134
if ctx.GlobalBool(pprofFlag.Name) {
132-
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
133-
// from the registry into expvar, and execute regular expvar handler.
134-
exp.Exp(metrics.DefaultRegistry)
135-
136135
address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name))
137-
go func() {
138-
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
139-
if err := http.ListenAndServe(address, nil); err != nil {
140-
log.Error("Failure in running pprof server", "err", err)
141-
}
142-
}()
136+
StartPProf(address)
143137
}
144138
return nil
145139
}
146140

141+
func StartPProf(address string) {
142+
// Hook go-metrics into expvar on any /debug/metrics request, load all vars
143+
// from the registry into expvar, and execute regular expvar handler.
144+
exp.Exp(metrics.DefaultRegistry)
145+
http.Handle("/memsize/", http.StripPrefix("/memsize", &Memsize))
146+
log.Info("Starting pprof server", "addr", fmt.Sprintf("http://%s/debug/pprof", address))
147+
go func() {
148+
if err := http.ListenAndServe(address, nil); err != nil {
149+
log.Error("Failure in running pprof server", "err", err)
150+
}
151+
}()
152+
}
153+
147154
// Exit stops all running profiles, flushing their output to the
148155
// respective file.
149156
func Exit() {

mobile/geth.go

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/ethereum/go-ethereum/eth/downloader"
3030
"github.com/ethereum/go-ethereum/ethclient"
3131
"github.com/ethereum/go-ethereum/ethstats"
32+
"github.com/ethereum/go-ethereum/internal/debug"
3233
"github.com/ethereum/go-ethereum/les"
3334
"github.com/ethereum/go-ethereum/node"
3435
"github.com/ethereum/go-ethereum/p2p"
@@ -72,6 +73,9 @@ type NodeConfig struct {
7273

7374
// WhisperEnabled specifies whether the node should run the Whisper protocol.
7475
WhisperEnabled bool
76+
77+
// Listening address of pprof server.
78+
PprofAddress string
7579
}
7680

7781
// defaultNodeConfig contains the default node configuration values to use if all
@@ -107,6 +111,11 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
107111
if config.BootstrapNodes == nil || config.BootstrapNodes.Size() == 0 {
108112
config.BootstrapNodes = defaultNodeConfig.BootstrapNodes
109113
}
114+
115+
if config.PprofAddress != "" {
116+
debug.StartPProf(config.PprofAddress)
117+
}
118+
110119
// Create the empty networking stack
111120
nodeConf := &node.Config{
112121
Name: clientIdentifier,
@@ -127,6 +136,8 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
127136
return nil, err
128137
}
129138

139+
debug.Memsize.Add("node", rawStack)
140+
130141
var genesis *core.Genesis
131142
if config.EthereumGenesis != "" {
132143
// Parse the user supplied genesis spec if not mainnet

vendor/github.com/fjl/memsize/LICENSE

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/fjl/memsize/bitmap.go

+119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/fjl/memsize/doc.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)