]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/trace: annotation proc start/stop with thread and proc always
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 13 Nov 2025 22:36:45 +0000 (22:36 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 13 Nov 2025 23:16:31 +0000 (15:16 -0800)
In the proc view, the thread ID is useful. In the thread view, the proc
ID is useful. Add both in both cases forever more.

Change-Id: I9cb7bd67a21ee17d865c25d73b2049b3da7aefbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/720402
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

src/cmd/trace/procgen.go
src/cmd/trace/threadgen.go
src/internal/trace/traceviewer/format/format.go

index 060e62fe04ba3f620399ae2fbeb76ff27892bff4..fc0a00e7ce7f24549263c7b21cf4b3222a55b2b9 100644 (file)
@@ -143,6 +143,13 @@ func (g *procGenerator) ProcTransition(ctx *traceContext, ev *trace.Event) {
        viewerEv := traceviewer.InstantEvent{
                Resource: uint64(proc),
                Stack:    ctx.Stack(viewerFrames(ev.Stack())),
+
+               // Annotate with the thread and proc. The proc is redundant, but this is to
+               // stay consistent with the thread view, where it's useful information.
+               Arg: format.SchedCtxArg{
+                       ProcID:   uint64(st.Resource.Proc()),
+                       ThreadID: uint64(ev.Thread()),
+               },
        }
 
        from, to := st.Proc()
@@ -156,7 +163,6 @@ func (g *procGenerator) ProcTransition(ctx *traceContext, ev *trace.Event) {
                        start = ctx.startTime
                }
                viewerEv.Name = "proc start"
-               viewerEv.Arg = format.ThreadIDArg{ThreadID: uint64(ev.Thread())}
                viewerEv.Ts = ctx.elapsed(start)
                ctx.IncThreadStateCount(ctx.elapsed(start), traceviewer.ThreadStateRunning, 1)
        }
index c2e2c86f6cde8c700f927f6ebc93fd9a70576f40..7f9e7a72f0f9ea143fe8fe95347dd97aa922c088 100644 (file)
@@ -138,14 +138,17 @@ func (g *threadGenerator) ProcTransition(ctx *traceContext, ev *trace.Event) {
                }
        }
 
-       type procArg struct {
-               Proc uint64 `json:"proc,omitempty"`
-       }
        st := ev.StateTransition()
        viewerEv := traceviewer.InstantEvent{
                Resource: uint64(ev.Thread()),
                Stack:    ctx.Stack(viewerFrames(ev.Stack())),
-               Arg:      procArg{Proc: uint64(st.Resource.Proc())},
+
+               // Annotate with the thread and proc. The thread is redundant, but this is to
+               // stay consistent with the proc view.
+               Arg: format.SchedCtxArg{
+                       ProcID:   uint64(st.Resource.Proc()),
+                       ThreadID: uint64(ev.Thread()),
+               },
        }
 
        from, to := st.Proc()
@@ -159,7 +162,6 @@ func (g *threadGenerator) ProcTransition(ctx *traceContext, ev *trace.Event) {
                        start = ctx.startTime
                }
                viewerEv.Name = "proc start"
-               viewerEv.Arg = format.ThreadIDArg{ThreadID: uint64(ev.Thread())}
                viewerEv.Ts = ctx.elapsed(start)
                // TODO(mknyszek): We don't have a state machine for threads, so approximate
                // running threads with running Ps.
index 83f32767042d3a95814545d29d4a29de907a1200..2ec4dd4bdc1537ea5046af3a8af3444f726b05f1 100644 (file)
@@ -74,6 +74,7 @@ type ThreadCountersArg struct {
        InSyscall int64
 }
 
-type ThreadIDArg struct {
-       ThreadID uint64
+type SchedCtxArg struct {
+       ThreadID uint64 `json:"thread,omitempty"`
+       ProcID   uint64 `json:"proc,omitempty"`
 }