aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/trace.go
diff options
context:
space:
mode:
authorMeng Zhuo <mzh@golangcn.org>2021-09-20 20:44:50 +0800
committerMeng Zhuo <mzh@golangcn.org>2021-10-19 07:45:46 +0000
commitee92daae25029882979eb694bd7246491e364d3c (patch)
treeb51399dcf9c58e55b83d4a034772cd4096a5c228 /src/runtime/trace.go
parent8838a3b53fccc7b3aa83312326bfd38bcb8f2281 (diff)
downloadgo-ee92daae25029882979eb694bd7246491e364d3c.tar.xz
runtime: ensure at least 1 tick between events
ticks might be same after tick division, although the real cputicks is linear growth Fixes #46737 Change-Id: I1d98866fbf21b426c6c1c96cc9cf802d7f440f18 Reviewed-on: https://go-review.googlesource.com/c/go/+/330849 Trust: Meng Zhuo <mzh@golangcn.org> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/runtime/trace.go')
-rw-r--r--src/runtime/trace.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/runtime/trace.go b/src/runtime/trace.go
index 00544e4283..5b14a5f553 100644
--- a/src/runtime/trace.go
+++ b/src/runtime/trace.go
@@ -551,8 +551,15 @@ func traceEventLocked(extraBytes int, mp *m, pid int32, bufp *traceBufPtr, ev by
bufp.set(buf)
}
+ // NOTE: ticks might be same after tick division, although the real cputicks is
+ // linear growth.
ticks := uint64(cputicks()) / traceTickDiv
tickDiff := ticks - buf.lastTicks
+ if tickDiff == 0 {
+ ticks = buf.lastTicks + 1
+ tickDiff = 1
+ }
+
buf.lastTicks = ticks
narg := byte(len(args))
if skip >= 0 {
@@ -653,6 +660,9 @@ func traceFlush(buf traceBufPtr, pid int32) traceBufPtr {
// initialize the buffer for a new batch
ticks := uint64(cputicks()) / traceTickDiv
+ if ticks == bufp.lastTicks {
+ ticks = bufp.lastTicks + 1
+ }
bufp.lastTicks = ticks
bufp.byte(traceEvBatch | 1<<traceArgCountShift)
bufp.varint(uint64(pid))