OSDN Git Service

add performance test point performance
authorpaladz <colt@ColtdeMBP.partners>
Thu, 29 Oct 2020 11:44:03 +0000 (19:44 +0800)
committerpaladz <colt@ColtdeMBP.partners>
Thu, 29 Oct 2020 11:44:03 +0000 (19:44 +0800)
application/mov/mov_core.go
database/store.go
proposal/proposal.go
protocol/bbft.go
protocol/block.go
protocol/consensus_node_manager.go
protocol/protocol.go
protocol/state/utxo_view.go
protocol/validation/block.go
protocol/validation/tx.go

index 2980553..b2adc06 100644 (file)
@@ -14,6 +14,7 @@ import (
        "github.com/bytom/vapor/protocol"
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/bc/types"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 var (
@@ -53,6 +54,9 @@ func NewCoreWithDB(store *database.LevelDBMovStore, startBlockHeight uint64) *Co
 // ApplyBlock parse pending order and cancel from the the transactions of block
 // and add pending order to the dex db, remove cancel order from dex db.
 func (m *Core) ApplyBlock(block *types.Block) error {
+       measure.Start()
+       defer measure.End()
+
        if block.Height < m.startBlockHeight {
                return nil
        }
@@ -175,6 +179,9 @@ func (m *Core) StartHeight() uint64 {
 // ValidateBlock no need to verify the block header, because the first module has been verified.
 // just need to verify the transactions in the block.
 func (m *Core) ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error {
+       measure.Start()
+       defer measure.End()
+
        for i, tx := range block.Transactions {
                if err := m.ValidateTx(tx, verifyResults[i], block.Height); err != nil {
                        return err
index 4ffc65d..26cb74b 100644 (file)
@@ -16,6 +16,7 @@ import (
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/bc/types"
        "github.com/bytom/vapor/protocol/state"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 const (
@@ -285,6 +286,9 @@ func (s *Store) GetStoreStatus() *protocol.BlockStoreState {
 
 // GetTransactionsUtxo will return all the utxo that related to the input txs
 func (s *Store) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) error {
+       measure.Start()
+       defer measure.End()
+
        return getTransactionsUtxo(s.db, view, txs)
 }
 
@@ -314,6 +318,9 @@ func (s *Store) GetConsensusResult(seq uint64) (*state.ConsensusResult, error) {
 
 // SaveBlock persists a new block in the protocol.
 func (s *Store) SaveBlock(block *types.Block, ts *bc.TransactionStatus) error {
+       measure.Start()
+       defer measure.End()
+
        startTime := time.Now()
        binaryBlockHeader, err := block.MarshalTextForBlockHeader()
        if err != nil {
index 2832c9b..255008e 100644 (file)
@@ -17,6 +17,7 @@ import (
        "github.com/bytom/vapor/protocol/state"
        "github.com/bytom/vapor/protocol/validation"
        "github.com/bytom/vapor/protocol/vm/vmutil"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 const (
@@ -49,6 +50,9 @@ type blockBuilder struct {
 }
 
 func newBlockBuilder(chain *protocol.Chain, accountManager *account.Manager, timestamp uint64, warnDuration, criticalDuration time.Duration) *blockBuilder {
+       measure.Start()
+       defer measure.End()
+
        preBlockHeader := chain.BestBlockHeader()
        block := &types.Block{
                BlockHeader: types.BlockHeader{
@@ -96,6 +100,9 @@ func (b *blockBuilder) applyCoinbaseTransaction() error {
 }
 
 func (b *blockBuilder) applyTransactions(txs []*types.Tx, timeoutStatus uint8) error {
+       measure.Start()
+       defer measure.End()
+
        tempTxs := []*types.Tx{}
        for i := 0; i < len(txs); i++ {
                if tempTxs = append(tempTxs, txs[i]); len(tempTxs) < batchApplyNum && i != len(txs)-1 {
@@ -127,6 +134,9 @@ func (b *blockBuilder) applyTransactions(txs []*types.Tx, timeoutStatus uint8) e
 }
 
 func (b *blockBuilder) applyTransactionFromPool() error {
+       measure.Start()
+       defer measure.End()
+
        txDescList := b.chain.GetTxPool().GetTransactions()
        sort.Sort(byTime(txDescList))
 
@@ -139,6 +149,9 @@ func (b *blockBuilder) applyTransactionFromPool() error {
 }
 
 func (b *blockBuilder) applyTransactionFromSubProtocol() error {
+       measure.Start()
+       defer measure.End()
+
        isTimeout := func() bool {
                return b.getTimeoutStatus() > timeoutOk
        }
@@ -162,6 +175,9 @@ func (b *blockBuilder) applyTransactionFromSubProtocol() error {
 }
 
 func (b *blockBuilder) build() (*types.Block, error) {
+       measure.Start()
+       defer measure.End()
+
        if err := b.applyCoinbaseTransaction(); err != nil {
                return nil, err
        }
@@ -186,6 +202,9 @@ func (b *blockBuilder) build() (*types.Block, error) {
 }
 
 func (b *blockBuilder) calcBlockCommitment() (err error) {
+       measure.Start()
+       defer measure.End()
+
        var txEntries []*bc.Tx
        for _, tx := range b.block.Transactions {
                txEntries = append(txEntries, tx.Tx)
@@ -290,6 +309,9 @@ type validateTxResult struct {
 }
 
 func (b *blockBuilder) preValidateTxs(txs []*types.Tx, chain *protocol.Chain, view *state.UtxoViewpoint, gasLeft int64) ([]*validateTxResult, int64) {
+       measure.Start()
+       defer measure.End()
+
        var results []*validateTxResult
        bcBlock := &bc.Block{BlockHeader: &bc.BlockHeader{Height: chain.BestBlockHeight() + 1}}
        bcTxs := make([]*bc.Tx, len(txs))
@@ -335,6 +357,9 @@ func (b *blockBuilder) preValidateTxs(txs []*types.Tx, chain *protocol.Chain, vi
 }
 
 func (b *blockBuilder) validateBySubProtocols(tx *types.Tx, statusFail bool, subProtocols []protocol.SubProtocol) error {
+       measure.Start()
+       defer measure.End()
+
        for _, subProtocol := range subProtocols {
                verifyResult := &bc.TxVerifyResult{StatusFail: statusFail}
                if err := subProtocol.ValidateTx(tx, verifyResult, b.block.Height); err != nil {
index e1fa489..f4f5886 100644 (file)
@@ -13,6 +13,7 @@ import (
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/bc/types"
        "github.com/bytom/vapor/protocol/state"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 const (
@@ -116,6 +117,9 @@ func (c *Chain) updateBlockSignature(blockHeader *types.BlockHeader, nodeOrder u
 // if some signature is invalid, they will be reset to nil
 // if the block does not have the signature of blocker, it will return error
 func (c *Chain) validateSign(block *types.Block) error {
+       measure.Start()
+       defer measure.End()
+
        consensusNodeMap, err := c.getConsensusNodes(&block.PreviousBlockHash)
        if err != nil {
                return err
@@ -215,6 +219,9 @@ func (c *Chain) SignBlockHeader(blockHeader *types.BlockHeader) error {
 }
 
 func (c *Chain) applyBlockSign(blockHeader *types.BlockHeader) error {
+       measure.Start()
+       defer measure.End()
+
        signature, err := c.signBlockHeader(blockHeader)
        if err != nil {
                return err
index 862c01a..3bf42d8 100644 (file)
@@ -8,6 +8,7 @@ import (
        "github.com/bytom/vapor/protocol/bc/types"
        "github.com/bytom/vapor/protocol/state"
        "github.com/bytom/vapor/protocol/validation"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 var (
@@ -87,6 +88,9 @@ func (c *Chain) calcReorganizeChain(beginAttach *types.BlockHeader, beginDetach
 }
 
 func (c *Chain) connectBlock(block *types.Block) (err error) {
+       measure.Start()
+       defer measure.End()
+
        bcBlock := types.MapBlock(block)
        if bcBlock.TransactionStatus, err = c.store.GetTransactionStatus(&bcBlock.ID); err != nil {
                return err
@@ -362,6 +366,9 @@ func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
 
 // SaveBlock will validate and save block into storage
 func (c *Chain) saveBlock(block *types.Block) error {
+       measure.Start()
+       defer measure.End()
+
        if err := c.validateSign(block); err != nil {
                return errors.Sub(ErrBadBlock, err)
        }
@@ -453,6 +460,9 @@ func (c *Chain) blockProcesser() {
 
 // ProcessBlock is the entry for handle block insert
 func (c *Chain) processBlock(block *types.Block) (bool, error) {
+       measure.Start()
+       defer measure.End()
+
        blockHash := block.Hash()
        if c.BlockExist(&blockHash) {
                log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Debug("block has been processed")
index 6b4668e..9c43dc4 100644 (file)
@@ -6,6 +6,7 @@ import (
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/bc/types"
        "github.com/bytom/vapor/protocol/state"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 var (
@@ -14,6 +15,9 @@ var (
 )
 
 func (c *Chain) getBestConsensusResult() (*state.ConsensusResult, error) {
+       measure.Start()
+       defer measure.End()
+
        bestBlockHeader := c.bestBlockHeader
        seq := state.CalcVoteSeq(bestBlockHeader.Height)
        return c.getConsensusResult(seq, bestBlockHeader)
index 50e0d59..d257575 100644 (file)
@@ -12,6 +12,7 @@ import (
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/bc/types"
        "github.com/bytom/vapor/protocol/state"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 const (
@@ -279,6 +280,9 @@ func (c *Chain) syncProtocolStatus(subProtocol SubProtocol) error {
 
 // This function must be called with mu lock in above level
 func (c *Chain) setState(blockHeader, irrBlockHeader *types.BlockHeader, mainBlockHeaders []*types.BlockHeader, view *state.UtxoViewpoint, consensusResults []*state.ConsensusResult) error {
+       measure.Start()
+       defer measure.End()
+
        if err := c.store.SaveChainStatus(blockHeader, irrBlockHeader, mainBlockHeaders, view, consensusResults); err != nil {
                return err
        }
index 98556f0..5f5c105 100644 (file)
@@ -5,6 +5,7 @@ import (
        "github.com/bytom/vapor/database/storage"
        "github.com/bytom/vapor/errors"
        "github.com/bytom/vapor/protocol/bc"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 // UtxoViewpoint represents a view into the set of unspent transaction outputs
@@ -32,6 +33,9 @@ func (view *UtxoViewpoint) ApplyTransaction(block *bc.Block, tx *bc.Tx, statusFa
 }
 
 func (view *UtxoViewpoint) ApplyBlock(block *bc.Block, txStatus *bc.TransactionStatus) error {
+       measure.Start()
+       defer measure.End()
+
        for i, tx := range block.Transactions {
                statusFail, err := txStatus.GetStatus(i)
                if err != nil {
index 4292014..d35628c 100644 (file)
@@ -12,6 +12,7 @@ import (
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/bc/types"
        "github.com/bytom/vapor/protocol/state"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 const logModule = "leveldb"
@@ -88,6 +89,9 @@ func ValidateBlockHeader(b *bc.Block, parent *types.BlockHeader) error {
 
 // ValidateBlock validates a block and the transactions within.
 func ValidateBlock(b *bc.Block, parent *types.BlockHeader, rewards []state.CoinbaseReward) error {
+       measure.Start()
+       defer measure.End()
+
        startTime := time.Now()
        if err := ValidateBlockHeader(b, parent); err != nil {
                return err
index 44287e9..9edad32 100644 (file)
@@ -13,6 +13,7 @@ import (
        "github.com/bytom/vapor/math/checked"
        "github.com/bytom/vapor/protocol/bc"
        "github.com/bytom/vapor/protocol/vm"
+       "github.com/bytom/vapor/toolbar/measure"
 )
 
 // validate transaction error
@@ -664,6 +665,9 @@ func validateTxWorker(workCh chan *validateTxWork, resultCh chan *ValidateTxResu
 
 // ValidateTxs validates txs in async mode
 func ValidateTxs(txs []*bc.Tx, block *bc.Block) []*ValidateTxResult {
+       measure.Start()
+       defer measure.End()
+
        txSize := len(txs)
        validateWorkerNum := runtime.NumCPU()
        //init the goroutine validate worker