]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add block profiling support
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 3 Apr 2017 01:37:04 +0000 (18:37 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 3 Apr 2017 01:48:59 +0000 (01:48 +0000)
Updates #15756

Change-Id: Ic635812b324af926333122c02908cebfb24d7bce
Reviewed-on: https://go-review.googlesource.com/39208
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/doc.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/util.go

index 2e77f702e353f51d307034ac2bbf625392d8bc96..0a364cabb743a57cf072755e604c8120c8dee768 100644 (file)
@@ -44,6 +44,8 @@ Flags:
                Print compiler version and exit.
        -asmhdr file
                Write assembly header to file.
+       -blockprofile file
+               Write block profile for the compilation to file.
        -complete
                Assume package has no non-Go components.
        -cpuprofile file
index a0d5170a46bb2a7c6468f6e6d54404745e4d14fd..b2efd7cbef2eb0e3f11503ee7e5fa51a1effd6ad 100644 (file)
@@ -221,6 +221,7 @@ func Main(archInit func(*Arch)) {
        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(&blockprofile, "blockprofile", "", "write block profile to `file`")
        flag.StringVar(&benchfile, "bench", "", "append benchmark times to `file`")
        obj.Flagparse(usage)
 
index 947d8a8516ebb170862230ceb1e81dbb4a562bad..97fff063f8339582656e0b4cf74fda485f424852 100644 (file)
@@ -32,6 +32,7 @@ func Exit(code int) {
 }
 
 var (
+       blockprofile   string
        cpuprofile     string
        memprofile     string
        memprofilerate int64
@@ -73,6 +74,17 @@ func startProfile() {
                // Not doing memory profiling; disable it entirely.
                runtime.MemProfileRate = 0
        }
+       if blockprofile != "" {
+               f, err := os.Create(blockprofile)
+               if err != nil {
+                       Fatalf("%v", err)
+               }
+               runtime.SetBlockProfileRate(1)
+               atExit(func() {
+                       pprof.Lookup("block").WriteTo(f, 0)
+                       f.Close()
+               })
+       }
        if traceprofile != "" && traceHandler != nil {
                traceHandler(traceprofile)
        }