From 2c0a9884e0dc930c1a3596bc1decf183c8fdcf77 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Mon, 18 Apr 2022 12:32:37 -0700 Subject: runtime: add CPU samples to execution trace When the CPU profiler and execution tracer are both active, report the CPU profile samples in the execution trace data stream. Include only samples that arrive on the threads known to the runtime, but include them even when running g0 (such as near the scheduler) or if there's no P (such as near syscalls). Render them in "go tool trace" as instantaneous events. For #16895 Change-Id: I0aa501a7b450c971e510961c0290838729033f7f Reviewed-on: https://go-review.googlesource.com/c/go/+/400795 Reviewed-by: Michael Knyszek Run-TryBot: Rhys Hiltner Reviewed-by: David Chase TryBot-Result: Gopher Robot --- src/cmd/trace/trace.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/cmd/trace/trace.go') diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index a0d742ac54..1cabc25ced 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -30,7 +30,6 @@ func init() { http.Handle("/static/", http.FileServer(http.FS(staticContent))) } - // httpTrace serves either whole trace (goid==0) or trace for goid goroutine. func httpTrace(w http.ResponseWriter, r *http.Request) { _, err := parseTrace() @@ -719,6 +718,11 @@ func generateTrace(params *traceParams, consumer traceConsumer) error { ctx.emitInstant(ev, "task start", "user event") case trace.EvUserTaskEnd: ctx.emitInstant(ev, "task end", "user event") + case trace.EvCPUSample: + if ev.P >= 0 { + // only show in this UI when there's an associated P + ctx.emitInstant(ev, "CPU profile sample", "") + } } // Emit any counter updates. ctx.emitThreadCounters(ev) -- cgit v1.3