Skip to content

Commit

Permalink
moved EnablePprof from backend.go to setEthconfig in flags.go + enabl…
Browse files Browse the repository at this point in the history
…ed block + mutex
  • Loading branch information
hubchub committed Jun 22, 2023
1 parent c36b1ea commit 5e9cc4e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
49 changes: 47 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
package utils

import (
"bytes"
"crypto/ecdsa"
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"math/big"
"net/http"
"path/filepath"
"runtime"
godebug "runtime/debug"
"strconv"
"strings"
Expand Down Expand Up @@ -1277,6 +1280,46 @@ func SetGlobalVars(ctx *cli.Context) {
}
}

func EnablePprof() {
runtime.SetBlockProfileRate(1)
runtime.SetMutexProfileFraction(1)
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)
}()
}

// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// Avoid conflicting network flags
Expand Down Expand Up @@ -1306,8 +1349,10 @@ 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)
if ctx.GlobalBool(PprofFlag.Name) {
log.Info("Starting pprof server")
EnablePprof()
}

// Cap the cache allowance and tune the garbage collector
mem, err := gopsutil.VirtualMemory()
Expand Down
45 changes: 0 additions & 45 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
package eth

import (
"bytes"
"fmt"
"math/big"
"net/http"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -235,11 +233,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Quai, error) {
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 @@ -256,44 +249,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Quai, 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 go-quai package offers.
// NOTE, some of these services probably need to be moved to somewhere else.
func (s *Quai) APIs() []rpc.API {
Expand Down
3 changes: 0 additions & 3 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ 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

0 comments on commit 5e9cc4e

Please sign in to comment.