aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-12-12 19:43:23 +0100
committerDmitry Vyukov <dvyukov@google.com>2015-01-28 16:43:00 +0000
commit20004ba889f9efe02e64b3c5a8287f7b50443ce7 (patch)
tree80b3880f6731fdcc2114cbcd608a1fdca299ced8 /src/testing/testing.go
parent986a1d2d1c4000955c5b63cf9a87cba91367b701 (diff)
downloadgo-20004ba889f9efe02e64b3c5a8287f7b50443ce7.tar.xz
testing: add tracing support
testing part of tracing functionality: https://docs.google.com/document/u/1/d/1FP5apqzBgr7ahCCgFO-yoVhk4YZrNIDNf9RybngBc14/pub Full change: https://codereview.appspot.com/146920043 Change-Id: Ia3c2c4417106937d5775b0e7064db92c1fc36679 Reviewed-on: https://go-review.googlesource.com/1461 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index e54a3b8ce4..966b5466b7 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -175,6 +175,7 @@ var (
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")
@@ -600,6 +601,19 @@ func before() {
}
// 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)
}
@@ -614,6 +628,9 @@ func after() {
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 {