cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")
blockProfile = flag.String("test.blockprofile", "", "write a goroutine blocking profile to the named file after execution")
blockProfileRate = flag.Int("test.blockprofilerate", 1, "if >= 0, calls runtime.SetBlockProfileRate()")
+ trace = flag.String("test.trace", "", "write an execution trace to the named file after execution")
timeout = flag.Duration("test.timeout", 0, "if positive, sets an aggregate time limit for all tests")
cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test")
parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "maximum test parallelism")
}
// Could save f so after can call f.Close; not worth the effort.
}
+ if *trace != "" {
+ f, err := os.Create(toOutputDir(*trace))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "testing: %s", err)
+ return
+ }
+ if err := pprof.StartTrace(f); err != nil {
+ fmt.Fprintf(os.Stderr, "testing: can't start tracing: %s", err)
+ f.Close()
+ return
+ }
+ // Could save f so after can call f.Close; not worth the effort.
+ }
if *blockProfile != "" && *blockProfileRate >= 0 {
runtime.SetBlockProfileRate(*blockProfileRate)
}
if *cpuProfile != "" {
pprof.StopCPUProfile() // flushes profile to disk
}
+ if *trace != "" {
+ pprof.StopTrace() // flushes trace to disk
+ }
if *memProfile != "" {
f, err := os.Create(toOutputDir(*memProfile))
if err != nil {