Commit 40f3a6a6 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Jeromy

events(bitswap) try the new event logger in the bitswap GetBlock method

@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.

https://github.com/jbenet/go-ipfs/issues/292

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent ca31457d
...@@ -17,9 +17,10 @@ import ( ...@@ -17,9 +17,10 @@ import (
strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy" strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util" 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 // New initializes a BitSwap instance that communicates over the
// provided BitSwapNetwork. This function registers the returned instance as // provided BitSwapNetwork. This function registers the returned instance as
...@@ -80,15 +81,21 @@ type bitswap struct { ...@@ -80,15 +81,21 @@ type bitswap struct {
// //
// TODO ensure only one active request per key // TODO ensure only one active request per key
func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, error) { func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, error) {
log.Debugf("Get Block %v", k)
now := time.Now() // make sure to derive a new |ctx| and pass it to children. It's correct to
defer func() { // listen on |parent| here, but incorrect to pass |parent| to new async
log.Debugf("GetBlock took %f secs", time.Now().Sub(now).Seconds()) // functions. This is difficult to enforce. May this comment keep you safe.
}()
ctx, cancelFunc := context.WithCancel(parent) ctx, cancelFunc := context.WithCancel(parent)
defer cancelFunc() 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) bs.wantlist.Add(k)
promise := bs.notifications.Subscribe(ctx, k) promise := bs.notifications.Subscribe(ctx, k)
......
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