mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Merge branch 'master' into fix-legacypool-gauges
This commit is contained in:
commit
4f70ff792a
9 changed files with 190 additions and 6 deletions
|
|
@ -300,6 +300,10 @@ func (s *SecureChannelSession) decryptAPDU(data []byte) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(data) == 0 || len(data)%aes.BlockSize != 0 {
|
||||||
|
return nil, fmt.Errorf("invalid ciphertext length: %d", len(data))
|
||||||
|
}
|
||||||
|
|
||||||
ret := make([]byte, len(data))
|
ret := make([]byte, len(data))
|
||||||
|
|
||||||
crypter := cipher.NewCBCDecrypter(a, s.iv)
|
crypter := cipher.NewCBCDecrypter(a, s.iv)
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZ
|
||||||
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
|
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
|
||||||
github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA=
|
github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA=
|
||||||
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
||||||
github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4=
|
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
|
||||||
github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/stateless"
|
"github.com/ethereum/go-ethereum/core/stateless"
|
||||||
|
|
@ -234,13 +236,24 @@ func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate all dirty addresses and record self-destructs.
|
// Collect all self-destructed addresses first, then sort them to ensure
|
||||||
|
// that state change hooks will be invoked in deterministic
|
||||||
|
// order when the accounts are deleted below
|
||||||
|
var selfDestructedAddrs []common.Address
|
||||||
for addr := range s.inner.journal.dirties {
|
for addr := range s.inner.journal.dirties {
|
||||||
obj := s.inner.stateObjects[addr]
|
obj := s.inner.stateObjects[addr]
|
||||||
if obj == nil || !obj.selfDestructed {
|
if obj == nil || !obj.selfDestructed {
|
||||||
// Not self-destructed, keep searching.
|
// Not self-destructed, keep searching.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
selfDestructedAddrs = append(selfDestructedAddrs, addr)
|
||||||
|
}
|
||||||
|
sort.Slice(selfDestructedAddrs, func(i, j int) bool {
|
||||||
|
return bytes.Compare(selfDestructedAddrs[i][:], selfDestructedAddrs[j][:]) < 0
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, addr := range selfDestructedAddrs {
|
||||||
|
obj := s.inner.stateObjects[addr]
|
||||||
// Bingo: state object was self-destructed, call relevant hooks.
|
// Bingo: state object was self-destructed, call relevant hooks.
|
||||||
|
|
||||||
// If ether was sent to account post-selfdestruct, record as burnt.
|
// If ether was sent to account post-selfdestruct, record as burnt.
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,9 @@ var (
|
||||||
queuedGauge = metrics.NewRegisteredGauge("txpool/queued", nil)
|
queuedGauge = metrics.NewRegisteredGauge("txpool/queued", nil)
|
||||||
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)
|
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)
|
||||||
|
|
||||||
|
pendingAddrsGauge = metrics.NewRegisteredGauge("txpool/pending/accounts", nil)
|
||||||
|
queuedAddrsGauge = metrics.NewRegisteredGauge("txpool/queued/accounts", nil)
|
||||||
|
|
||||||
reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)
|
reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -844,6 +847,7 @@ func (pool *LegacyPool) promoteTx(addr common.Address, hash common.Hash, tx *typ
|
||||||
// Try to insert the transaction into the pending queue
|
// Try to insert the transaction into the pending queue
|
||||||
if pool.pending[addr] == nil {
|
if pool.pending[addr] == nil {
|
||||||
pool.pending[addr] = newList(true)
|
pool.pending[addr] = newList(true)
|
||||||
|
pendingAddrsGauge.Inc(1)
|
||||||
}
|
}
|
||||||
list := pool.pending[addr]
|
list := pool.pending[addr]
|
||||||
|
|
||||||
|
|
@ -1083,6 +1087,7 @@ func (pool *LegacyPool) removeTx(hash common.Hash, outofbound bool, unreserve bo
|
||||||
// If no more pending transactions are left, remove the list
|
// If no more pending transactions are left, remove the list
|
||||||
if pending.Empty() {
|
if pending.Empty() {
|
||||||
delete(pool.pending, addr)
|
delete(pool.pending, addr)
|
||||||
|
pendingAddrsGauge.Dec(1)
|
||||||
}
|
}
|
||||||
// Postpone any invalidated transactions
|
// Postpone any invalidated transactions
|
||||||
for _, tx := range invalids {
|
for _, tx := range invalids {
|
||||||
|
|
@ -1580,6 +1585,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
|
||||||
// Delete the entire pending entry if it became empty.
|
// Delete the entire pending entry if it became empty.
|
||||||
if list.Empty() {
|
if list.Empty() {
|
||||||
delete(pool.pending, addr)
|
delete(pool.pending, addr)
|
||||||
|
pendingAddrsGauge.Dec(1)
|
||||||
if _, ok := pool.queue.get(addr); !ok {
|
if _, ok := pool.queue.get(addr); !ok {
|
||||||
pool.reserver.Release(addr)
|
pool.reserver.Release(addr)
|
||||||
}
|
}
|
||||||
|
|
@ -1844,6 +1850,8 @@ func (pool *LegacyPool) Clear() {
|
||||||
pendingGauge.Update(0)
|
pendingGauge.Update(0)
|
||||||
queuedGauge.Update(0)
|
queuedGauge.Update(0)
|
||||||
slotsGauge.Update(0)
|
slotsGauge.Update(0)
|
||||||
|
pendingAddrsGauge.Update(0)
|
||||||
|
queuedAddrsGauge.Update(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasPendingAuth returns a flag indicating whether there are pending
|
// HasPendingAuth returns a flag indicating whether there are pending
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ func (q *queue) remove(addr common.Address, tx *types.Transaction) {
|
||||||
if future.Empty() {
|
if future.Empty() {
|
||||||
delete(q.queued, addr)
|
delete(q.queued, addr)
|
||||||
delete(q.beats, addr)
|
delete(q.beats, addr)
|
||||||
|
queuedAddrsGauge.Dec(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -123,6 +124,7 @@ func (q *queue) add(tx *types.Transaction) (*common.Hash, error) {
|
||||||
from, _ := types.Sender(q.signer, tx) // already validated
|
from, _ := types.Sender(q.signer, tx) // already validated
|
||||||
if q.queued[from] == nil {
|
if q.queued[from] == nil {
|
||||||
q.queued[from] = newList(false)
|
q.queued[from] = newList(false)
|
||||||
|
queuedAddrsGauge.Inc(1)
|
||||||
}
|
}
|
||||||
inserted, old := q.queued[from].Add(tx, q.config.PriceBump)
|
inserted, old := q.queued[from].Add(tx, q.config.PriceBump)
|
||||||
if !inserted {
|
if !inserted {
|
||||||
|
|
@ -200,6 +202,7 @@ func (q *queue) promoteExecutables(accounts []common.Address, gasLimit uint64, c
|
||||||
if list.Empty() {
|
if list.Empty() {
|
||||||
delete(q.queued, addr)
|
delete(q.queued, addr)
|
||||||
delete(q.beats, addr)
|
delete(q.beats, addr)
|
||||||
|
queuedAddrsGauge.Dec(1)
|
||||||
removedAddresses = append(removedAddresses, addr)
|
removedAddresses = append(removedAddresses, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
go.mod
4
go.mod
|
|
@ -121,10 +121,12 @@ require (
|
||||||
github.com/golang/protobuf v1.5.4 // indirect
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
|
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
|
||||||
|
github.com/grafana/pyroscope-go v1.2.7
|
||||||
|
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 // indirect
|
||||||
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
|
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/kilic/bls12-381 v0.1.0 // indirect
|
github.com/kilic/bls12-381 v0.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.16.0 // indirect
|
github.com/klauspost/compress v1.17.8 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||||
github.com/kr/pretty v0.3.1 // indirect
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
|
|
||||||
10
go.sum
10
go.sum
|
|
@ -188,6 +188,10 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/grafana/pyroscope-go v1.2.7 h1:VWBBlqxjyR0Cwk2W6UrE8CdcdD80GOFNutj0Kb1T8ac=
|
||||||
|
github.com/grafana/pyroscope-go v1.2.7/go.mod h1:o/bpSLiJYYP6HQtvcoVKiE9s5RiNgjYTj1DhiddP2Pc=
|
||||||
|
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 h1:c1Us8i6eSmkW+Ez05d3co8kasnuOY813tbMN8i/a3Og=
|
||||||
|
github.com/grafana/pyroscope-go/godeltaprof v0.1.9/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
|
||||||
github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0=
|
github.com/graph-gophers/graphql-go v1.3.0 h1:Eb9x/q6MFpCLz7jBCiP/WTxjSDrYLR1QY41SORZyNJ0=
|
||||||
github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
|
github.com/graph-gophers/graphql-go v1.3.0/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
|
||||||
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
|
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
|
||||||
|
|
@ -223,8 +227,8 @@ github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4
|
||||||
github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig=
|
github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig=
|
||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4=
|
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
|
||||||
github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
|
|
@ -340,6 +344,8 @@ github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||||
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,11 @@ var Flags = []cli.Flag{
|
||||||
blockprofilerateFlag,
|
blockprofilerateFlag,
|
||||||
cpuprofileFlag,
|
cpuprofileFlag,
|
||||||
traceFlag,
|
traceFlag,
|
||||||
|
pyroscopeFlag,
|
||||||
|
pyroscopeServerFlag,
|
||||||
|
pyroscopeAuthUsernameFlag,
|
||||||
|
pyroscopeAuthPasswordFlag,
|
||||||
|
pyroscopeTagsFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -298,6 +303,14 @@ func Setup(ctx *cli.Context) error {
|
||||||
// It cannot be imported because it will cause a cyclical dependency.
|
// It cannot be imported because it will cause a cyclical dependency.
|
||||||
StartPProf(address, !ctx.IsSet("metrics.addr"))
|
StartPProf(address, !ctx.IsSet("metrics.addr"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pyroscope profiling
|
||||||
|
if ctx.Bool(pyroscopeFlag.Name) {
|
||||||
|
if err := startPyroscope(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(logFile) > 0 || rotation {
|
if len(logFile) > 0 || rotation {
|
||||||
log.Info("Logging configured", context...)
|
log.Info("Logging configured", context...)
|
||||||
}
|
}
|
||||||
|
|
@ -321,6 +334,7 @@ func StartPProf(address string, withMetrics bool) {
|
||||||
// Exit stops all running profiles, flushing their output to the
|
// Exit stops all running profiles, flushing their output to the
|
||||||
// respective file.
|
// respective file.
|
||||||
func Exit() {
|
func Exit() {
|
||||||
|
stopPyroscope()
|
||||||
Handler.StopCPUProfile()
|
Handler.StopCPUProfile()
|
||||||
Handler.StopGoTrace()
|
Handler.StopGoTrace()
|
||||||
if logOutputFile != nil {
|
if logOutputFile != nil {
|
||||||
|
|
|
||||||
134
internal/debug/pyroscope.go
Normal file
134
internal/debug/pyroscope.go
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
// Copyright 2026 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/internal/flags"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/grafana/pyroscope-go"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pyroscopeFlag = &cli.BoolFlag{
|
||||||
|
Name: "pyroscope",
|
||||||
|
Usage: "Enable Pyroscope profiling",
|
||||||
|
Value: false,
|
||||||
|
Category: flags.LoggingCategory,
|
||||||
|
}
|
||||||
|
pyroscopeServerFlag = &cli.StringFlag{
|
||||||
|
Name: "pyroscope.server",
|
||||||
|
Usage: "Pyroscope server URL to push profiling data to",
|
||||||
|
Value: "http://localhost:4040",
|
||||||
|
Category: flags.LoggingCategory,
|
||||||
|
}
|
||||||
|
pyroscopeAuthUsernameFlag = &cli.StringFlag{
|
||||||
|
Name: "pyroscope.username",
|
||||||
|
Usage: "Pyroscope basic authentication username",
|
||||||
|
Value: "",
|
||||||
|
Category: flags.LoggingCategory,
|
||||||
|
}
|
||||||
|
pyroscopeAuthPasswordFlag = &cli.StringFlag{
|
||||||
|
Name: "pyroscope.password",
|
||||||
|
Usage: "Pyroscope basic authentication password",
|
||||||
|
Value: "",
|
||||||
|
Category: flags.LoggingCategory,
|
||||||
|
}
|
||||||
|
pyroscopeTagsFlag = &cli.StringFlag{
|
||||||
|
Name: "pyroscope.tags",
|
||||||
|
Usage: "Comma separated list of key=value tags to add to profiling data",
|
||||||
|
Value: "",
|
||||||
|
Category: flags.LoggingCategory,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// This holds the globally-configured Pyroscope instance.
|
||||||
|
var pyroscopeProfiler *pyroscope.Profiler
|
||||||
|
|
||||||
|
func startPyroscope(ctx *cli.Context) error {
|
||||||
|
server := ctx.String(pyroscopeServerFlag.Name)
|
||||||
|
authUsername := ctx.String(pyroscopeAuthUsernameFlag.Name)
|
||||||
|
authPassword := ctx.String(pyroscopeAuthPasswordFlag.Name)
|
||||||
|
|
||||||
|
rawTags := ctx.String(pyroscopeTagsFlag.Name)
|
||||||
|
tags := make(map[string]string)
|
||||||
|
for tag := range strings.SplitSeq(rawTags, ",") {
|
||||||
|
tag = strings.TrimSpace(tag)
|
||||||
|
if tag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
k, v, _ := strings.Cut(tag, "=")
|
||||||
|
tags[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
config := pyroscope.Config{
|
||||||
|
ApplicationName: "geth",
|
||||||
|
ServerAddress: server,
|
||||||
|
BasicAuthUser: authUsername,
|
||||||
|
BasicAuthPassword: authPassword,
|
||||||
|
Logger: &pyroscopeLogger{Logger: log.Root()},
|
||||||
|
Tags: tags,
|
||||||
|
ProfileTypes: []pyroscope.ProfileType{
|
||||||
|
// Enabling all profile types
|
||||||
|
pyroscope.ProfileCPU,
|
||||||
|
pyroscope.ProfileAllocObjects,
|
||||||
|
pyroscope.ProfileAllocSpace,
|
||||||
|
pyroscope.ProfileInuseObjects,
|
||||||
|
pyroscope.ProfileInuseSpace,
|
||||||
|
pyroscope.ProfileGoroutines,
|
||||||
|
pyroscope.ProfileMutexCount,
|
||||||
|
pyroscope.ProfileMutexDuration,
|
||||||
|
pyroscope.ProfileBlockCount,
|
||||||
|
pyroscope.ProfileBlockDuration,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
profiler, err := pyroscope.Start(config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pyroscopeProfiler = profiler
|
||||||
|
log.Info("Enabled Pyroscope")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopPyroscope() {
|
||||||
|
if pyroscopeProfiler != nil {
|
||||||
|
pyroscopeProfiler.Stop()
|
||||||
|
pyroscopeProfiler = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Small wrapper for log.Logger to satisfy pyroscope.Logger interface
|
||||||
|
type pyroscopeLogger struct {
|
||||||
|
Logger log.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *pyroscopeLogger) Infof(format string, v ...any) {
|
||||||
|
l.Logger.Info(fmt.Sprintf("Pyroscope: "+format, v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *pyroscopeLogger) Debugf(format string, v ...any) {
|
||||||
|
l.Logger.Debug(fmt.Sprintf("Pyroscope: "+format, v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *pyroscopeLogger) Errorf(format string, v ...any) {
|
||||||
|
l.Logger.Error(fmt.Sprintf("Pyroscope: "+format, v...))
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue