aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-06-05 22:45:11 +0200
committerJakob Unterwurzacher2017-06-07 22:09:06 +0200
commit71978ec88a2aa8ec92df080a4a6becf623957c81 (patch)
treedee06235a540e7188a6defc6f2bc6057cd000af5 /main.go
parent22820bcd76a781d09ce82f6e734013d55afc1e5c (diff)
Add "-trace" flag (record execution trace)
Uses the runtime/trace functionality. TODO: add to man page.
Diffstat (limited to 'main.go')
-rw-r--r--main.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/main.go b/main.go
index 1599d53..13514c1 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
+ "runtime/trace"
"strconv"
"strings"
"time"
@@ -212,9 +213,13 @@ func main() {
f, err = os.Create(args.cpuprofile)
if err != nil {
tlog.Fatal.Println(err)
- os.Exit(exitcodes.Init)
+ os.Exit(exitcodes.Profiler)
+ }
+ err = pprof.StartCPUProfile(f)
+ if err != nil {
+ tlog.Fatal.Println(err)
+ os.Exit(exitcodes.Profiler)
}
- pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
// "-memprofile"
@@ -224,7 +229,7 @@ func main() {
f, err = os.Create(args.memprofile)
if err != nil {
tlog.Fatal.Println(err)
- os.Exit(exitcodes.Init)
+ os.Exit(exitcodes.Profiler)
}
defer func() {
pprof.WriteHeapProfile(f)
@@ -232,7 +237,22 @@ func main() {
return
}()
}
- if args.cpuprofile != "" || args.memprofile != "" {
+ // "-trace"
+ if args.trace != "" {
+ tlog.Info.Printf("Writing execution trace to %s", args.trace)
+ f, err := os.Create(args.trace)
+ if err != nil {
+ tlog.Fatal.Println(err)
+ os.Exit(exitcodes.Profiler)
+ }
+ err = trace.Start(f)
+ if err != nil {
+ tlog.Fatal.Println(err)
+ os.Exit(exitcodes.Profiler)
+ }
+ defer trace.Stop()
+ }
+ if args.cpuprofile != "" || args.memprofile != "" || args.trace != "" {
tlog.Info.Printf("Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!\n")
}
// "-openssl"