]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/trace: change span id computation for trace view use
authorHana Kim <hakim@google.com>
Thu, 12 Apr 2018 21:06:33 +0000 (17:06 -0400)
committerHyang-Ah Hana Kim <hyangah@gmail.com>
Fri, 13 Apr 2018 16:18:30 +0000 (16:18 +0000)
golang.org/cl/102697 attempted to fix the span presentation by utilizing
the position of the span in the span slices of a task. But it is
not complete either.

First, id=0 is omitted in json encoding and the trace viewer silently
drops entries with the missing id field, so we must avoid zero-value id.
Second, it is possible that a goroutine handles multiple tasks. Then,
id collisions will happen.

This takes a simpler approach - have a counter that increments for every
emitSpan call, and use the value as the id value.

Change-Id: Idaa9505634acf6d327c6f00af32d8260955b85e1
Reviewed-on: https://go-review.googlesource.com/106755
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/trace/trace.go

index ecc7c3f9c92181e97f837c769790fbaf1bc656ce..e3bb40614dea0d39b821ac9c27d2a5e18189b2a3 100644 (file)
@@ -404,6 +404,8 @@ type traceContext struct {
        heapStats, prevHeapStats     heapStats
        threadStats, prevThreadStats threadStats
        gstates, prevGstates         [gStateCount]int64
+
+       spanID int // last emitted span id. incremented in each emitSpan call.
 }
 
 type heapStats struct {
@@ -758,8 +760,8 @@ func generateTrace(params *traceParams, consumer traceConsumer) error {
                        // If we are in goroutine-oriented mode, we draw spans.
                        // TODO(hyangah): add this for task/P-oriented mode (i.e., focustask view) too.
                        if ctx.mode&modeGoroutineOriented != 0 {
-                               for i, s := range task.spans {
-                                       ctx.emitSpan(s, i)
+                               for _, s := range task.spans {
+                                       ctx.emitSpan(s)
                                }
                        }
                }
@@ -857,10 +859,13 @@ func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent {
        return sl
 }
 
-func (ctx *traceContext) emitSpan(s spanDesc, spanID int) {
+func (ctx *traceContext) emitSpan(s spanDesc) {
        if s.Name == "" {
                return
        }
+       ctx.spanID++
+       spanID := ctx.spanID
+
        id := s.TaskID
        scopeID := fmt.Sprintf("%x", id)