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
This commit is contained in:
Rémy Oudompheng 2012-02-06 19:16:26 +01:00
parent 9c060b8d60
commit 842c906e2e
23 changed files with 129 additions and 105 deletions

View file

@ -1545,15 +1545,19 @@ func TestAddr(t *testing.T) {
func noAlloc(t *testing.T, n int, f func(int)) {
// once to prime everything
f(-1)
runtime.MemStats.Mallocs = 0
memstats := new(runtime.MemStats)
runtime.ReadMemStats(memstats)
oldmallocs := memstats.Mallocs
for j := 0; j < n; j++ {
f(j)
}
// A few allocs may happen in the testing package when GOMAXPROCS > 1, so don't
// require zero mallocs.
if runtime.MemStats.Mallocs > 5 {
t.Fatalf("%d mallocs after %d iterations", runtime.MemStats.Mallocs, n)
runtime.ReadMemStats(memstats)
mallocs := memstats.Mallocs - oldmallocs
if mallocs > 5 {
t.Fatalf("%d mallocs after %d iterations", mallocs, n)
}
}