-
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: ReadMemStats before writing heap profile #20565
Comments
The problem you see is that When calling If you move the call to diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index 21ea25ce36..1de9efc6d3 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -476,6 +476,8 @@ func countHeap() int {
// writeHeap writes the current runtime heap profile to w.
func writeHeap(w io.Writer, debug int) error {
+ s := new(runtime.MemStats)
+ runtime.ReadMemStats(s)
// Find out how many records there are (MemProfile(nil, true)),
// allocate that many records, and get the data.
// There's a race—more records might be added between
@@ -538,8 +540,6 @@ func writeHeap(w io.Writer, debug int) error {
// Print memstats information too.
// Pprof will ignore, but useful for people
- s := new(runtime.MemStats)
- runtime.ReadMemStats(s)
fmt.Fprintf(w, "\n# runtime.MemStats\n")
fmt.Fprintf(w, "# Alloc = %d\n", s.Alloc)
fmt.Fprintf(w, "# TotalAlloc = %d\n", s.TotalAlloc) |
Thanks, Justin! Marking as 1.10, since this doesn't appear to be a regression from 1.8. |
Change https://golang.org/cl/80739 mentions this issue: |
The allocs/op numbers should be more or less unchanged by memprofilerate. All that compilebench does is read the Mallocs number printed by the compiler, and the compiler's Mallocs number comes directly from runtime.ReadMemStats.
My simple attempts to reproduce directly using only runtime.ReadMemStats in a simple program have failed, though, and I'm out of time to investigate.
I'd be delighted if anyone reading this was willing to investigate enough to at least rule out a bug in runtime.ReadMemStats.
The text was updated successfully, but these errors were encountered: