]> Cypherpunks repositories - gostls13.git/commitdiff
internal/trace: use the correct stack for goroutine naming in v2 traces
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 21 Nov 2023 17:33:20 +0000 (17:33 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 21 Nov 2023 21:27:05 +0000 (21:27 +0000)
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 <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/internal/trace/goroutinesv2.go

index 6b13f2042593563691315a0de96884659ab3357f..7dbe0c59051637b07094234e039c9f1ab5195f5b 100644 (file)
@@ -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