-
Notifications
You must be signed in to change notification settings - Fork 14
/
template_trace.go
67 lines (56 loc) · 1.48 KB
/
template_trace.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gengorums
import (
"fmt"
"github.com/relab/gorums"
"google.golang.org/protobuf/compiler/protogen"
)
var traceable bool
// SetTrace is used to indicate whether or not to generate trace code.
func SetTrace(trace bool) {
traceable = trace
}
func trace() string {
if traceable {
return traceDefinition
}
return notrace
}
var traceDefinition = `
{{define "trace"}}
var ti traceInfo
if c.mgr.opts.trace {
ti.Trace = {{use "trace.New" .GenFile}}("gorums."+c.String()+".Sent", "{{.Method.GoName}}")
defer ti.Finish()
ti.firstLine.cid = c.id
if deadline, ok := ctx.Deadline(); ok {
ti.firstLine.deadline = {{use "time.Until" .GenFile}}(deadline)
}
ti.LazyLog(&ti.firstLine, false)
ti.LazyLog(&payload{sent: true, msg: in}, false)
defer func() {
ti.LazyLog({{qcresult .GenFile .Method}}, false)
if {{withPromise .Method "resp."}}err != nil {
ti.SetError()
}
}()
}
{{end}}
{{define "traceLazyLog"}}
if c.mgr.opts.trace {
ti.LazyLog(&payload{sent: false, id: r.nid, msg: r.reply}, false)
}
{{end}}
`
var notrace = `
{{define "trace"}}{{end}}
{{define "traceLazyLog"}}{{end}}
`
func qcresult(g *protogen.GeneratedFile, method *protogen.Method) string {
if hasMethodOption(method, callTypesWithPromiseObject...) {
return fmt.Sprintf("&qcresult{ids: resp.NodeIDs, reply: resp.%s, err: resp.err}", field(customOut(g, method)))
}
if hasMethodOption(method, gorums.E_Quorumcall, gorums.E_Ordered) {
return "&qcresult{reply: resp, err: err}"
}
return ""
}