| // Copyright 2009 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| var chatty = flag.Bool("v", false, "chatty") |
| var memstats runtime.MemStats |
| println(st.Sys, " system bytes for ", st.Alloc, " Go bytes") |
| runtime.GC() // clean up garbage from init |
| runtime.ReadMemStats(&memstats) // first call can do some allocations |
| runtime.MemProfileRate = 0 // disable profiler |
| stacks := memstats.Alloc // ignore stacks |
| for i := 0; i < 1<<7; i++ { |
| for j := 1; j <= 1<<22; j <<= 1 { |
| println("First alloc:", j) |
| if a := memstats.Alloc - stacks; a != 0 { |
| println("no allocations but stats report", a, "bytes allocated") |
| b := runtime.Alloc(uintptr(j)) |
| runtime.ReadMemStats(&memstats) |
| during := memstats.Alloc - stacks |
| runtime.ReadMemStats(&memstats) |
| if a := memstats.Alloc - stacks; a != 0 { |
| println("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)") |
| if i%(1<<10) == 0 && *chatty { |