Merge pull request #755 from karalabe/command-flags-cleanup
cmd/geth, cmd/utils: add cli flags for pprof and whisper
This commit is contained in:
commit
3d7c1b8194
@ -24,8 +24,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -237,6 +235,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
|||||||
utils.RPCEnabledFlag,
|
utils.RPCEnabledFlag,
|
||||||
utils.RPCListenAddrFlag,
|
utils.RPCListenAddrFlag,
|
||||||
utils.RPCPortFlag,
|
utils.RPCPortFlag,
|
||||||
|
utils.WhisperEnabledFlag,
|
||||||
utils.VMDebugFlag,
|
utils.VMDebugFlag,
|
||||||
utils.ProtocolVersionFlag,
|
utils.ProtocolVersionFlag,
|
||||||
utils.NetworkIdFlag,
|
utils.NetworkIdFlag,
|
||||||
@ -247,6 +246,14 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
|||||||
utils.LogVModuleFlag,
|
utils.LogVModuleFlag,
|
||||||
utils.LogFileFlag,
|
utils.LogFileFlag,
|
||||||
utils.LogJSONFlag,
|
utils.LogJSONFlag,
|
||||||
|
utils.PProfEanbledFlag,
|
||||||
|
utils.PProfPortFlag,
|
||||||
|
}
|
||||||
|
app.Before = func(ctx *cli.Context) error {
|
||||||
|
if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
|
||||||
|
utils.StartPProf(ctx)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// missing:
|
// missing:
|
||||||
@ -261,11 +268,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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")
|
fmt.Printf("Welcome to the FRONTIER\n")
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
defer logger.Flush()
|
defer logger.Flush()
|
||||||
@ -337,6 +339,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
||||||
|
// Start Ethereum itself
|
||||||
utils.StartEthereum(eth)
|
utils.StartEthereum(eth)
|
||||||
am := eth.AccountManager()
|
am := eth.AccountManager()
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -140,10 +143,33 @@ var (
|
|||||||
Usage: "Send json structured log output to a file or '-' for standard output (default: no json output)",
|
Usage: "Send json structured log output to a file or '-' for standard output (default: no json output)",
|
||||||
Value: "",
|
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{
|
VMDebugFlag = cli.BoolFlag{
|
||||||
Name: "vmdebug",
|
Name: "vmdebug",
|
||||||
Usage: "Virtual Machine debug output",
|
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(),
|
||||||
|
}
|
||||||
|
PProfEanbledFlag = cli.BoolFlag{
|
||||||
|
Name: "pprof",
|
||||||
|
Usage: "Whether the profiling server should be enabled",
|
||||||
|
}
|
||||||
|
PProfPortFlag = cli.IntFlag{
|
||||||
|
Name: "pprofport",
|
||||||
|
Usage: "Port on which the profiler should listen",
|
||||||
|
Value: 6060,
|
||||||
|
}
|
||||||
|
|
||||||
// RPC settings
|
// RPC settings
|
||||||
RPCEnabledFlag = cli.BoolFlag{
|
RPCEnabledFlag = cli.BoolFlag{
|
||||||
@ -194,25 +220,15 @@ var (
|
|||||||
Usage: "Port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
|
Usage: "Port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
|
||||||
Value: "any",
|
Value: "any",
|
||||||
}
|
}
|
||||||
|
WhisperEnabledFlag = cli.BoolFlag{
|
||||||
|
Name: "shh",
|
||||||
|
Usage: "Whether the whisper sub-protocol is enabled",
|
||||||
|
}
|
||||||
JSpathFlag = cli.StringFlag{
|
JSpathFlag = cli.StringFlag{
|
||||||
Name: "jspath",
|
Name: "jspath",
|
||||||
Usage: "JS library path to be used with console and js subcommands",
|
Usage: "JS library path to be used with console and js subcommands",
|
||||||
Value: ".",
|
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 {
|
func GetNAT(ctx *cli.Context) nat.Interface {
|
||||||
@ -274,7 +290,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
|||||||
NAT: GetNAT(ctx),
|
NAT: GetNAT(ctx),
|
||||||
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
|
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
|
||||||
NodeKey: GetNodeKey(ctx),
|
NodeKey: GetNodeKey(ctx),
|
||||||
Shh: true,
|
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
|
||||||
Dial: true,
|
Dial: true,
|
||||||
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
|
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
|
||||||
}
|
}
|
||||||
@ -324,3 +340,10 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) {
|
|||||||
xeth := xeth.New(eth, nil)
|
xeth := xeth.New(eth, nil)
|
||||||
_ = rpc.Start(xeth, config)
|
_ = 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))
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user