From 8830403acfea745bd5e256d1498727e9128f02ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 20 Apr 2015 18:45:37 +0300 Subject: [PATCH 1/3] cmd/geth, cmd/utils: add cli flags for pprof and whisper. --- cmd/geth/main.go | 15 +++++++------ cmd/utils/flags.go | 53 +++++++++++++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index fa6a93b78..de1a59772 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -24,8 +24,6 @@ import ( "bufio" "fmt" "io/ioutil" - "log" - "net/http" "os" "runtime" "strconv" @@ -236,6 +234,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.RPCEnabledFlag, utils.RPCListenAddrFlag, utils.RPCPortFlag, + utils.WhisperEnabledFlag, utils.VMDebugFlag, utils.ProtocolVersionFlag, utils.NetworkIdFlag, @@ -246,6 +245,8 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.LogVModuleFlag, utils.LogFileFlag, utils.LogJSONFlag, + utils.PProfEnabledFlag, + utils.PProfPortFlag, } // missing: @@ -260,11 +261,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso } func main() { - // Start up the default http server for pprof - go func() { - log.Println(http.ListenAndServe("localhost:6060", nil)) - }() - fmt.Printf("Welcome to the FRONTIER\n") runtime.GOMAXPROCS(runtime.NumCPU()) defer logger.Flush() @@ -336,6 +332,11 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass } func startEth(ctx *cli.Context, eth *eth.Ethereum) { + // Start profiling, if requested + if ctx.GlobalBool(utils.PProfEnabledFlag.Name) { + utils.StartPProf(ctx) + } + // Start Ethereum itself utils.StartEthereum(eth) am := eth.AccountManager() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a1d9eedda..3b1fda32e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2,6 +2,9 @@ package utils import ( "crypto/ecdsa" + "fmt" + "log" + "net/http" "os" "path" "runtime" @@ -136,10 +139,33 @@ var ( Usage: "Send json structured log output to a file or '-' for standard output (default: no json output)", Value: "", } + LogToStdErrFlag = cli.BoolFlag{ + Name: "logtostderr", + Usage: "Logs are written to standard error instead of to files.", + } + LogVModuleFlag = cli.GenericFlag{ + Name: "vmodule", + Usage: "The syntax of the argument is a comma-separated list of pattern=N, where pattern is a literal file name (minus the \".go\" suffix) or \"glob\" pattern and N is a V level.", + Value: glog.GetVModule(), + } VMDebugFlag = cli.BoolFlag{ Name: "vmdebug", Usage: "Virtual Machine debug output", } + BacktraceAtFlag = cli.GenericFlag{ + Name: "backtrace_at", + Usage: "When set to a file and line number holding a logging statement a stack trace will be written to the Info log", + Value: glog.GetTraceLocation(), + } + PProfEnabledFlag = cli.BoolFlag{ + Name: "pprof", + Usage: "Whether the profiling server is enabled", + } + PProfPortFlag = cli.IntFlag{ + Name: "pprofport", + Usage: "Port on which the profiler should listen", + Value: 6060, + } // RPC settings RPCEnabledFlag = cli.BoolFlag{ @@ -190,25 +216,15 @@ var ( Usage: "Port mapping mechanism (any|none|upnp|pmp|extip:)", Value: "any", } + WhisperEnabledFlag = cli.BoolFlag{ + Name: "shh", + Usage: "Whether the whisper sub-protocol is enabled", + } JSpathFlag = cli.StringFlag{ Name: "jspath", Usage: "JS library path to be used with console and js subcommands", Value: ".", } - BacktraceAtFlag = cli.GenericFlag{ - Name: "backtrace_at", - Usage: "When set to a file and line number holding a logging statement a stack trace will be written to the Info log", - Value: glog.GetTraceLocation(), - } - LogToStdErrFlag = cli.BoolFlag{ - Name: "logtostderr", - Usage: "Logs are written to standard error instead of to files.", - } - LogVModuleFlag = cli.GenericFlag{ - Name: "vmodule", - Usage: "The syntax of the argument is a comma-separated list of pattern=N, where pattern is a literal file name (minus the \".go\" suffix) or \"glob\" pattern and N is a V level.", - Value: glog.GetVModule(), - } ) func GetNAT(ctx *cli.Context) nat.Interface { @@ -269,7 +285,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config { Port: ctx.GlobalString(ListenPortFlag.Name), NAT: GetNAT(ctx), NodeKey: GetNodeKey(ctx), - Shh: true, + Shh: ctx.GlobalBool(WhisperEnabledFlag.Name), Dial: true, BootNodes: ctx.GlobalString(BootnodesFlag.Name), } @@ -319,3 +335,10 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) { xeth := xeth.New(eth, nil) _ = rpc.Start(xeth, config) } + +func StartPProf(ctx *cli.Context) { + address := fmt.Sprintf("localhost:%d", ctx.GlobalInt(PProfPortFlag.Name)) + go func() { + log.Println(http.ListenAndServe(address, nil)) + }() +} From c8e2b3710cec47f023fd01c42ea829579a2753be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 20 Apr 2015 18:59:41 +0300 Subject: [PATCH 2/3] cmd/geth, cmd/utils: use pprof disable flag, start globally --- cmd/geth/main.go | 12 +++++++----- cmd/utils/flags.go | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index de1a59772..5695c4117 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -245,9 +245,15 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.LogVModuleFlag, utils.LogFileFlag, utils.LogJSONFlag, - utils.PProfEnabledFlag, + utils.PProfDisabledFlag, utils.PProfPortFlag, } + app.Before = func(ctx *cli.Context) error { + if !ctx.GlobalBool(utils.PProfDisabledFlag.Name) { + utils.StartPProf(ctx) + } + return nil + } // missing: // flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") @@ -332,10 +338,6 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass } func startEth(ctx *cli.Context, eth *eth.Ethereum) { - // Start profiling, if requested - if ctx.GlobalBool(utils.PProfEnabledFlag.Name) { - utils.StartPProf(ctx) - } // Start Ethereum itself utils.StartEthereum(eth) am := eth.AccountManager() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3b1fda32e..429007642 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -157,9 +157,9 @@ var ( Usage: "When set to a file and line number holding a logging statement a stack trace will be written to the Info log", Value: glog.GetTraceLocation(), } - PProfEnabledFlag = cli.BoolFlag{ - Name: "pprof", - Usage: "Whether the profiling server is enabled", + PProfDisabledFlag = cli.BoolFlag{ + Name: "nopprof", + Usage: "Whether the profiling server should be disabled", } PProfPortFlag = cli.IntFlag{ Name: "pprofport", From 3b008723db3f89696dab53b311cbd2efc987a01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 20 Apr 2015 19:14:49 +0300 Subject: [PATCH 3/3] cmd/geth, cmd/utils: invert --pprof once more --- cmd/geth/main.go | 4 ++-- cmd/utils/flags.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 5695c4117..e213423ce 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -245,11 +245,11 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.LogVModuleFlag, utils.LogFileFlag, utils.LogJSONFlag, - utils.PProfDisabledFlag, + utils.PProfEanbledFlag, utils.PProfPortFlag, } app.Before = func(ctx *cli.Context) error { - if !ctx.GlobalBool(utils.PProfDisabledFlag.Name) { + if ctx.GlobalBool(utils.PProfEanbledFlag.Name) { utils.StartPProf(ctx) } return nil diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 429007642..f81645e4e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -157,9 +157,9 @@ var ( Usage: "When set to a file and line number holding a logging statement a stack trace will be written to the Info log", Value: glog.GetTraceLocation(), } - PProfDisabledFlag = cli.BoolFlag{ - Name: "nopprof", - Usage: "Whether the profiling server should be disabled", + PProfEanbledFlag = cli.BoolFlag{ + Name: "pprof", + Usage: "Whether the profiling server should be enabled", } PProfPortFlag = cli.IntFlag{ Name: "pprofport",