-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: WriteHeapProfile example is not strictly equivalent to testing memprofile #65328
Comments
There is some additional discussion (from long ago) on the |
You are looking at the in-use space, of which there won't be any by the time you are taking the profile. Try |
Then, isn't the documentation at https://pkg.go.dev/runtime/pprof#hdr-Profiling_a_Go_program wrong, or at least very unhelpful? |
Turns out the documentation is wrong! When I turn my code into a unit test, then Here is my new code:
And here is how the pprof call now works as described in the docs (i.e. without the extra option):
|
You're correct that there is a slight difference between the behavior of |
Maybe this could be explained in the documentation: Maybe the example code in the documentation could be changed to match what testing is going? Or the difference between testing and the example code could be explained there, together with the Or maybe |
I have no opinions on that, but have reopened the issue so it'll be on the radar of the other team members. |
In triage, we should probably align the default EDIT: Though, perhaps there are arguments for not aligning the two. I'm not sure. |
I'm not sure we can/should align the two. The testing package writes an alloc profile because the inuse profile is expected to be essentially empty and thus useless in tests. On the other hand, I agree that https://pkg.go.dev/runtime/pprof#hdr-Profiling_a_Go_program is a little misleading and could be improved. |
Change https://go.dev/cl/597980 mentions this issue: |
Go version
go version go1.21.6 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I followed the instructions at https://pkg.go.dev/runtime/pprof#hdr-Profiling_a_Go_program , trying to get a memory profile of my program. Here is a short program, which illustrates the problem:
What did you see happen?
The profiler did not report the memory allocations:
What did you expect to see?
I would have expected the line
data := make([]float64, 16*1024)
to feature prominently in thego tool pprof
output.The text was updated successfully, but these errors were encountered: