diff --git a/main.go b/main.go index 10ec02c..3eea02f 100644 --- a/main.go +++ b/main.go @@ -407,9 +407,10 @@ func main() { flag.BoolVar(&pedantic, "pedantic", false, "protocol violations result in errors instead of accepting/working around them") flag.BoolVar(&store.CheckConsistencyOnClose, "checkconsistency", false, "dangerous option for testing only, enables data checks that abort/panic when inconsistencies are found") - var cpuprofile, memprofile string + var cpuprofile, memprofile, tracefile string flag.StringVar(&cpuprofile, "cpuprof", "", "store cpu profile to file") flag.StringVar(&memprofile, "memprof", "", "store mem profile to file") + flag.StringVar(&tracefile, "trace", "", "store execution trace to file") flag.Usage = func() { usage(cmds, false) } flag.Parse() @@ -418,6 +419,9 @@ func main() { usage(cmds, false) } + if tracefile != "" { + defer traceExecution(tracefile)() + } defer profile(cpuprofile, memprofile)() if pedantic { diff --git a/profile.go b/profile.go index 4441c5a..251e37d 100644 --- a/profile.go +++ b/profile.go @@ -5,6 +5,7 @@ import ( "os" "runtime" "runtime/pprof" + "runtime/trace" ) func memprofile(mempath string) { @@ -43,3 +44,14 @@ func profile(cpupath, mempath string) func() { memprofile(mempath) } } + +func traceExecution(path string) func() { + f, err := os.Create(path) + xcheckf(err, "create trace file") + trace.Start(f) + return func() { + trace.Stop() + err := f.Close() + xcheckf(err, "close trace file") + } +}