add flag to mox to store execution trace, similar to cpu/memory profiling

useful for performance testing
This commit is contained in:
Mechiel Lukkien 2023-09-12 14:43:52 +02:00
parent 4a4ccb83a3
commit 6f1e38f2ce
No known key found for this signature in database
2 changed files with 17 additions and 1 deletions

View file

@ -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 {

View file

@ -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")
}
}