From: Hana Kim Date: Wed, 4 Apr 2018 17:47:53 +0000 (-0400) Subject: cmd/trace: avoid emitting traceview slice with 0 duration X-Git-Tag: go1.11beta1~973 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e6ab614fda5ce7533bda81f2b0de0f9fe18139bf;p=gostls13.git 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 --- diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index 12d8dec753..ecc7c3f9c9 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -815,11 +815,18 @@ func (ctx *traceContext) proc(ev *trace.Event) uint64 { } func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent { + // If ViewerEvent.Dur is not a positive value, + // trace viewer handles it as a non-terminating time interval. + // Avoid it by setting the field with a small value. + durationUsec := ctx.time(ev.Link) - ctx.time(ev) + if ev.Link.Ts-ev.Ts <= 0 { + durationUsec = 0.0001 // 0.1 nanoseconds + } sl := &ViewerEvent{ Name: name, Phase: "X", Time: ctx.time(ev), - Dur: ctx.time(ev.Link) - ctx.time(ev), + Dur: durationUsec, Tid: ctx.proc(ev), Stack: ctx.stack(ev.Stk), EndStack: ctx.stack(ev.Link.Stk),