]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add mutex profiling support
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 5 Apr 2017 15:01:33 +0000 (08:01 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 5 Apr 2017 22:10:54 +0000 (22:10 +0000)
Updates #15756
Updates #19822

Change-Id: I98b17dcbbfd80e7e164b0523185382175fe2d89b
Reviewed-on: https://go-review.googlesource.com/39554
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/bootstrap.go [new file with mode: 0644]
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/pprof.go [new file with mode: 0644]
src/cmd/compile/internal/gc/util.go

index 0a364cabb743a57cf072755e604c8120c8dee768..83bd36c34cba96fa9cd8408eb7128dcbaa8c5258 100644 (file)
@@ -77,6 +77,8 @@ Flags:
                Set runtime.MemProfileRate for the compilation to rate.
        -msan
                Insert calls to C/C++ memory sanitizer.
+       -mutexprofile file
+               Write mutex profile for the compilation to file.
        -nolocalimports
                Disallow local (relative) imports.
        -o file
diff --git a/src/cmd/compile/internal/gc/bootstrap.go b/src/cmd/compile/internal/gc/bootstrap.go
new file mode 100644 (file)
index 0000000..967f75a
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2017 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.8
+
+package gc
+
+import "runtime"
+
+func startMutexProfiling() {
+       Fatalf("mutex profiling unavailable in version %v", runtime.Version())
+}
index b2efd7cbef2eb0e3f11503ee7e5fa51a1effd6ad..e850bef2b6a7a72d1607fe552b803817e701031c 100644 (file)
@@ -222,6 +222,7 @@ func Main(archInit func(*Arch)) {
        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(&mutexprofile, "mutexprofile", "", "write mutex profile to `file`")
        flag.StringVar(&benchfile, "bench", "", "append benchmark times to `file`")
        obj.Flagparse(usage)
 
diff --git a/src/cmd/compile/internal/gc/pprof.go b/src/cmd/compile/internal/gc/pprof.go
new file mode 100644 (file)
index 0000000..256c659
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2017 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.8
+
+package gc
+
+import "runtime"
+
+func startMutexProfiling() {
+       runtime.SetMutexProfileFraction(1)
+}
index 97fff063f8339582656e0b4cf74fda485f424852..58be2f82530a90cb694a7820ade234304a065ea4 100644 (file)
@@ -38,6 +38,7 @@ var (
        memprofilerate int64
        traceprofile   string
        traceHandler   func(string)
+       mutexprofile   string
 )
 
 func startProfile() {
@@ -85,6 +86,17 @@ func startProfile() {
                        f.Close()
                })
        }
+       if mutexprofile != "" {
+               f, err := os.Create(mutexprofile)
+               if err != nil {
+                       Fatalf("%v", err)
+               }
+               startMutexProfiling()
+               atExit(func() {
+                       pprof.Lookup("mutex").WriteTo(f, 0)
+                       f.Close()
+               })
+       }
        if traceprofile != "" && traceHandler != nil {
                traceHandler(traceprofile)
        }