Skip to content

Commit 351d852

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 450ecbe commit 351d852

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/internal/trace/goroutinesv2.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,12 @@ func (b *goroutineStatsBuilder) event(ev tracev2.Event) {
318318
}
319319
}
320320

321-
// The goroutine hasn't been identified yet. Take any stack we
322-
// can get and identify it by the bottom-most frame of that stack.
321+
// The goroutine hasn't been identified yet. Take the transition stack
322+
// and identify the goroutine by the bottom-most frame of that stack.
323+
// This bottom-most frame will be identical for all transitions on this
324+
// goroutine, because it represents its immutable start point.
323325
if g.PC == 0 {
324-
stk := ev.Stack()
326+
stk := st.Stack
325327
if stk != tracev2.NoStack {
326328
var frame tracev2.StackFrame
327329
var ok bool

0 commit comments

Comments
 (0)