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
|
|
@ -53,8 +53,9 @@ func TestCountEncodeMallocs(t *testing.T) {
|
|||
var buf bytes.Buffer
|
||||
enc := NewEncoder(&buf)
|
||||
bench := &Bench{7, 3.2, "now is the time", []byte("for all good men")}
|
||||
runtime.UpdateMemStats()
|
||||
mallocs := 0 - runtime.MemStats.Mallocs
|
||||
memstats := new(runtime.MemStats)
|
||||
runtime.ReadMemStats(memstats)
|
||||
mallocs := 0 - memstats.Mallocs
|
||||
const count = 1000
|
||||
for i := 0; i < count; i++ {
|
||||
err := enc.Encode(bench)
|
||||
|
|
@ -62,8 +63,8 @@ func TestCountEncodeMallocs(t *testing.T) {
|
|||
t.Fatal("encode:", err)
|
||||
}
|
||||
}
|
||||
runtime.UpdateMemStats()
|
||||
mallocs += runtime.MemStats.Mallocs
|
||||
runtime.ReadMemStats(memstats)
|
||||
mallocs += memstats.Mallocs
|
||||
fmt.Printf("mallocs per encode of type Bench: %d\n", mallocs/count)
|
||||
}
|
||||
|
||||
|
|
@ -79,8 +80,9 @@ func TestCountDecodeMallocs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
dec := NewDecoder(&buf)
|
||||
runtime.UpdateMemStats()
|
||||
mallocs := 0 - runtime.MemStats.Mallocs
|
||||
memstats := new(runtime.MemStats)
|
||||
runtime.ReadMemStats(memstats)
|
||||
mallocs := 0 - memstats.Mallocs
|
||||
for i := 0; i < count; i++ {
|
||||
*bench = Bench{}
|
||||
err := dec.Decode(&bench)
|
||||
|
|
@ -88,7 +90,7 @@ func TestCountDecodeMallocs(t *testing.T) {
|
|||
t.Fatal("decode:", err)
|
||||
}
|
||||
}
|
||||
runtime.UpdateMemStats()
|
||||
mallocs += runtime.MemStats.Mallocs
|
||||
runtime.ReadMemStats(memstats)
|
||||
mallocs += memstats.Mallocs
|
||||
fmt.Printf("mallocs per decode of type Bench: %d\n", mallocs/count)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue