Skip to content

Commit 878f2f5

Browse files
committed
core/blockchain: add more detailed metrics for block processing
1 parent 2a113f6 commit 878f2f5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/blockchain.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ import (
4747
)
4848

4949
var (
50-
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
50+
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
51+
blockValidationTimer = metrics.NewRegisteredTimer("chain/validation", nil)
52+
blockExecutionTimer = metrics.NewRegisteredTimer("chain/execution", nil)
53+
blockWriteTimer = metrics.NewRegisteredTimer("chain/write", nil)
5154

5255
ErrNoGenesis = errors.New("Genesis not found in chain")
5356
)
@@ -1188,7 +1191,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
11881191
return it.index, events, coalescedLogs, err
11891192
}
11901193
// Process block using the parent state as reference point.
1194+
t0 := time.Now()
11911195
receipts, logs, usedGas, err := bc.processor.Process(block, state, bc.vmConfig)
1196+
t1 := time.Now()
11921197
if err != nil {
11931198
bc.reportBlock(block, receipts, err)
11941199
return it.index, events, coalescedLogs, err
@@ -1198,13 +1203,19 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
11981203
bc.reportBlock(block, receipts, err)
11991204
return it.index, events, coalescedLogs, err
12001205
}
1206+
t2 := time.Now()
12011207
proctime := time.Since(start)
12021208

12031209
// Write the block to the chain and get the status.
12041210
status, err := bc.WriteBlockWithState(block, receipts, state)
1211+
t3 := time.Now()
12051212
if err != nil {
12061213
return it.index, events, coalescedLogs, err
12071214
}
1215+
blockInsertTimer.UpdateSince(start)
1216+
blockExecutionTimer.Update(t1.Sub(t0))
1217+
blockValidationTimer.Update(t2.Sub(t1))
1218+
blockWriteTimer.Update(t3.Sub(t2))
12081219
switch status {
12091220
case CanonStatTy:
12101221
log.Debug("Inserted new block", "number", block.Number(), "hash", block.Hash(),

0 commit comments

Comments
 (0)