mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
9c060b8d60
commit
842c906e2e
23 changed files with 129 additions and 105 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue