Merge pull request #127 from colincross/memprofile
Add support for memory profiling
This commit is contained in:
commit
53d4357592
1 changed files with 18 additions and 0 deletions
|
@ -22,6 +22,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"runtime/pprof"
|
||||
"runtime/trace"
|
||||
|
||||
|
@ -34,8 +35,10 @@ var (
|
|||
depFile string
|
||||
docFile string
|
||||
cpuprofile string
|
||||
memprofile string
|
||||
traceFile string
|
||||
runGoTests bool
|
||||
noGC bool
|
||||
|
||||
BuildDir string
|
||||
SrcDir string
|
||||
|
@ -48,6 +51,8 @@ func init() {
|
|||
flag.StringVar(&docFile, "docs", "", "build documentation file to output")
|
||||
flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to file")
|
||||
flag.StringVar(&traceFile, "trace", "", "write trace to file")
|
||||
flag.StringVar(&memprofile, "memprofile", "", "write memory profile to file")
|
||||
flag.BoolVar(&noGC, "nogc", false, "turn off GC for debugging")
|
||||
flag.BoolVar(&runGoTests, "t", false, "build and run go tests during bootstrap")
|
||||
}
|
||||
|
||||
|
@ -58,6 +63,10 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
|
|||
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
||||
if noGC {
|
||||
debug.SetGCPercent(-1)
|
||||
}
|
||||
|
||||
if cpuprofile != "" {
|
||||
f, err := os.Create(cpuprofile)
|
||||
if err != nil {
|
||||
|
@ -160,6 +169,15 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
|
|||
fatalf("error removing abandoned files: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if memprofile != "" {
|
||||
f, err := os.Create(memprofile)
|
||||
if err != nil {
|
||||
fatalf("error opening memprofile: %s", err)
|
||||
}
|
||||
defer f.Close()
|
||||
pprof.WriteHeapProfile(f)
|
||||
}
|
||||
}
|
||||
|
||||
func fatalf(format string, args ...interface{}) {
|
||||
|
|
Loading…
Reference in a new issue