core: improve mgasps meter

This commit is contained in:
Gary Rong 2025-06-12 14:53:13 +08:00
parent f1eee7f7f5
commit e5098e9283
2 changed files with 2 additions and 6 deletions

View file

@ -66,8 +66,7 @@ var (
headSafeBlockGauge = metrics.NewRegisteredGauge("chain/head/safe", nil) headSafeBlockGauge = metrics.NewRegisteredGauge("chain/head/safe", nil)
chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil) chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil)
chainMgaspsGauge = metrics.NewRegisteredGauge("chain/mgasps", nil) chainMgaspsMeter = metrics.NewRegisteredMeter("chain/mgasps", nil)
chainGasCounter = metrics.NewRegisteredCounter("chain/gas/total", nil)
accountReadTimer = metrics.NewRegisteredResettingTimer("chain/account/reads", nil) accountReadTimer = metrics.NewRegisteredResettingTimer("chain/account/reads", nil)
accountHashTimer = metrics.NewRegisteredResettingTimer("chain/account/hashes", nil) accountHashTimer = metrics.NewRegisteredResettingTimer("chain/account/hashes", nil)
@ -1845,7 +1844,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness
// Report the import stats before returning the various results // Report the import stats before returning the various results
stats.processed++ stats.processed++
stats.usedGas += res.usedGas stats.usedGas += res.usedGas
chainGasCounter.Inc(int64(res.usedGas))
witness = res.witness witness = res.witness
var snapDiffItems, snapBufItems common.StorageSize var snapDiffItems, snapBufItems common.StorageSize
@ -2070,6 +2068,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
blockWriteTimer.Update(time.Since(wstart) - max(statedb.AccountCommits, statedb.StorageCommits) /* concurrent */ - statedb.SnapshotCommits - statedb.TrieDBCommits) blockWriteTimer.Update(time.Since(wstart) - max(statedb.AccountCommits, statedb.StorageCommits) /* concurrent */ - statedb.SnapshotCommits - statedb.TrieDBCommits)
blockInsertTimer.UpdateSince(startTime) blockInsertTimer.UpdateSince(startTime)
chainMgaspsMeter.Mark(int64(float64(res.GasUsed) / 1000_000))
return &blockProcessingResult{ return &blockProcessingResult{
usedGas: res.GasUsed, usedGas: res.GasUsed,

View file

@ -46,9 +46,6 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn
elapsed = now.Sub(st.startTime) + 1 // prevent zero division elapsed = now.Sub(st.startTime) + 1 // prevent zero division
mgasps = float64(st.usedGas) * 1000 / float64(elapsed) mgasps = float64(st.usedGas) * 1000 / float64(elapsed)
) )
// Update the Mgas per second gauge
chainMgaspsGauge.Update(int64(mgasps))
// If we're at the last block of the batch or report period reached, log // If we're at the last block of the batch or report period reached, log
if index == len(chain)-1 || elapsed >= statsReportLimit { if index == len(chain)-1 || elapsed >= statsReportLimit {
// Count the number of transactions in this segment // Count the number of transactions in this segment