mirror of https://github.com/golang/go.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 <heschi@google.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
4d59b14400
commit
1d8fc211f9
|
|
@ -404,6 +404,8 @@ type traceContext struct {
|
||||||
heapStats, prevHeapStats heapStats
|
heapStats, prevHeapStats heapStats
|
||||||
threadStats, prevThreadStats threadStats
|
threadStats, prevThreadStats threadStats
|
||||||
gstates, prevGstates [gStateCount]int64
|
gstates, prevGstates [gStateCount]int64
|
||||||
|
|
||||||
|
spanID int // last emitted span id. incremented in each emitSpan call.
|
||||||
}
|
}
|
||||||
|
|
||||||
type heapStats struct {
|
type heapStats struct {
|
||||||
|
|
@ -758,8 +760,8 @@ func generateTrace(params *traceParams, consumer traceConsumer) error {
|
||||||
// If we are in goroutine-oriented mode, we draw spans.
|
// If we are in goroutine-oriented mode, we draw spans.
|
||||||
// TODO(hyangah): add this for task/P-oriented mode (i.e., focustask view) too.
|
// TODO(hyangah): add this for task/P-oriented mode (i.e., focustask view) too.
|
||||||
if ctx.mode&modeGoroutineOriented != 0 {
|
if ctx.mode&modeGoroutineOriented != 0 {
|
||||||
for i, s := range task.spans {
|
for _, s := range task.spans {
|
||||||
ctx.emitSpan(s, i)
|
ctx.emitSpan(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -857,10 +859,13 @@ func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent {
|
||||||
return sl
|
return sl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *traceContext) emitSpan(s spanDesc, spanID int) {
|
func (ctx *traceContext) emitSpan(s spanDesc) {
|
||||||
if s.Name == "" {
|
if s.Name == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ctx.spanID++
|
||||||
|
spanID := ctx.spanID
|
||||||
|
|
||||||
id := s.TaskID
|
id := s.TaskID
|
||||||
scopeID := fmt.Sprintf("%x", id)
|
scopeID := fmt.Sprintf("%x", id)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue