From 3732daa8e7c635ba306dd923a4342650524320df Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 3 Feb 2010 16:31:34 -0800 Subject: finalizers; merge package malloc into package runtime R=r, cw CC=golang-dev http://codereview.appspot.com/198085 --- test/mallocrep.go | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'test/mallocrep.go') 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; } } } -- cgit v1.2.3