Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
events(bitswap) try the new event logger in the bitswap GetBlock method
Browse files Browse the repository at this point in the history
@jbenet
@whyrusleeping

Let me know if you want to direct the eventlog output to _both_ the file
and stderr. Right now it goes to file. Perhaps this is just a minor bip
in the larger discussion around log levels.

ipfs/kubo#292

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
  • Loading branch information
Brian Tiger Chow authored and whyrusleeping committed Dec 5, 2014
1 parent ca31457 commit 40f3a6a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util/eventlog"
)

var log = u.Logger("bitswap")
var log = eventlog.Logger("bitswap")

// New initializes a BitSwap instance that communicates over the
// provided BitSwapNetwork. This function registers the returned instance as
Expand Down Expand Up @@ -80,15 +81,21 @@ type bitswap struct {
//
// TODO ensure only one active request per key
func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, error) {
log.Debugf("Get Block %v", k)
now := time.Now()
defer func() {
log.Debugf("GetBlock took %f secs", time.Now().Sub(now).Seconds())
}()

// make sure to derive a new |ctx| and pass it to children. It's correct to
// listen on |parent| here, but incorrect to pass |parent| to new async
// functions. This is difficult to enforce. May this comment keep you safe.

ctx, cancelFunc := context.WithCancel(parent)
defer cancelFunc()

ctx = eventlog.ContextWithMetadata(ctx, eventlog.Uuid("BitswapGetBlockRequest"))
log.Event(ctx, "BitswapGetBlockRequestBegin", &k)

defer func() {
log.Event(ctx, "BitSwapGetBlockRequestEnd", &k)
}()

bs.wantlist.Add(k)
promise := bs.notifications.Subscribe(ctx, k)

Expand Down

0 comments on commit 40f3a6a

Please sign in to comment.