From 49e16e7e6b5e5e3662a75816c399c1cf4db66fba Mon Sep 17 00:00:00 2001 From: Monkey Date: Thu, 22 May 2025 00:36:55 +0800 Subject: [PATCH] add gas used ratio --- core/blockchain.go | 1 + core/blockchain_insert.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index 64345bc1a3..daa32f47e5 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1844,6 +1844,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness // Report the import stats before returning the various results stats.processed++ stats.usedGas += res.usedGas + stats.gasLimit += block.GasLimit() witness = res.witness var snapDiffItems, snapBufItems common.StorageSize diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index 695aa6679b..f023936d5a 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -17,6 +17,7 @@ package core import ( + "fmt" "time" "github.com/ethereum/go-ethereum/common" @@ -29,6 +30,7 @@ import ( type insertStats struct { queued, processed, ignored int usedGas uint64 + gasLimit uint64 lastIndex int startTime mclock.AbsTime } @@ -45,6 +47,7 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn now = mclock.Now() elapsed = now.Sub(st.startTime) + 1 // prevent zero division mgasps = float64(st.usedGas) * 1000 / float64(elapsed) + gasUsed = fmt.Sprintf("%.2f%%", float64(st.usedGas)/float64(st.gasLimit)*100) ) // Update the Mgas per second gauge chainMgaspsGauge.Update(int64(mgasps)) @@ -62,7 +65,7 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn context := []interface{}{ "number", end.Number(), "hash", end.Hash(), "blocks", st.processed, "txs", txs, "mgas", float64(st.usedGas) / 1000000, - "elapsed", common.PrettyDuration(elapsed), "mgasps", mgasps, + "elapsed", common.PrettyDuration(elapsed), "mgasps", mgasps, "gasused", gasUsed, } if timestamp := time.Unix(int64(end.Time()), 0); time.Since(timestamp) > time.Minute { context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)