Skip to content

Commit a09ea59

Browse files
committed
runtime: cpu profiler to use high resolution timers on Windows
The CPU profiler skip samples if the sampling rate is too high for the system timer resolution. This CL uses high resolution timers on Windows when available, to avoid this problem. Note that the default sampling rate (100Hz) is already too high for the Windows timer resolution (15.6ms), so this CL also improves the default Windows sampling coverage. Not adding regression tests, as they would be too flaky. Fixes #61665 Change-Id: Ifdadabc9ebaf56f397eac517bd0e5f1502b956b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/514375 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Quim Muntal <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 54e9d6d commit a09ea59

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/runtime/os_windows.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,12 @@ func profileLoop() {
12661266

12671267
func setProcessCPUProfiler(hz int32) {
12681268
if profiletimer == 0 {
1269-
timer := stdcall3(_CreateWaitableTimerA, 0, 0, 0)
1269+
var timer uintptr
1270+
if haveHighResTimer {
1271+
timer = createHighResTimer()
1272+
} else {
1273+
timer = stdcall3(_CreateWaitableTimerA, 0, 0, 0)
1274+
}
12701275
atomic.Storeuintptr(&profiletimer, timer)
12711276
newm(profileLoop, nil, -1)
12721277
}

0 commit comments

Comments
 (0)