From: Austin Clements Date: Thu, 11 Aug 2022 16:08:35 +0000 (-0400) Subject: runtime: simplify trace buffer management around footer X-Git-Tag: go1.20rc1~1685 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b648591b705490d14147f3beb66c68be9a97c5b5;p=gostls13.git runtime: simplify trace buffer management around footer Writing out the trace footer currently manages trace buffers differently from the rest of trace code. Rearrange it so it looks like the rest of the code. In particular, we now write the frequency event out to the trace buffer rather than returning it in a special byte slice, and (*traceStackTable).dump threads a traceBufPtr like most other functions that write to the trace buffers. Change-Id: I3d0e108e56df884e7bd19823310dfbc0e21af9a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/422974 Reviewed-by: Michael Knyszek Run-TryBot: Austin Clements TryBot-Result: Gopher Robot --- diff --git a/src/runtime/trace.go b/src/runtime/trace.go index d2cc2acc15..9001956de1 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -459,6 +459,9 @@ func ReadTrace() []byte { goparkunlock(&trace.lock, waitReasonTraceReaderBlocked, traceEvGoBlock, 2) lock(&trace.lock) } + +newFull: + assertLockHeld(&trace.lock) // Write a buffer. if trace.fullHead != 0 { buf := traceFullDequeue() @@ -478,13 +481,22 @@ func ReadTrace() []byte { } trace.lockOwner = nil unlock(&trace.lock) - var data []byte - data = append(data, traceEvFrequency|0<= 0x80; v >>= 7 { - buf = append(buf, 0x80|byte(v)) - } - buf = append(buf, byte(v)) - return buf -} - // varint appends v to buf in little-endian-base-128 encoding. func (buf *traceBuf) varint(v uint64) { pos := buf.pos @@ -1058,8 +1061,7 @@ func traceFrames(bufp traceBufPtr, pcs []uintptr) ([]traceFrame, traceBufPtr) { // dump writes all previously cached stacks to trace buffers, // releases all memory and resets state. -func (tab *traceStackTable) dump() { - bufp := traceFlush(0, 0) +func (tab *traceStackTable) dump(bufp traceBufPtr) traceBufPtr { for i, _ := range tab.tab { stk := tab.tab[i].ptr() for ; stk != nil; stk = stk.link.ptr() { @@ -1097,13 +1099,11 @@ func (tab *traceStackTable) dump() { } } - lock(&trace.lock) - traceFullQueue(bufp) - unlock(&trace.lock) - tab.mem.drop() *tab = traceStackTable{} lockInit(&((*tab).lock), lockRankTraceStackTab) + + return bufp } type traceFrame struct {