Commit 3ea9dc69 authored by Lucas Kuhring's avatar Lucas Kuhring
Browse files

Add logging for measurements

parent 4d304de4
package config
import (
"encoding/json"
"errors"
"fmt"
"os"
)
var Log LogConfig
type LogConfig struct {
Validation bool
Endorsement bool
Ordering bool
FullCommit bool
}
func ReadConfig(path string) error {
file, err := os.Open(path)
if err != nil {
return errors.New("No config file found")
}
defer file.Close()
dec := json.NewDecoder(file)
lc := LogConfig{}
if err := dec.Decode(&lc); err != nil {
Log = LogConfig{false, false, false, false}
return err
}
Log = lc
fmt.Printf("Log config loaded: %t\n", Log)
return nil
}
{
"Validation": true,
"Endorsement": false,
"Ordering": false,
"FullCommit": false
}
\ No newline at end of file
...@@ -7,10 +7,15 @@ SPDX-License-Identifier: Apache-2.0 ...@@ -7,10 +7,15 @@ SPDX-License-Identifier: Apache-2.0
package committer package committer
import ( import (
"fmt"
"strconv"
"time"
"github.com/hyperledger/fabric/common/flogging" "github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/core/ledger" "github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric/protos/utils"
"github.com/hyperledger/fabric_org/config"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
...@@ -94,6 +99,24 @@ func (lc *LedgerCommitter) CommitWithPvtData(blockAndPvtData *ledger.BlockAndPvt ...@@ -94,6 +99,24 @@ func (lc *LedgerCommitter) CommitWithPvtData(blockAndPvtData *ledger.BlockAndPvt
return err return err
} }
if config.Log.FullCommit {
/*
txData := blockAndPvtData.Block.Data.Data[0]
msg, _ := utils.UnmarshalEnvelope(txData)
payload, _ := utils.UnmarshalPayload(msg.Payload)
hdr := payload.GetHeader()
chdr, _ := utils.UnmarshalChannelHeader(hdr.ChannelHeader)
firstTransaction := chdr.TxId
*/
//fmt.Printf("{\"ts\":" + strconv.FormatInt(time.Now().UnixNano(), 10) + ",\"msg\":\"FABRIC PERF Validation\",\"block\":\"" + strconv.Itoa(int(blockAndPvtData.Block.GetHeader().GetNumber())) + "\",\"STEP\":3}\n")
fmt.Printf(strconv.FormatInt(time.Now().UnixNano(), 10) + "," + strconv.Itoa(int(blockAndPvtData.Block.GetHeader().GetNumber())) + " (Step 3)\n")
}
if config.Log.Validation {
fmt.Println("val1," + strconv.Itoa(int(blockAndPvtData.Block.GetHeader().GetNumber())) + "," + strconv.FormatInt(time.Now().UnixNano(), 10))
}
return nil return nil
} }
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
pb "github.com/hyperledger/fabric/protos/peer" pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/transientstore" "github.com/hyperledger/fabric/protos/transientstore"
putils "github.com/hyperledger/fabric/protos/utils" putils "github.com/hyperledger/fabric/protos/utils"
"github.com/hyperledger/fabric_org/config"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
) )
...@@ -445,6 +446,10 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro ...@@ -445,6 +446,10 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
e.Metrics.ProposalDuration.With(meterLabels...).Observe(time.Since(startTime).Seconds()) e.Metrics.ProposalDuration.With(meterLabels...).Observe(time.Since(startTime).Seconds())
} }
if config.Log.Endorsement {
fmt.Printf("%d,%f\n", time.Now().UnixNano()/1000000, time.Since(startTime).Seconds()*1000)
}
endorserLogger.Debug("Exit: request from", addr) endorserLogger.Debug("Exit: request from", addr)
}() }()
......
...@@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0 ...@@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package kvledger package kvledger
import ( import (
"fmt"
"strconv"
"sync" "sync"
"time" "time"
...@@ -26,6 +28,7 @@ import ( ...@@ -26,6 +28,7 @@ import (
"github.com/hyperledger/fabric/core/ledger/pvtdatapolicy" "github.com/hyperledger/fabric/core/ledger/pvtdatapolicy"
"github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer" "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric_org/config"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
...@@ -303,6 +306,12 @@ func (l *kvLedger) CommitWithPvtData(pvtdataAndBlock *ledger.BlockAndPvtData) er ...@@ -303,6 +306,12 @@ func (l *kvLedger) CommitWithPvtData(pvtdataAndBlock *ledger.BlockAndPvtData) er
if err != nil { if err != nil {
return err return err
} }
if config.Log.FullCommit {
//fmt.Printf("{\"ts\":" + strconv.FormatInt(time.Now().UnixNano(), 10) + ",\"msg\":\"FABRIC PERF Validation\",\"block\":" + strconv.Itoa(int(blockNo)) + ",\"STEP\":2}\n")
fmt.Printf(strconv.FormatInt(time.Now().UnixNano(), 10) + "," + strconv.Itoa(int(blockNo)) + " (Step 2)\n")
}
elapsedBlockProcessing := time.Since(startBlockProcessing) elapsedBlockProcessing := time.Since(startBlockProcessing)
startCommitBlockStorage := time.Now() startCommitBlockStorage := time.Now()
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"strconv"
"time" "time"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
...@@ -29,6 +30,7 @@ import ( ...@@ -29,6 +30,7 @@ import (
"github.com/hyperledger/fabric/protos/peer" "github.com/hyperledger/fabric/protos/peer"
transientstore2 "github.com/hyperledger/fabric/protos/transientstore" transientstore2 "github.com/hyperledger/fabric/protos/transientstore"
"github.com/hyperledger/fabric/protos/utils" "github.com/hyperledger/fabric/protos/utils"
"github.com/hyperledger/fabric_org/config"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
...@@ -153,6 +155,38 @@ func (c *coordinator) VerifyBlock(block *common.Block, privateDataSets util.PvtD ...@@ -153,6 +155,38 @@ func (c *coordinator) VerifyBlock(block *common.Block, privateDataSets util.PvtD
logger.Infof("[%s] Received block [%d] from buffer", c.ChainID, block.Header.Number) logger.Infof("[%s] Received block [%d] from buffer", c.ChainID, block.Header.Number)
if config.Log.FullCommit {
//fmt.Printf("{\"ts\":" + strconv.FormatInt(time.Now().UnixNano(), 10) + ",\"msg\":\"FABRIC PERF Validation\",\"block\":" + strconv.Itoa(int(block.Header.Number)) + ",\"STEP\":0}\n")
fmt.Printf(strconv.FormatInt(time.Now().UnixNano(), 10) + "," + strconv.Itoa(int(block.Header.Number)) + " (Step 0)\n")
}
if config.Log.Validation {
/*
txcount := -1
if block != nil && block.Metadata != nil && block.Metadata.Metadata != nil && block.Data != nil && block.Data.Data != nil {
txcount = 0
txsFilter := ha.TxValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
if len(txsFilter) == 0 {
txsFilter = ha.NewTxValidationFlags(len(block.Data.Data))
block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER] = txsFilter
}
for txIndex := range block.Data.Data {
if txsFilter.IsInvalid(txIndex) {
continue
}
txcount++
}
}
*/
fmt.Println("val0," + strconv.Itoa(int(block.Header.Number)) + "," + strconv.FormatInt(time.Now().UnixNano(), 10))
//logs.WriteString("{\"ts\":" + strconv.FormatInt(time.Now().UnixNano(), 10) + ",\"msg\":\"FABRIC PERF Validation\",\"block\":" + strconv.Itoa(int(block.Header.Number)) + ",\"transactions\":" + strconv.Itoa(txcount) + ",\"STEP\":0}\n")
}
logger.Debugf("[%s] Validating block [%d]", c.ChainID, block.Header.Number) logger.Debugf("[%s] Validating block [%d]", c.ChainID, block.Header.Number)
err := c.Validator.Validate(block) err := c.Validator.Validate(block)
if err != nil { if err != nil {
...@@ -165,7 +199,10 @@ func (c *coordinator) VerifyBlock(block *common.Block, privateDataSets util.PvtD ...@@ -165,7 +199,10 @@ func (c *coordinator) VerifyBlock(block *common.Block, privateDataSets util.PvtD
// StoreBlock stores block with private data into the ledger // StoreBlock stores block with private data into the ledger
func (c *coordinator) StoreBlock(block *common.Block, privateDataSets util.PvtDataCollections) error { func (c *coordinator) StoreBlock(block *common.Block, privateDataSets util.PvtDataCollections) error {
//logs.WriteString("{\"ts\":" + strconv.FormatInt(time.Now().UnixNano(), 10) + ",\"msg\":\"FABRIC PERF Validation\",\"block\":" + strconv.Itoa(int(block.Header.Number)) + ",\"STEP\":1}\n") if config.Log.FullCommit {
//fmt.Printf("{\"ts\":" + strconv.FormatInt(time.Now().UnixNano(), 10) + ",\"msg\":\"FABRIC PERF Validation\",\"block\":" + strconv.Itoa(int(block.Header.Number)) + ",\"STEP\":1}\n")
fmt.Printf(strconv.FormatInt(time.Now().UnixNano(), 10) + "," + strconv.Itoa(int(block.Header.Number)) + " (Step 1)\n")
}
blockAndPvtData := &ledger.BlockAndPvtData{ blockAndPvtData := &ledger.BlockAndPvtData{
Block: block, Block: block,
......
...@@ -21,7 +21,7 @@ func (m *noopmsp) Setup(conf1 *msp.MSPConfig) error { ...@@ -21,7 +21,7 @@ func (m *noopmsp) Setup(conf1 *msp.MSPConfig) error {
} }
func (m *noopmsp) GetVersion() MSPVersion { func (m *noopmsp) GetVersion() MSPVersion {
return MSPv1_0 return MSPv1_3
} }
func (m *noopmsp) GetType() ProviderType { func (m *noopmsp) GetType() ProviderType {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment