Add option to trace goroutine execution

Passing -trace <file> on the command line produces a trace file that can
be used with go tool trace to examine concurrency.

Change-Id: I7d27bca64d0f0816cb4e518e947b70bc1c0573a3
This commit is contained in:
Colin Cross 2016-08-05 13:59:43 -07:00
parent 01ee36eeea
commit aec881da86

View file

@ -23,6 +23,7 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
"runtime/trace"
"github.com/google/blueprint"
"github.com/google/blueprint/deptools"
@ -36,6 +37,7 @@ var (
manifestFile string
docFile string
cpuprofile string
traceFile string
runGoTests bool
BuildDir string
@ -50,6 +52,7 @@ func init() {
flag.StringVar(&manifestFile, "m", "", "the bootstrap manifest file")
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.BoolVar(&runGoTests, "t", false, "build and run go tests during bootstrap")
}
@ -70,6 +73,16 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
defer pprof.StopCPUProfile()
}
if traceFile != "" {
f, err := os.Create(traceFile)
if err != nil {
fatalf("error opening trace: %s", err)
}
trace.Start(f)
defer f.Close()
defer trace.Stop()
}
if flag.NArg() != 1 {
fatalf("no Blueprints file specified")
}