Source file
src/runtime/tracestring.go
1
2
3
4
5
6
7 package runtime
8
9
10
11 const maxTraceStringLen = 1024
12
13
14
15 type traceStringTable struct {
16
17 lock mutex
18 buf *traceBuf
19
20
21 tab traceMap
22 }
23
24
25 func (t *traceStringTable) put(gen uintptr, s string) uint64 {
26
27 ss := stringStructOf(&s)
28 id, added := t.tab.put(ss.str, uintptr(ss.len))
29 if added {
30
31 systemstack(func() {
32 t.writeString(gen, id, s)
33 })
34 }
35 return id
36 }
37
38
39 func (t *traceStringTable) emit(gen uintptr, s string) uint64 {
40
41 id := t.tab.stealID()
42 systemstack(func() {
43 t.writeString(gen, id, s)
44 })
45 return id
46 }
47
48
49
50
51
52
53 func (t *traceStringTable) writeString(gen uintptr, id uint64, s string) {
54
55 if len(s) > maxTraceStringLen {
56 s = s[:maxTraceStringLen]
57 }
58
59 lock(&t.lock)
60 w := unsafeTraceWriter(gen, t.buf)
61
62
63 var flushed bool
64 w, flushed = w.ensure(2 + 2*traceBytesPerNumber + len(s) )
65 if flushed {
66
67 w.byte(byte(traceEvStrings))
68 }
69
70
71 w.byte(byte(traceEvString))
72 w.varint(id)
73 w.varint(uint64(len(s)))
74 w.stringData(s)
75
76
77 t.buf = w.traceBuf
78 unlock(&t.lock)
79 }
80
81
82
83
84
85 func (t *traceStringTable) reset(gen uintptr) {
86 if t.buf != nil {
87 systemstack(func() {
88 lock(&trace.lock)
89 traceBufFlush(t.buf, gen)
90 unlock(&trace.lock)
91 })
92 t.buf = nil
93 }
94
95
96 t.tab.reset()
97 }
98
View as plain text