]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: add runtime/trace support
authorDave Cheney <dave@cheney.net>
Mon, 1 Aug 2016 10:34:12 +0000 (20:34 +1000)
committerRuss Cox <rsc@golang.org>
Wed, 12 Oct 2016 13:57:26 +0000 (13:57 +0000)
This change adds runtime/trace support to go tool compile.

Change-Id: I6c496b9b063796123f75eba6af511c53a57c0196
Reviewed-on: https://go-review.googlesource.com/25354
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/trace.go [new file with mode: 0644]
src/cmd/compile/internal/gc/util.go

index 5179f68f4af431fb4ebfbc34ce016da71bde1715..321f34776a3f64471bedd4eb03c6d8bef4cf61c5 100644 (file)
@@ -208,6 +208,7 @@ func Main() {
        flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to `file`")
        flag.StringVar(&memprofile, "memprofile", "", "write memory profile to `file`")
        flag.Int64Var(&memprofilerate, "memprofilerate", 0, "set runtime.MemProfileRate to `rate`")
+       flag.StringVar(&traceprofile, "traceprofile", "", "write an execution trace to `file`")
        flag.StringVar(&benchfile, "bench", "", "append benchmark times to `file`")
        obj.Flagparse(usage)
 
diff --git a/src/cmd/compile/internal/gc/trace.go b/src/cmd/compile/internal/gc/trace.go
new file mode 100644 (file)
index 0000000..ed4b5a2
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build go1.7
+
+package gc
+
+import (
+       "os"
+       tracepkg "runtime/trace"
+)
+
+func init() {
+       traceHandler = traceHandlerGo17
+}
+
+func traceHandlerGo17(traceprofile string) {
+       f, err := os.Create(traceprofile)
+       if err != nil {
+               Fatalf("%v", err)
+       }
+       if err := tracepkg.Start(f); err != nil {
+               Fatalf("%v", err)
+       }
+       atExit(tracepkg.Stop)
+}
index 3786769a2424dd911150700f3f546d1397542240..bb5cede5a60da75f700594c4aede4dacfa39ae01 100644 (file)
@@ -33,6 +33,8 @@ var (
        cpuprofile     string
        memprofile     string
        memprofilerate int64
+       traceprofile   string
+       traceHandler   func(string)
 )
 
 func startProfile() {
@@ -61,4 +63,7 @@ func startProfile() {
                        }
                })
        }
+       if traceprofile != "" && traceHandler != nil {
+               traceHandler(traceprofile)
+       }
 }