1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:40:08 -07:00

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 <heschi@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hana Kim 2018-04-12 17:06:33 -04:00 committed by Hyang-Ah Hana Kim
parent 4d59b14400
commit 1d8fc211f9

View 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)