From: Michael Anthony Knyszek Date: Tue, 21 Nov 2023 17:33:20 +0000 (+0000) Subject: internal/trace: use the correct stack for goroutine naming in v2 traces X-Git-Tag: go1.22rc1~199 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=351d8520a6e55cbadc1714ad62405699ee172c5e;p=gostls13.git internal/trace: use the correct stack for goroutine naming in v2 traces Currently goroutine names are determined (for v2 traces) by internal/tracev/2.Event.Stack, but this is wrong in general. For example, if we end up seeing a transition from GoNotExist->GoRunnable (goroutine creation) then we're taking the stack from the creator, not the created goroutine (which is what we're naming at that point). Use the StateTransition.Stack instead. This is always the correct one to use because we're always naming the goroutine that the state transition is for. Change-Id: I3fc7c8e4f85dfee3802d666c0c091b6953c7d6cf Reviewed-on: https://go-review.googlesource.com/c/go/+/544317 Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- diff --git a/src/internal/trace/goroutinesv2.go b/src/internal/trace/goroutinesv2.go index 6b13f20425..7dbe0c5905 100644 --- a/src/internal/trace/goroutinesv2.go +++ b/src/internal/trace/goroutinesv2.go @@ -318,10 +318,12 @@ func (b *goroutineStatsBuilder) event(ev tracev2.Event) { } } - // The goroutine hasn't been identified yet. Take any stack we - // can get and identify it by the bottom-most frame of that stack. + // The goroutine hasn't been identified yet. Take the transition stack + // and identify the goroutine by the bottom-most frame of that stack. + // This bottom-most frame will be identical for all transitions on this + // goroutine, because it represents its immutable start point. if g.PC == 0 { - stk := ev.Stack() + stk := st.Stack if stk != tracev2.NoStack { var frame tracev2.StackFrame var ok bool