package runtime
const maxTraceStringLen = 1024
type traceStringTable struct {
lock mutex
buf *traceBuf
tab traceMap
}
func (t *traceStringTable ) put (gen uintptr , s string ) uint64 {
ss := stringStructOf (&s )
id , added := t .tab .put (ss .str , uintptr (ss .len ))
if added {
systemstack (func () {
t .writeString (gen , id , s )
})
}
return id
}
func (t *traceStringTable ) emit (gen uintptr , s string ) uint64 {
id := t .tab .stealID ()
systemstack (func () {
t .writeString (gen , id , s )
})
return id
}
func (t *traceStringTable ) writeString (gen uintptr , id uint64 , s string ) {
if len (s ) > maxTraceStringLen {
s = s [:maxTraceStringLen ]
}
lock (&t .lock )
w := unsafeTraceWriter (gen , t .buf )
var flushed bool
w , flushed = w .ensure (2 + 2 *traceBytesPerNumber + len (s ) )
if flushed {
w .byte (byte (traceEvStrings ))
}
w .byte (byte (traceEvString ))
w .varint (id )
w .varint (uint64 (len (s )))
w .stringData (s )
t .buf = w .traceBuf
unlock (&t .lock )
}
func (t *traceStringTable ) reset (gen uintptr ) {
if t .buf != nil {
systemstack (func () {
lock (&trace .lock )
traceBufFlush (t .buf , gen )
unlock (&trace .lock )
})
t .buf = nil
}
t .tab .reset ()
}
The pages are generated with Golds v0.7.6 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .