mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 08:23:48 +03:00
add flag to mox to store execution trace, similar to cpu/memory profiling
useful for performance testing
This commit is contained in:
parent
4a4ccb83a3
commit
6f1e38f2ce
2 changed files with 17 additions and 1 deletions
6
main.go
6
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(&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")
|
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(&cpuprofile, "cpuprof", "", "store cpu profile to file")
|
||||||
flag.StringVar(&memprofile, "memprof", "", "store mem 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.Usage = func() { usage(cmds, false) }
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -418,6 +419,9 @@ func main() {
|
||||||
usage(cmds, false)
|
usage(cmds, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tracefile != "" {
|
||||||
|
defer traceExecution(tracefile)()
|
||||||
|
}
|
||||||
defer profile(cpuprofile, memprofile)()
|
defer profile(cpuprofile, memprofile)()
|
||||||
|
|
||||||
if pedantic {
|
if pedantic {
|
||||||
|
|
12
profile.go
12
profile.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"runtime/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
func memprofile(mempath string) {
|
func memprofile(mempath string) {
|
||||||
|
@ -43,3 +44,14 @@ func profile(cpupath, mempath string) func() {
|
||||||
memprofile(mempath)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue