Skip to content

core: add gas used ratio in the inserting report log #31872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion core/blockchain_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -29,6 +30,7 @@ import (
type insertStats struct {
queued, processed, ignored int
usedGas uint64
gasLimit uint64
lastIndex int
startTime mclock.AbsTime
}
Expand All @@ -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))
Expand All @@ -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)}...)
Expand Down