Skip to content

Commit

Permalink
add dump time cost logs
Browse files Browse the repository at this point in the history
  • Loading branch information
HanWang233 committed Jul 27, 2022
1 parent 0f11ed6 commit a666c09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package core

import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
Expand All @@ -26,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"math/big"
)

// StateProcessor is a basic Processor, which takes care of transitioning
Expand Down Expand Up @@ -56,6 +59,9 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
// returns the amount of gas that was used in the process. If any of the
// transactions failed to execute due to insufficient gas it will return an error.
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) {
defer func(start time.Time) {
fmt.Printf("Execution state_process, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), time.Since(start))
}(time.Now())
var (
receipts types.Receipts
usedGas = new(uint64)
Expand All @@ -65,7 +71,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
allLogs []*types.Log
gp = new(GasPool).AddGas(block.GasLimit())
)

vm.BlockDumpLogger(block, 10000, 100)

parityLogContext := vm.ParityLogContext{
Expand Down Expand Up @@ -98,6 +103,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
blockContext := NewEVMBlockContext(header, p.bc, nil)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
// Iterate over and process the individual transactions
var totalts time.Duration = 0.0
for i, tx := range block.Transactions() {
parityLogContext.TxPos = i
parityLogContext.TxHash = tx.Hash()
Expand All @@ -111,12 +117,19 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}

txstart := time.Now()
if err := txLogger.Dump(i, tx, receipt); err != nil {
return nil, nil, 0, fmt.Errorf("could not dump tx %d [%v] logger: %w", i, tx.Hash().Hex(), err)
}

totalts += time.Since(txstart)

receipts = append(receipts, receipt)
allLogs = append(allLogs, receipt.Logs...)
}

fmt.Printf("Dump transaction, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), totalts.Seconds())
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
vm.ReceiptDumpLogger(block.NumberU64(), 10000, 100, receipts)
Expand Down
6 changes: 6 additions & 0 deletions core/vm/dump_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ func (l *ParityLogger) CaptureExit(output []byte, gasUsed uint64, err error) {
}

func ReceiptDumpLogger(blockNumber uint64, perFolder, perFile uint64, receipts types.Receipts) error {
defer func(start time.Time) {
fmt.Printf("Dump receipt, block_number = %v ,cost time = %v\n", strconv.FormatUint(blockNumber, 10), time.Since(start))
}(time.Now())
file, err := getFile("receipts", blockNumber, perFolder, perFile)
if err != nil {
return err
Expand Down Expand Up @@ -330,6 +333,9 @@ func (t *TxLogger) Close() error {
}

func BlockDumpLogger(block *types.Block, perFolder, perFile uint64) error {
defer func(start time.Time) {
fmt.Printf("Dump blocks, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), time.Since(start))
}(time.Now())
file, err := getFile("blocks", block.NumberU64(), perFolder, perFile)
if err != nil {
return err
Expand Down

0 comments on commit a666c09

Please sign in to comment.