dht_logger.go 556 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package dht

import (
	"encoding/json"
	"time"

	u "github.com/jbenet/go-ipfs/util"
)

type logDhtRpc struct {
	Type     string
	Start    time.Time
	End      time.Time
	Duration time.Duration
	RpcCount int
	Success  bool
}

func startNewRpc(name string) *logDhtRpc {
	r := new(logDhtRpc)
	r.Type = name
	r.Start = time.Now()
	return r
}

func (l *logDhtRpc) EndLog() {
	l.End = time.Now()
	l.Duration = l.End.Sub(l.Start)
}

func (l *logDhtRpc) Print() {
	b, err := json.Marshal(l)
	if err != nil {
34
		u.DOut(err.Error())
Jeromy's avatar
Jeromy committed
35
	} else {
36
		u.DOut(string(b))
Jeromy's avatar
Jeromy committed
37 38
	}
}