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