diff options
author | Russ Cox <rsc@golang.org> | 2010-02-03 16:31:34 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-02-03 16:31:34 -0800 |
commit | 3732daa8e7c635ba306dd923a4342650524320df (patch) | |
tree | 31d454f4c7a1d0189ddbd9b1e771c8716655dc72 /test/mallocrep.go | |
parent | 9c681e46bfdf7a2745d2df35412592e8c13e0fce (diff) | |
download | golang-3732daa8e7c635ba306dd923a4342650524320df.tar.gz |
finalizers; merge package malloc into package runtime
R=r, cw
CC=golang-dev
http://codereview.appspot.com/198085
Diffstat (limited to 'test/mallocrep.go')
-rw-r--r-- | test/mallocrep.go | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/test/mallocrep.go b/test/mallocrep.go index 5367787e9..5e1314ef5 100644 --- a/test/mallocrep.go +++ b/test/mallocrep.go @@ -9,52 +9,53 @@ package main import ( - "flag"; - "malloc" + "flag" + "runtime" ) -var chatty = flag.Bool("v", false, "chatty"); +var chatty = flag.Bool("v", false, "chatty") + +var oldsys uint64 -var oldsys uint64; func bigger() { - if st := malloc.GetStats(); oldsys < st.Sys { - oldsys = st.Sys; + if st := runtime.MemStats; oldsys < st.Sys { + oldsys = st.Sys if *chatty { - println(st.Sys, " system bytes for ", st.Alloc, " Go bytes"); + println(st.Sys, " system bytes for ", st.Alloc, " Go bytes") } if st.Sys > 1e9 { - panicln("too big"); + panicln("too big") } } } func main() { - flag.Parse(); - malloc.GetStats().Alloc = 0; // ignore stacks + flag.Parse() + runtime.MemStats.Alloc = 0 // ignore stacks for i := 0; i < 1<<7; i++ { - for j := 1; j <= 1<<22; j<<=1 { + for j := 1; j <= 1<<22; j <<= 1 { if i == 0 && *chatty { - println("First alloc:", j); + println("First alloc:", j) } - if a := malloc.GetStats().Alloc; a != 0 { - panicln("no allocations but stats report", a, "bytes allocated"); + if a := runtime.MemStats.Alloc; a != 0 { + panicln("no allocations but stats report", a, "bytes allocated") } - b := malloc.Alloc(uintptr(j)); - during := malloc.GetStats().Alloc; - malloc.Free(b); - if a := malloc.GetStats().Alloc; a != 0 { - panic("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)"); + b := runtime.Alloc(uintptr(j)) + during := runtime.MemStats.Alloc + runtime.Free(b) + if a := runtime.MemStats.Alloc; a != 0 { + panic("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)") } - bigger(); + bigger() } if i%(1<<10) == 0 && *chatty { - println(i); + println(i) } if i == 0 { if *chatty { - println("Primed", i); + println("Primed", i) } - // malloc.frozen = true; + // runtime.frozen = true; } } } |