Skip to content

Commit

Permalink
cmd/trace: assign a unique span id for slice representation
Browse files Browse the repository at this point in the history
Spans are represented using Async Event types of chrome trace viewer.
According to the doc, the 'id' should be unique within category, scope.

https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1

Use the index in the task's span slice as the slice id, so it
can be unique within the task. The scope is the task id which
is unique.

This fixes a visualization bug that caused incorrect or missing
presentation of nested spans.

Change-Id: If1537ee00247f71fa967abfe45569a9e7dbcdce7
Reviewed-on: https://go-review.googlesource.com/102697
Reviewed-by: Heschi Kreinick <[email protected]>
  • Loading branch information
hyangah committed Mar 27, 2018
1 parent 331c187 commit aaeaad6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cmd/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,8 @@ func generateTrace(params *traceParams, consumer traceConsumer) error {
ctx.emit(tEnd)

// Spans
for _, s := range task.spans {
ctx.emitSpan(s)
for i, s := range task.spans {
ctx.emitSpan(s, i)
}
}
}
Expand Down Expand Up @@ -824,7 +824,7 @@ func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent {
return sl
}

func (ctx *traceContext) emitSpan(s spanDesc) {
func (ctx *traceContext) emitSpan(s spanDesc, spanID int) {
if s.Name == "" {
return
}
Expand All @@ -837,7 +837,7 @@ func (ctx *traceContext) emitSpan(s spanDesc) {
Phase: "b",
Time: float64(s.firstTimestamp()) / 1e3,
Tid: s.G,
ID: s.G,
ID: uint64(spanID),
Scope: scopeID,
Cname: colorDeepMagenta,
}
Expand All @@ -852,7 +852,7 @@ func (ctx *traceContext) emitSpan(s spanDesc) {
Phase: "e",
Time: float64(s.lastTimestamp()) / 1e3,
Tid: s.G,
ID: s.G,
ID: uint64(spanID),
Scope: scopeID,
Cname: colorDeepMagenta,
}
Expand Down

0 comments on commit aaeaad6

Please sign in to comment.