go/ssa: report memory consumption separated by phase in stdlib_test
LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/170600043
This commit is contained in:
parent
b8d26f5b94
commit
50755a56a8
|
@ -7,7 +7,7 @@ package ssa_test
|
||||||
// This file runs the SSA builder in sanity-checking mode on all
|
// This file runs the SSA builder in sanity-checking mode on all
|
||||||
// packages beneath $GOROOT and prints some summary information.
|
// packages beneath $GOROOT and prints some summary information.
|
||||||
//
|
//
|
||||||
// Run test with GOMAXPROCS=8.
|
// Run with "go test -cpu=8 to" set GOMAXPROCS.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go/build"
|
"go/build"
|
||||||
|
@ -22,9 +22,17 @@ import (
|
||||||
"golang.org/x/tools/go/ssa/ssautil"
|
"golang.org/x/tools/go/ssa/ssautil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func bytesAllocated() uint64 {
|
||||||
|
runtime.GC()
|
||||||
|
var stats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&stats)
|
||||||
|
return stats.Alloc
|
||||||
|
}
|
||||||
|
|
||||||
func TestStdlib(t *testing.T) {
|
func TestStdlib(t *testing.T) {
|
||||||
// Load, parse and type-check the program.
|
// Load, parse and type-check the program.
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
|
alloc0 := bytesAllocated()
|
||||||
|
|
||||||
// Load, parse and type-check the program.
|
// Load, parse and type-check the program.
|
||||||
ctxt := build.Default // copy
|
ctxt := build.Default // copy
|
||||||
|
@ -44,11 +52,7 @@ func TestStdlib(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
|
alloc1 := bytesAllocated()
|
||||||
runtime.GC()
|
|
||||||
var memstats runtime.MemStats
|
|
||||||
runtime.ReadMemStats(&memstats)
|
|
||||||
alloc := memstats.Alloc
|
|
||||||
|
|
||||||
// Create SSA packages.
|
// Create SSA packages.
|
||||||
var mode ssa.BuilderMode
|
var mode ssa.BuilderMode
|
||||||
|
@ -63,15 +67,18 @@ func TestStdlib(t *testing.T) {
|
||||||
prog.BuildAll()
|
prog.BuildAll()
|
||||||
|
|
||||||
t3 := time.Now()
|
t3 := time.Now()
|
||||||
|
alloc3 := bytesAllocated()
|
||||||
runtime.GC()
|
|
||||||
runtime.ReadMemStats(&memstats)
|
|
||||||
|
|
||||||
numPkgs := len(prog.AllPackages())
|
numPkgs := len(prog.AllPackages())
|
||||||
if want := 140; numPkgs < want {
|
if want := 140; numPkgs < want {
|
||||||
t.Errorf("Loaded only %d packages, want at least %d", numPkgs, want)
|
t.Errorf("Loaded only %d packages, want at least %d", numPkgs, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep iprog reachable until after we've measured memory usage.
|
||||||
|
if len(iprog.AllPackages) == 0 {
|
||||||
|
print() // unreachable
|
||||||
|
}
|
||||||
|
|
||||||
allFuncs := ssautil.AllFunctions(prog)
|
allFuncs := ssautil.AllFunctions(prog)
|
||||||
|
|
||||||
// Check that all non-synthetic functions have distinct names.
|
// Check that all non-synthetic functions have distinct names.
|
||||||
|
@ -118,5 +125,6 @@ func TestStdlib(t *testing.T) {
|
||||||
t.Log("#Packages: ", numPkgs)
|
t.Log("#Packages: ", numPkgs)
|
||||||
t.Log("#Functions: ", len(allFuncs))
|
t.Log("#Functions: ", len(allFuncs))
|
||||||
t.Log("#Instructions: ", numInstrs)
|
t.Log("#Instructions: ", numInstrs)
|
||||||
t.Log("#MB: ", int64(memstats.Alloc-alloc)/1000000)
|
t.Log("#MB AST+types: ", int64(alloc1-alloc0)/1e6)
|
||||||
|
t.Log("#MB SSA: ", int64(alloc3-alloc1)/1e6)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue