Skip to content

Commit

Permalink
more timer
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Feb 19, 2024
1 parent be4870d commit ff1aed2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
16 changes: 12 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
continue
}
preProcessDur = time.Since(preprocessBegin)

varDeclBegin := time.Now()
var (
err error
receipts, receiptExist = bc.miningReceiptsCache.Get(block.Hash())
Expand All @@ -1830,12 +1832,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
)

interruptCh := make(chan struct{})
pstart := time.Now()
varDeclDur := time.Since(varDeclBegin)

pstart := time.Now()
steps := 0
var processPrepareDur time.Duration
var processDur time.Duration
// skip block process if we already have the state, receipts and logs from mining work
if !(receiptExist && logExist && stateExist) {
processPrepareBegin := time.Now()
// Retrieve the parent block and it's state to execute on top
parent := it.previous()
if parent == nil {
Expand Down Expand Up @@ -1869,6 +1874,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
}(time.Now(), followup, throwaway, vmc)
}
}
processPrepareDur = time.Since(processPrepareBegin)

steps = 0

vmcount.Debug = bc.vmConfig.Debug
Expand All @@ -1886,6 +1893,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
// Process block using the parent state as reference point
receipts, logs, usedGas, err = bc.processor.Process(block, statedb, *vmcount)
processDur = time.Since(processBegin)

if oldTracer == nil {
steps = tracer.Steps()
tracer.Reset()
Expand All @@ -1908,8 +1916,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
return it.index, err
}
validateDur := time.Since(validateStart)
vtime := time.Since(vstart)

vtime := time.Since(vstart)
proctime := time.Since(start) // processing + validation

metricsUpdateStart := time.Now()
Expand Down Expand Up @@ -1982,14 +1990,14 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
ptime, steps, processDur,
validateDur, metricsUpdateTime,
writeDur, cacheBlockDur, metricsUpdateTime1,
preProcessDur, postProcessDur)
preProcessDur, postProcessDur, varDeclDur, processPrepareDur)

postProcessBegin := time.Now()
if !setHead {
// After merge we expect few side chains. Simply count
// all blocks the CL gives us for GC processing time
bc.gcproc += proctime

postProcessDur = time.Since(postProcessBegin)
return it.index, nil // Direct block insertion of a single block
}
switch status {
Expand Down
8 changes: 7 additions & 1 deletion core/blockchain_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ const statsReportLimit = 1 * time.Nanosecond

// report prints statistics if some number of blocks have been processed
// or more than a few seconds have passed since the last message.
func (st *insertStats) report(chain []*types.Block, index int, dirty common.StorageSize, setHead bool, execTime time.Duration, steps int, processDur time.Duration, validateDur time.Duration, metricUpdateTime1 time.Duration, writeDur time.Duration, cacheDur time.Duration, metricUpdateTime2 time.Duration, preProcessDur time.Duration, postProcessDur time.Duration) {
func (st *insertStats) report(chain []*types.Block, index int,
dirty common.StorageSize, setHead bool, execTime time.Duration, steps int,
processDur time.Duration, validateDur time.Duration, metricUpdateTime1 time.Duration,
writeDur time.Duration, cacheDur time.Duration, metricUpdateTime2 time.Duration,
preProcessDur time.Duration, postProcessDur time.Duration, varDeclDuration time.Duration, processPrepareDur time.Duration) {
// Fetch the timings for the batch
var (
now = mclock.Now()
Expand All @@ -61,6 +65,8 @@ func (st *insertStats) report(chain []*types.Block, index int, dirty common.Stor
"elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed),
"execTime", common.PrettyDuration(execTime), "execPercent", float64(execTime) / float64(elapsed),
"steps", steps,
"varDeclDur", common.PrettyDuration(varDeclDuration), "valDeclDurPercent", float64(varDeclDuration) / float64(elapsed),
"processPrepareDur", common.PrettyDuration(processPrepareDur), "processPrepareDurPercent", float64(processPrepareDur) / float64(elapsed),
"processDur", common.PrettyDuration(processDur), "processDurPercent", float64(processDur) / float64(elapsed),
"validateDur", common.PrettyDuration(validateDur), "validateDurPercent", float64(validateDur) / float64(elapsed),
"metricUpdate1", common.PrettyDuration(metricUpdateTime1), "metricUpdate1Percent", float64(metricUpdateTime1) / float64(elapsed),
Expand Down
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
ret, err = evm.interpreter.Run(contract, input, false)

interpreterRunTime := time.Since(getCodeBegin) - getCodeTime
log.Info("Inside Interpreter (gasps)", "getCodeDuration", common.PrettyDuration(getCodeTime), "RunDuration", common.PrettyDuration(interpreterRunTime), "cacheHit", hit)
log.Info("Inside Interpreter (gasps)", "depth", evm.depth, "getCodeDuration", common.PrettyDuration(getCodeTime), "RunDuration", common.PrettyDuration(interpreterRunTime), "cacheHit", hit)

gas = contract.Gas
}
Expand Down
5 changes: 5 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package vm

import (
"github.com/ethereum/go-ethereum/core/vm/compiler"
"github.com/ethereum/go-ethereum/log"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -374,7 +376,10 @@ func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
if interpreter.evm.Config.EnableOpcodeOptimizations && scope.Contract.optimized {
if scope.Contract.RawCode == nil || len(scope.Contract.RawCode) == 0 {
// if we have optimization, get rawCode from DB.
getCodeBegin := time.Now()
scope.Contract.RawCode = interpreter.evm.StateDB.GetCode(*scope.Contract.CodeAddr)
getCodeDur := time.Since(getCodeBegin)
log.Warn("opCodeCopy getRawCode (gasps)", "Duration", common.PrettyDuration(getCodeDur))
}
contractRawCode = scope.Contract.RawCode
}
Expand Down

0 comments on commit ff1aed2

Please sign in to comment.