From d300ca3f316d34f5013be43d01a9a473fe3000b2 Mon Sep 17 00:00:00 2001 From: Hiro Date: Fri, 16 Jun 2023 08:23:04 +0530 Subject: [PATCH] runtime: fix trace.Stop run indefinitely when built with faketime Updated doc for the logic Change-Id: I8b4df301b925ddea648bbb49bc35bc718046bd59 --- src/runtime/trace.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/trace.go b/src/runtime/trace.go index ac80ca2902..a4d50d77a0 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -453,12 +453,17 @@ func StopTrace() { } } + // Wait for startNanotime != endNanotime. On Windows the default interval between + // system clock ticks is typically between 1 and 15 milliseconds, which may not + // have passed since the trace started. Without nanotime moving forward, trace + // tooling has no way of identifying how much real time each cputicks time deltas + // represent. for { trace.endTime = traceClockNow() trace.endTicks = cputicks() trace.endNanotime = nanotime() - // Windows time can tick only every 15ms, wait for at least one tick. - if trace.endNanotime != trace.startNanotime { + + if trace.endNanotime != trace.startNanotime || faketime != 0 { break } osyield()