Skip to content

Commit

Permalink
Merge pull request hyperledger-labs#107 from dongrie/time-track
Browse files Browse the repository at this point in the history
Add time track
  • Loading branch information
siburu authored Sep 22, 2023
2 parents 2811543 + 4d82d56 commit d1346bc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// TODO: add max retries or something to this function
func CreateChannel(src, dst *ProvableChain, ordered bool, to time.Duration) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "CreateChannel")
var order chantypes.Order
if ordered {
order = chantypes.ORDERED
Expand Down
4 changes: 4 additions & 0 deletions core/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package core

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/hyperledger-labs/yui-relayer/log"
"golang.org/x/sync/errgroup"
)

func CreateClients(src, dst *ProvableChain) error {
logger := GetChainPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "CreateClients")
var (
clients = &RelayMsgs{Src: []sdk.Msg{}, Dst: []sdk.Msg{}}
)
Expand Down Expand Up @@ -76,6 +79,7 @@ func CreateClients(src, dst *ProvableChain) error {

func UpdateClients(src, dst *ProvableChain) error {
logger := GetClientPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "UpdateClients")
var (
clients = &RelayMsgs{Src: []sdk.Msg{}, Dst: []sdk.Msg{}}
)
Expand Down
1 change: 1 addition & 0 deletions core/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (

func CreateConnection(src, dst *ProvableChain, to time.Duration) error {
logger := GetConnectionPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "CreateConnection")
ticker := time.NewTicker(to)

failed := 0
Expand Down
5 changes: 5 additions & 0 deletions core/naive-strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"context"
"fmt"
"time"

retry "github.com/avast/retry-go"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -72,6 +73,7 @@ func getQueryContext(chain *ProvableChain, sh SyncHeaders, useFinalizedHeader bo

func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "UnrelayedPackets")
var (
eg = new(errgroup.Group)
srcPackets PacketInfoList
Expand Down Expand Up @@ -177,6 +179,7 @@ func (st *NaiveStrategy) UnrelayedPackets(src, dst *ProvableChain, sh SyncHeader

func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "RelayPackets")
// set the maximum relay transaction constraints
msgs := &RelayMsgs{
Src: []sdk.Msg{},
Expand Down Expand Up @@ -275,6 +278,7 @@ func (st *NaiveStrategy) RelayPackets(src, dst *ProvableChain, rp *RelayPackets,

func (st *NaiveStrategy) UnrelayedAcknowledgements(src, dst *ProvableChain, sh SyncHeaders, includeRelayedButUnfinalized bool) (*RelayPackets, error) {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "UnrelayedAcknowledgements")
var (
eg = new(errgroup.Group)
srcAcks PacketInfoList
Expand Down Expand Up @@ -417,6 +421,7 @@ func logPacketsRelayed(src, dst Chain, num int, obj string, dir string) {

func (st *NaiveStrategy) RelayAcknowledgements(src, dst *ProvableChain, rp *RelayPackets, sh SyncHeaders) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "RelayAcknowledgements")
// set the maximum relay transaction constraints
msgs := &RelayMsgs{
Src: []sdk.Msg{},
Expand Down
1 change: 1 addition & 0 deletions core/packet-tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func SendTransferMsg(src, dst *ProvableChain, amount sdk.Coin, dstAddr fmt.Stringer, toHeightOffset uint64, toTimeOffset time.Duration) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "SendTransferMsg")
var (
timeoutHeight uint64
timeoutTimestamp uint64
Expand Down
16 changes: 16 additions & 0 deletions log/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"time"

"github.com/cockroachdb/errors"
"github.com/cockroachdb/errors/withstack"
Expand Down Expand Up @@ -80,6 +81,16 @@ func GetLogger() *RelayLogger {
return relayLogger
}

func (rl *RelayLogger) WithChain(
chainID string,
) *RelayLogger {
return &RelayLogger{
rl.Logger.With(
"chain_id", chainID,
),
}
}

func (rl *RelayLogger) WithChainPair(
srcChainID string,
dstChainID string,
Expand Down Expand Up @@ -175,3 +186,8 @@ func (rl *RelayLogger) WithModule(
),
}
}

func (rl *RelayLogger) TimeTrack(start time.Time, name string) {
elapsed := time.Since(start)
rl.Logger.Info("time track", "name", name, "elapsed", elapsed.Nanoseconds())
}

0 comments on commit d1346bc

Please sign in to comment.