mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
extend --profile cmd line option to allow interface to be specified
Closes #691
This commit is contained in:
parent
dd3bc8afd7
commit
509eed37fb
27
config.go
27
config.go
@ -126,7 +126,7 @@ type config struct {
|
||||
SimNet bool `long:"simnet" description:"Use the simulation test network"`
|
||||
DisableCheckpoints bool `long:"nocheckpoints" description:"Disable built-in checkpoints. Don't do this unless you know what you're doing."`
|
||||
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"`
|
||||
Profile string `long:"profile" description:"Enable HTTP profiling on given [addr:]port -- NOTE port must be between 1024 and 65536"`
|
||||
CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"`
|
||||
MemProfile string `long:"memprofile" description:"Write mem profile to the specified file"`
|
||||
DumpBlockchain string `long:"dumpblockchain" description:"Write blockchain as a flat file of blocks for use with addblock, to the specified filename"`
|
||||
@ -636,12 +636,27 @@ func loadConfig() (*config, []string, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Validate profile port number
|
||||
// Validate format of profile, can be an address:port, or just a port.
|
||||
if cfg.Profile != "" {
|
||||
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 := fmt.Errorf(str, funcName)
|
||||
// if profile is just a number, then add a default host of "127.0.0.1" such that Profile is a valid tcp address
|
||||
if _, err := strconv.Atoi(cfg.Profile); err == nil {
|
||||
cfg.Profile = net.JoinHostPort("127.0.0.1", cfg.Profile)
|
||||
}
|
||||
|
||||
// check the Profile is a valid address
|
||||
_, portStr, err := net.SplitHostPort(cfg.Profile)
|
||||
if err != nil {
|
||||
str := "%s: profile: %s"
|
||||
err := fmt.Errorf(str, funcName, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// finally, check the port is in range
|
||||
if port, _ := strconv.Atoi(portStr); port < 1024 || port > 65535 {
|
||||
str := "%s: profile: address %s: port must be between 1024 and 65535"
|
||||
err := fmt.Errorf(str, funcName, cfg.Profile)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
return nil, nil, err
|
||||
|
||||
3
dcrd.go
3
dcrd.go
@ -7,7 +7,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
@ -58,7 +57,7 @@ func dcrdMain(serverChan chan<- *server) error {
|
||||
// Enable http profiling server if requested.
|
||||
if cfg.Profile != "" {
|
||||
go func() {
|
||||
listenAddr := net.JoinHostPort("", cfg.Profile)
|
||||
listenAddr := cfg.Profile
|
||||
dcrdLog.Infof("Creating profiling server "+
|
||||
"listening on %s", listenAddr)
|
||||
profileRedirect := http.RedirectHandler("/debug/pprof",
|
||||
|
||||
2
doc.go
2
doc.go
@ -76,7 +76,7 @@ Application Options:
|
||||
--nocheckpoints Disable built-in checkpoints. Don't do this unless
|
||||
you know what you're doing.
|
||||
--dbtype= Database backend to use for the Block Chain (ffldb)
|
||||
--profile= Enable HTTP profiling on given port -- NOTE port
|
||||
--profile= Enable HTTP profiling on given [addr:]port -- NOTE: port
|
||||
must be between 1024 and 65536
|
||||
--cpuprofile= Write CPU profile to the specified file
|
||||
--memprofile= Write mem profile to the specified file
|
||||
|
||||
@ -333,8 +333,20 @@ const FileContents = `[Application Options]
|
||||
; available subsystems.
|
||||
; debuglevel=info
|
||||
|
||||
; The port used to listen for HTTP profile requests. The profile server will
|
||||
; be disabled if this option is not specified. The profile information can be
|
||||
; accessed at http://localhost:<profileport>/debug/pprof once running.
|
||||
; profile=6061
|
||||
; ------------------------------------------------------------------------------
|
||||
; Profile - enable the HTTP profiler
|
||||
; ------------------------------------------------------------------------------
|
||||
|
||||
; The profile server will be disabled if this option is not specified. Profile
|
||||
; information can be accessed at http://ipaddr:<profileport>/debug/pprof once
|
||||
; running. Note that the IP address will default to 127.0.0.1 if an IP address
|
||||
; is not specified, so that the profiler is not accessible on the network.
|
||||
; Listen on selected port on localhost only:
|
||||
; profile=6061
|
||||
; Listen on selected port on all network interfaces:
|
||||
; profile=:6061
|
||||
; Listen on single network ipv4 interface:
|
||||
; profile=192.168.1.123:6061
|
||||
; Listen on ipv6 loopback interface:
|
||||
; profile=[::1]:6061
|
||||
`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user