-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime/pprof: Golang pprof cpu performance analysis, after the sampling frequency increases on the windows platform, the number of samples decreases #61665
Comments
"When the computer is running the test program, the total CPU usage does not exceed 50%." What is the total CPU usage on Linux? (I.e., is this information supposed to tell us
And I assume that you first observed this with a not-toy program, instead of a tight loop checking the current time. Is that assumption correct? |
@qmuntal are there any well-known windows gotchas that might cause this? |
It is related to #44343. The maximum sampling rate that doesn't reduce the number of samples is ~60, that is one sample every ~16ms, which matches the default Windows time accuracy. I've have reproduced @ypcd results, and managed to get back the number of samples to ~96% by calling What I don't know is why the number of samples are reduced. Could it be that the Go runtime is expecting the OS to honor the sampling rate, and when this assumption is not met it doesn't behaves well? |
Submitted CL 514375, which fixes this issue by using high resolution timers for CPU sampling. |
Change https://go.dev/cl/514375 mentions this issue: |
When I run tests on different platforms (windows, linux), the computer has enough free cpu time to use. I first discovered this problem while profiling other programs. |
I rewrote the test program a bit. I also found the sample reduction problem in the pure calculation test program. Specific performance: Pure calculation test program:
|
What version of Go are you using (
go version
)?go version go1.20.6 windows/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?windows/amd64
windows11 (22H2, 22621.1992)
cpu x86 amd pyzen 5500
What did you do?
I want to increase the sampling frequency of cpu profiling and get more cpu sampling samples.
On the windows platform, I use the runtime.SetCPUProfileRate() interface to set the cpu performance analysis sampling frequency.
It was found that after increasing the sampling frequency, the number of cpu samples (Total samples) decreased abnormally.
When the computer is running the test program, the total CPU usage does not exceed 50%.
I tested again on the same computer using linux (centos stream 9, 5.14.0-340.el9.x86_64) through a virtual machine, and found that the sampling results were basically the same, and the results were normal.
Test code:
What did you expect to see?
I want to increase the sampling frequency of cpu profiling and get more cpu sampling samples.
What did you see instead?
It was found that after increasing the sampling frequency, the number of cpu samples (Total samples) decreased abnormally.
When the computer is running the test program, the total CPU usage does not exceed 50%.
I tested again on the same computer using linux (centos stream 9, 5.14.0-340.el9.x86_64) through a virtual machine, and found that the sampling results were basically the same, and the results were normal.
Specific sampling results:
windows11 (22H2, 22621.1992):
Sampling frequency Sampling result
25 Duration: 3.08s, Total samples = 2.92s (94.68%)
50 Duration: 3.19s, Total samples = 3s (93.94%)
100 Duration: 3.16s, Total samples = 1.91s (60.48%)
200 Duration: 3.18s, Total samples = 960ms (30.20%)
linux --centos-stream 9, 5.14.0-340.el9.x86_64:
Sampling frequency Sampling result
25 Duration: 3.13s, Total samples = 2.84s (90.68%)
50 Duration: 3.13s, Total samples = 2.84s (90.71%)
100 Duration: 3.13s, Total samples = 2.85s (91.06%)
200 Duration: 3.13s, Total samples = 2.85s (91.01%)
The text was updated successfully, but these errors were encountered: