Skip to content

Commit

Permalink
runtime: cpu profiler to use high resolution timers on Windows
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
qmuntal committed Aug 2, 2023
1 parent 54e9d6d commit a09ea59
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/runtime/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,12 @@ func profileLoop() {

func setProcessCPUProfiler(hz int32) {
if profiletimer == 0 {
timer := stdcall3(_CreateWaitableTimerA, 0, 0, 0)
var timer uintptr
if haveHighResTimer {
timer = createHighResTimer()
} else {
timer = stdcall3(_CreateWaitableTimerA, 0, 0, 0)
}
atomic.Storeuintptr(&profiletimer, timer)
newm(profileLoop, nil, -1)
}
Expand Down

0 comments on commit a09ea59

Please sign in to comment.