Skip to content

Commit a7e59dd

Browse files
seanl-circlerjl493456442
authored andcommitted
metrics: add chain/gas for cumulative gas usage (ethereum#32004)
This is a followup to ethereum#31753. A cumulative counter is more useful when we need to measure / aggregate the metric over a longer period of time. It also means we won't miss data, e.g. our prometheus scrapes every 30 seconds, and so may miss a transient spike in the pre-aggregated mgas/s. --------- Co-authored-by: Gary Rong <[email protected]>
1 parent 94a7624 commit a7e59dd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

core/blockchain.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var (
6666
headSafeBlockGauge = metrics.NewRegisteredGauge("chain/head/safe", nil)
6767

6868
chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil)
69-
chainMgaspsGauge = metrics.NewRegisteredGauge("chain/mgasps", nil)
69+
chainMgaspsMeter = metrics.NewRegisteredResettingTimer("chain/mgasps", nil)
7070

7171
accountReadTimer = metrics.NewRegisteredResettingTimer("chain/account/reads", nil)
7272
accountHashTimer = metrics.NewRegisteredResettingTimer("chain/account/hashes", nil)
@@ -2067,7 +2067,12 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
20672067
triedbCommitTimer.Update(statedb.TrieDBCommits) // Trie database commits are complete, we can mark them
20682068

20692069
blockWriteTimer.Update(time.Since(wstart) - max(statedb.AccountCommits, statedb.StorageCommits) /* concurrent */ - statedb.SnapshotCommits - statedb.TrieDBCommits)
2070-
blockInsertTimer.UpdateSince(startTime)
2070+
elapsed := time.Since(startTime) + 1 // prevent zero division
2071+
blockInsertTimer.Update(elapsed)
2072+
2073+
// TODO(rjl493456442) generalize the ResettingTimer
2074+
mgasps := float64(res.GasUsed) * 1000 / float64(elapsed)
2075+
chainMgaspsMeter.Update(time.Duration(mgasps))
20712076

20722077
return &blockProcessingResult{
20732078
usedGas: res.GasUsed,

core/blockchain_insert.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn
4646
elapsed = now.Sub(st.startTime) + 1 // prevent zero division
4747
mgasps = float64(st.usedGas) * 1000 / float64(elapsed)
4848
)
49-
// Update the Mgas per second gauge
50-
chainMgaspsGauge.Update(int64(mgasps))
51-
5249
// If we're at the last block of the batch or report period reached, log
5350
if index == len(chain)-1 || elapsed >= statsReportLimit {
5451
// Count the number of transactions in this segment

0 commit comments

Comments
 (0)