Commit 7e068895 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: add mutex profiling support

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9741f027
......@@ -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
......
// 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())
}
......@@ -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)
......
// 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)
}
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment