-
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: under-samples all work when runtime creates threads #40963
Labels
Comments
Based on the description, this may be affected by https://golang.org/cl/240003 which was recently submitted. Does tip behave differently than 1.15 here? |
Yes, this works as I'd expect in tip. CL 240003 / commit bd519d0 look like they would be what fixed it. Thanks!
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Go are you using (
go version
)?I'm cross-compiling to GOOS=linux GOARCH=amd64 for the test.
Does this issue reproduce with the latest release?
Yes, this is present in Go 1.15 which is currently the latest release.
What operating system and processor architecture are you using (
go env
)?Here's the view from my laptop; the bug is on linux/amd64.
go env
OutputWhat did you do?
This program does work in a single goroutine and collects a CPU profile of itself. It periodically forces a thread to be created to do a trivial amount of processing in a separate goroutine.
I altered the period between new thread creations to be less than the CPU profiling rate (100 Hz, 10ms), somewhat longer than that period, and much longer than that period.
The code for the test is in the "details" immediately below:
bumps.go
What did you expect to see?
I expected the profile to show the CPU cost of the program's work. I expected it to show the CPU cost of the work equally well as I varied the "tick" parameter: without regard to how often the program created new OS threads.
What did you see instead?
When the program creates threads infrequently, its CPU profile reports a number of samples (each representing 10ms of work) that corresponds to the OS's view of how much CPU time the program spent.
When the program creates threads every 20ms, the resulting CPU profile has about half as many 10ms samples as I'd expect.
When the program creates threads faster than it earns SIGPROF deliveries (less than 10ms), the CPU profile ends up with almost no samples.
I think the problem is that
runtime.execute
callsruntime.setThreadCPUProfiler
when the current thread'sprofilehz
is different from what the program requests, which leads to asetitimer
syscall to adjust the profiling rate for the entire process. The test program creates new threads while the program is being profiled, and because they've never before run Go code theirprofilehz
values are still 0 .. and that the result of thesetitimer
syscall they make is to reset the kernel's account of how much CPU time the process has spent.The text was updated successfully, but these errors were encountered: