aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/trace
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2023-11-20 21:19:35 +0000
committerGopher Robot <gobot@golang.org>2023-11-21 21:29:58 +0000
commit4e3ac99a3311e60587a296a636e4bbe3f066d2a9 (patch)
treeb7261a9a8722e0317ec8f08671ae40b518196330 /src/cmd/trace
parent28f873444d4e7fdfef9c07108002cd6347a8da0f (diff)
downloadgo-4e3ac99a3311e60587a296a636e4bbe3f066d2a9.tar.xz
cmd/trace/v2: emit regions in the goroutine-oriented task view
This change emits regions in the goroutine-oriented task view (the /trace endpoint with the taskid query variable set) in the same way the old cmd/trace does. For #60773. Fixes #63960. Change-Id: If6c3e7072c694c84a7d2d6c34df668f48d3acc2a Reviewed-on: https://go-review.googlesource.com/c/go/+/543995 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/trace')
-rw-r--r--src/cmd/trace/v2/gen.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/cmd/trace/v2/gen.go b/src/cmd/trace/v2/gen.go
index ac20dd1131..ad1599db92 100644
--- a/src/cmd/trace/v2/gen.go
+++ b/src/cmd/trace/v2/gen.go
@@ -73,6 +73,11 @@ func runGenerator(ctx *traceContext, g generator, parsed *parsedTrace, opts *gen
}
for i, task := range opts.tasks {
emitTask(ctx, task, i)
+ if opts.mode&traceviewer.ModeGoroutineOriented != 0 {
+ for _, region := range task.Regions {
+ emitRegion(ctx, region)
+ }
+ }
}
g.Finish(ctx)
}
@@ -130,6 +135,54 @@ func emitTask(ctx *traceContext, task *trace.UserTaskSummary, sortIndex int) {
}
}
+// emitRegion emits goroutine-based slice events to the UI. The caller
+// must be emitting for a goroutine-oriented trace.
+//
+// TODO(mknyszek): Make regions part of the regular generator loop and
+// treat them like ranges so that we can emit regions in traces oriented
+// by proc or thread.
+func emitRegion(ctx *traceContext, region *trace.UserRegionSummary) {
+ if region.Name == "" {
+ return
+ }
+ // Collect information about the region.
+ var startStack, endStack tracev2.Stack
+ goroutine := tracev2.NoGoroutine
+ startTime, endTime := ctx.startTime, ctx.endTime
+ if region.Start != nil {
+ startStack = region.Start.Stack()
+ startTime = region.Start.Time()
+ goroutine = region.Start.Goroutine()
+ }
+ if region.End != nil {
+ endStack = region.End.Stack()
+ endTime = region.End.Time()
+ goroutine = region.End.Goroutine()
+ }
+ if goroutine == tracev2.NoGoroutine {
+ return
+ }
+ arg := struct {
+ TaskID uint64 `json:"taskid"`
+ }{
+ TaskID: uint64(region.TaskID),
+ }
+ ctx.AsyncSlice(traceviewer.AsyncSliceEvent{
+ SliceEvent: traceviewer.SliceEvent{
+ Name: region.Name,
+ Ts: ctx.elapsed(startTime),
+ Dur: endTime.Sub(startTime),
+ Resource: uint64(goroutine),
+ Stack: ctx.Stack(viewerFrames(startStack)),
+ EndStack: ctx.Stack(viewerFrames(endStack)),
+ Arg: arg,
+ },
+ Category: "Region",
+ Scope: fmt.Sprintf("%x", region.TaskID),
+ TaskColorIndex: uint64(region.TaskID),
+ })
+}
+
// Building blocks for generators.
// stackSampleGenerator implements a generic handler for stack sample events.