From: Hana Kim Date: Thu, 12 Apr 2018 21:06:33 +0000 (-0400) Subject: cmd/trace: change span id computation for trace view use X-Git-Tag: go1.11beta1~840 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1d8fc211f99ea813e3c6517c12d7758691bf0529;p=gostls13.git cmd/trace: change span id computation for trace view use 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 Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index ecc7c3f9c9..e3bb40614d 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -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)