Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/geth, cmd/utils: add cli flags for pprof and whisper #755

Merged
merged 3 commits into from
Apr 20, 2015
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
17 changes: 10 additions & 7 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"bufio"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"runtime"
"strconv"
Expand Down Expand Up @@ -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,
Expand All @@ -246,6 +245,14 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.LogVModuleFlag,
utils.LogFileFlag,
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:
Expand All @@ -260,11 +267,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()
Expand Down Expand Up @@ -336,6 +338,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
}

func startEth(ctx *cli.Context, eth *eth.Ethereum) {
// Start Ethereum itself
utils.StartEthereum(eth)
am := eth.AccountManager()

Expand Down
53 changes: 38 additions & 15 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package utils

import (
"crypto/ecdsa"
"fmt"
"log"
"net/http"
"os"
"path"
"runtime"
Expand Down Expand Up @@ -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(),
}
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
RPCEnabledFlag = cli.BoolFlag{
Expand Down Expand Up @@ -190,25 +216,15 @@ var (
Usage: "Port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
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 {
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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))
}()
}