Skip to content

Commit

Permalink
added pprof flag to enable/disable pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
hubchub committed May 23, 2023
1 parent 82b85d5 commit 72116c0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ BASE_CMD += --slices $(SLICES)
ifeq ($(ENABLE_ARCHIVE),true)
BASE_CMD += --gcmode archive
endif
ifeq ($(ENABLE_PPROF),true)
BASE_CMD += --pprof
endif
ifeq ($(ENABLE_UNLOCK),true)
BASE_CMD += --allow-insecure-unlock
endif
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ var (
Name: "slices",
Usage: "All the slices that are running on this node",
}
PprofFlag = cli.BoolFlag{
Name: "pprof",
Usage: "Enable the pprof HTTP server",
}
ColosseumFlag = cli.BoolFlag{
Name: "colosseum",
Usage: "Quai Colosseum testnet",
Expand Down Expand Up @@ -1295,6 +1299,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// set the slices that the node is running
setSlicesRunning(ctx, cfg)

// configure pprof
cfg.PprofEnabled = ctx.GlobalBool(PprofFlag.Name)

// Cap the cache allowance and tune the garbage collector
mem, err := gopsutil.VirtualMemory()
if err == nil {
Expand Down
48 changes: 47 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
package eth

import (
"bytes"
"fmt"
"math/big"
sync "github.com/sasha-s/go-deadlock"
"math/big"
"net/http"
"sync/atomic"
"time"

Expand Down Expand Up @@ -232,6 +234,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
stack.RegisterAPIs(eth.APIs())
stack.RegisterProtocols(eth.Protocols())
stack.RegisterLifecycle(eth)

if config.PprofEnabled {
log.Info("Starting pprof server")
EnablePprof()
}

// Check for unclean shutdown
if uncleanShutdowns, discards, err := rawdb.PushUncleanShutdownMarker(chainDb); err != nil {
log.Error("Could not update unclean-shutdown-marker list", "error", err)
Expand All @@ -248,6 +256,44 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return eth, nil
}

func EnablePprof() {
var port string
myContext := common.NodeLocation
switch {
case bytes.Equal(myContext, []byte{}): // PRIME
port = "8081"
case bytes.Equal(myContext, []byte{0}): // Region 0
port = "8090"
case bytes.Equal(myContext, []byte{1}): // Region 1
port = "8100"
case bytes.Equal(myContext, []byte{2}): // Region 2
port = "8110"
case bytes.Equal(myContext, []byte{0, 0}): // Zone 0-0
port = "8091"
case bytes.Equal(myContext, []byte{0, 1}): // Zone 0-1
port = "8092"
case bytes.Equal(myContext, []byte{0, 2}): // Zone 0-2
port = "8093"
case bytes.Equal(myContext, []byte{1, 0}): // Zone 1-0
port = "8101"
case bytes.Equal(myContext, []byte{1, 1}): // Zone 1-1
port = "8102"
case bytes.Equal(myContext, []byte{1, 2}): // Zone 1-2
port = "8103"
case bytes.Equal(myContext, []byte{2, 0}): // Zone 2-0
port = "8111"
case bytes.Equal(myContext, []byte{2, 1}): // Zone 2-1
port = "8112"
case bytes.Equal(myContext, []byte{2, 2}): // Zone 2-2
port = "8113"
default:
port = "8085"
}
go func() {
_ = http.ListenAndServe("localhost:"+port, nil)
}()
}

// APIs return the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API {
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ type Config struct {

// Slices running on the node
SlicesRunning []common.Location

// PPROF enabled
PprofEnabled bool
}

// CreateConsensusEngine creates a consensus engine for the given chain configuration.
Expand Down
1 change: 1 addition & 0 deletions network.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ QUAI_STATS=false
STATS_NAME=
STATS_PASS=
STATS_HOST=
ENABLE_PPROF=false

0 comments on commit 72116c0

Please sign in to comment.