diff options
| author | Rémy Oudompheng <oudomphe@phare.normalesup.org> | 2012-02-06 19:16:26 +0100 |
|---|---|---|
| committer | Rémy Oudompheng <oudomphe@phare.normalesup.org> | 2012-02-06 19:16:26 +0100 |
| commit | 842c906e2e9560187d4877d9f52e8f9ceb63d84c (patch) | |
| tree | 218df3c83f3177d2f8ceccf20898d8e037c37042 /test/mallocrep.go | |
| parent | 9c060b8d60f14d930e5eadd7c9968ee2ba4f4131 (diff) | |
| download | go-842c906e2e9560187d4877d9f52e8f9ceb63d84c.tar.xz | |
runtime: delete UpdateMemStats, replace with ReadMemStats(&stats).
Unexports runtime.MemStats and rename MemStatsType to MemStats.
The new accessor requires passing a pointer to a user-allocated
MemStats structure.
Fixes #2572.
R=bradfitz, rsc, bradfitz, gustavo
CC=golang-dev, remy
https://golang.org/cl/5616072
Diffstat (limited to 'test/mallocrep.go')
| -rw-r--r-- | test/mallocrep.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/test/mallocrep.go b/test/mallocrep.go index cffcd1638f..4188da9b83 100644 --- a/test/mallocrep.go +++ b/test/mallocrep.go @@ -16,10 +16,12 @@ import ( var chatty = flag.Bool("v", false, "chatty") var oldsys uint64 +var memstats runtime.MemStats func bigger() { - runtime.UpdateMemStats() - if st := runtime.MemStats; oldsys < st.Sys { + st := &memstats + runtime.ReadMemStats(st) + if oldsys < st.Sys { oldsys = st.Sys if *chatty { println(st.Sys, " system bytes for ", st.Alloc, " Go bytes") @@ -32,26 +34,26 @@ func bigger() { } func main() { - runtime.GC() // clean up garbage from init - runtime.UpdateMemStats() // first call can do some allocations - runtime.MemProfileRate = 0 // disable profiler - runtime.MemStats.Alloc = 0 // ignore stacks + 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 flag.Parse() for i := 0; i < 1<<7; i++ { for j := 1; j <= 1<<22; j <<= 1 { if i == 0 && *chatty { println("First alloc:", j) } - if a := runtime.MemStats.Alloc; a != 0 { + if a := memstats.Alloc - stacks; a != 0 { println("no allocations but stats report", a, "bytes allocated") panic("fail") } b := runtime.Alloc(uintptr(j)) - runtime.UpdateMemStats() - during := runtime.MemStats.Alloc + runtime.ReadMemStats(&memstats) + during := memstats.Alloc - stacks runtime.Free(b) - runtime.UpdateMemStats() - if a := runtime.MemStats.Alloc; a != 0 { + runtime.ReadMemStats(&memstats) + if a := memstats.Alloc - stacks; a != 0 { println("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)") panic("fail") } |
