add a bool in payload struct

This commit is contained in:
yangzhouhan 2015-07-24 11:30:14 -07:00
parent bd20726bd8
commit 6cfd2022af
3 changed files with 29 additions and 6 deletions

12
call.go
View File

@ -164,7 +164,11 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
return toRPCErr(err)
}
if EnableTracing {
c.traceInfo.tr.LazyLog(&fmtStringer{"sent: %v", []interface{}{payload{args}}}, true)
p := &payload{
sent: true,
msg: args,
}
c.traceInfo.tr.LazyLog(p, true)
}
stream, err = sendRequest(ctx, cc.dopts.codec, callHdr, t, args, topts)
if err != nil {
@ -183,7 +187,11 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
continue
}
if EnableTracing {
c.traceInfo.tr.LazyLog(&fmtStringer{"received: %v", []interface{}{payload{reply}}}, true)
p := &payload{
sent: false,
msg: reply,
}
c.traceInfo.tr.LazyLog(p, true)
}
t.CloseStream(stream, lastErr)
if lastErr != nil {

View File

@ -166,7 +166,11 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) {
if cs.tracing {
cs.mu.Lock()
if cs.traceInfo.tr != nil {
cs.traceInfo.tr.LazyLog(&fmtStringer{"sent: %v", []interface{}{payload{m}}}, true)
p := &payload{
sent: true,
msg: m,
}
cs.traceInfo.tr.LazyLog(p, true)
}
cs.mu.Unlock()
}
@ -190,7 +194,13 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) {
if cs.tracing {
cs.mu.Lock()
if cs.traceInfo.tr != nil {
cs.traceInfo.tr.LazyLog(&fmtStringer{"received: %v", []interface{}{payload{m}}}, true)
if cs.traceInfo.tr != nil {
p := &payload{
sent: false,
msg: m,
}
cs.traceInfo.tr.LazyLog(p, true)
}
}
cs.mu.Unlock()
}

View File

@ -93,12 +93,17 @@ func (f *firstLine) String() string {
// payload represents an RPC request or response payload.
type payload struct {
m interface{} // e.g. a proto.Message
sent bool // whether this is a request or response
msg interface{} // e.g. a proto.Message
// TODO(dsymonds): add stringifying info to codec, and limit how much we hold here?
}
func (p payload) String() string {
return fmt.Sprint(p.m)
if p.sent {
return fmt.Sprintf("sent: %v", p.msg)
} else {
return fmt.Sprintf("recv: %v", p.msg)
}
}
type fmtStringer struct {