Skip to content

Commit e6ab614

Browse files
committed
cmd/trace: avoid emitting traceview slice with 0 duration
The trace viewer interprets the slice as a non-terminating time interval which is quite opposit to what trace records indicate (i.e., almostly immediately terminating time interval). As observed in the issue #24663 this can result in quite misleading visualization of the trace. Work around the trace viewer's issue by setting a small value (0.0001usec) as the duration if the time interval is not positive. Change-Id: I1c2aac135c194d0717f5c01a98ca60ffb14ef45c Reviewed-on: https://go-review.googlesource.com/104716 Reviewed-by: Heschi Kreinick <[email protected]>
1 parent c4874aa commit e6ab614

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cmd/trace/trace.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,18 @@ func (ctx *traceContext) proc(ev *trace.Event) uint64 {
815815
}
816816

817817
func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent {
818+
// If ViewerEvent.Dur is not a positive value,
819+
// trace viewer handles it as a non-terminating time interval.
820+
// Avoid it by setting the field with a small value.
821+
durationUsec := ctx.time(ev.Link) - ctx.time(ev)
822+
if ev.Link.Ts-ev.Ts <= 0 {
823+
durationUsec = 0.0001 // 0.1 nanoseconds
824+
}
818825
sl := &ViewerEvent{
819826
Name: name,
820827
Phase: "X",
821828
Time: ctx.time(ev),
822-
Dur: ctx.time(ev.Link) - ctx.time(ev),
829+
Dur: durationUsec,
823830
Tid: ctx.proc(ev),
824831
Stack: ctx.stack(ev.Stk),
825832
EndStack: ctx.stack(ev.Link.Stk),

0 commit comments

Comments
 (0)