Add a flag to enable live profiling.
The profile information can be seen with a browser on e.g. http://localhost:6060/debug/pprof/ Alternatively, one can use the pprof tool as described at http://golang.org/pkg/net/http/pprof/ ok davec
This commit is contained in:
parent
7609ff396a
commit
ada49f1413
2 changed files with 22 additions and 0 deletions
10
btcd.go
10
btcd.go
|
@ -11,6 +11,8 @@ import (
|
|||
"github.com/conformal/btcscript"
|
||||
"github.com/conformal/seelog"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
@ -108,6 +110,14 @@ func btcdMain() error {
|
|||
loggers = setLogLevel(cfg.DebugLevel)
|
||||
}
|
||||
|
||||
// See if we want to enable profiling
|
||||
if cfg.Profile != "" {
|
||||
go func() {
|
||||
log.Errorf("%v", http.ListenAndServe(
|
||||
net.JoinHostPort("", cfg.Profile), nil))
|
||||
}()
|
||||
}
|
||||
|
||||
// Perform upgrades to btcd as new versions require it.
|
||||
err = doUpgrades()
|
||||
if err != nil {
|
||||
|
|
12
config.go
12
config.go
|
@ -15,6 +15,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -62,6 +63,7 @@ type config struct {
|
|||
TestNet3 bool `long:"testnet" description:"Use the test network"`
|
||||
RegressionTest bool `long:"regtest" description:"Use the regression test network"`
|
||||
DbType string `long:"dbtype" description:"Database backend to use for the Block Chain"`
|
||||
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
|
||||
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"`
|
||||
}
|
||||
|
||||
|
@ -282,6 +284,16 @@ func loadConfig() (*config, []string, error) {
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Validate profile port number
|
||||
profilePort, err := strconv.Atoi(cfg.Profile)
|
||||
if err != nil || profilePort < 1024 || profilePort > 65535 {
|
||||
str := "%s: The profile port must be between 1024 and 65535"
|
||||
err := errors.New(fmt.Sprintf(str, "loadConfig"))
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
parser.WriteHelp(os.Stderr)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Append the network type to the data directory so it is "namespaced"
|
||||
// per network. In addition to the block database, there are other
|
||||
// pieces of data that are saved to disk such as address manager state.
|
||||
|
|
Loading…
Reference in a new issue