Skip to content

Commit

Permalink
Add support for pprof in harmony + node.sh (#2424)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Johnsson authored and Leo Chen committed Apr 30, 2020
1 parent 07f6f64 commit 6e4db00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cmd/harmony/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"math/big"
"math/rand"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -87,6 +89,7 @@ var (
freshDB = flag.Bool("fresh_db", false, "true means the existing disk based db will be removed")
profile = flag.Bool("profile", false, "Turn on profiling (CPU, Memory).")
metricsReportURL = flag.String("metrics_report_url", "", "If set, reports metrics to this URL.")
pprof = flag.String("pprof", "", "what address and port the pprof profiling server should listen on")
versionFlag = flag.Bool("version", false, "Output version info")
onlyLogTps = flag.Bool("only_log_tps", false, "Only log TPS if true")
dnsZone = flag.String("dns_zone", "", "if given and not empty, use peers from the zone (default: use libp2p peer discovery instead)")
Expand Down Expand Up @@ -164,6 +167,12 @@ var (
)

func initSetup() {

// Setup pprof
if addr := *pprof; addr != "" {
go func() { http.ListenAndServe(addr, nil) }()
}

// maybe request passphrase for bls key.
if *cmkEncryptedBLSKey == "" {
passphraseForBls()
Expand Down
10 changes: 9 additions & 1 deletion scripts/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ usage: ${progname} [-1ch] [-k KEYFILE]
-M support multi-key mode (default: off)
-A enable archival node mode (default: off)
-R tracefile enable p2p trace using tracefile (default: off)
-r address start a pprof profiling server listening on the specified address
examples:
Expand Down Expand Up @@ -168,6 +169,7 @@ shard_id=1
download_harmony_db=false
public_rpc=false
blacklist=./.hmy/blacklist.txt
pprof=""
static=false
multi_key=false
archival=false
Expand All @@ -177,7 +179,7 @@ ${TRACEFILE=}

unset OPTIND OPTARG opt
OPTIND=1
while getopts :1chk:sSp:dDmN:tT:i:ba:U:PvVIMB:AYR: opt
while getopts :1chk:sSp:dDmN:tT:i:ba:U:PvVIMB:AYR:r: opt
do
case "${opt}" in
'?') usage "unrecognized option -${OPTARG}";;
Expand All @@ -203,6 +205,7 @@ do
U) upgrade_rel="${OPTARG}";;
P) public_rpc=true;;
B) blacklist="${OPTARG}";;
r) pprof="${OPTARG}";;
v) msg "version: $version"
exit 0 ;;
V) LD_LIBRARY_PATH=. ./harmony -version
Expand Down Expand Up @@ -684,6 +687,11 @@ do
-public_rpc
)
fi
if [ ! -z "${pprof}" ]; then
args+=(
-pprof "${pprof}"
)
fi
# backward compatible with older harmony node software
case "${node_type}" in
explorer)
Expand Down

0 comments on commit 6e4db00

Please sign in to comment.