aboutsummaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorPeter Weinberger <pjw@google.com>2016-09-22 09:48:30 -0400
committerPeter Weinberger <pjw@google.com>2016-10-28 11:47:16 +0000
commitca922b6d363b6ca47822188dcbc5b92d912c7a4b (patch)
tree5bee54a86cd9db992e5d77e735b94d9a0eed9a17 /src/sync
parentb679665a182bd6ec2989ae759df6b11142921cfb (diff)
downloadgo-ca922b6d363b6ca47822188dcbc5b92d912c7a4b.tar.xz
runtime: Profile goroutines holding contended mutexes.
runtime.SetMutexProfileFraction(n int) will capture 1/n-th of stack traces of goroutines holding contended mutexes if n > 0. From runtime/pprof, pprot.Lookup("mutex").WriteTo writes the accumulated stack traces to w (in essentially the same format that blocking profiling uses). Change-Id: Ie0b54fa4226853d99aa42c14cb529ae586a8335a Reviewed-on: https://go-review.googlesource.com/29650 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/mutex.go2
-rw-r--r--src/sync/mutex_test.go4
-rw-r--r--src/sync/runtime.go3
3 files changed, 8 insertions, 1 deletions
diff --git a/src/sync/mutex.go b/src/sync/mutex.go
index 717934344e..8c9366f4fe 100644
--- a/src/sync/mutex.go
+++ b/src/sync/mutex.go
@@ -84,7 +84,7 @@ func (m *Mutex) Lock() {
if old&mutexLocked == 0 {
break
}
- runtime_Semacquire(&m.sema)
+ runtime_SemacquireMutex(&m.sema)
awoke = true
iter = 0
}
diff --git a/src/sync/mutex_test.go b/src/sync/mutex_test.go
index fbfe4b77fe..88dbccf3ad 100644
--- a/src/sync/mutex_test.go
+++ b/src/sync/mutex_test.go
@@ -66,6 +66,10 @@ func HammerMutex(m *Mutex, loops int, cdone chan bool) {
}
func TestMutex(t *testing.T) {
+ if n := runtime.SetMutexProfileFraction(1); n != 0 {
+ t.Logf("got mutexrate %d expected 0", n)
+ }
+ defer runtime.SetMutexProfileFraction(0)
m := new(Mutex)
c := make(chan bool)
for i := 0; i < 10; i++ {
diff --git a/src/sync/runtime.go b/src/sync/runtime.go
index 96c56c8522..4d22ce6b0d 100644
--- a/src/sync/runtime.go
+++ b/src/sync/runtime.go
@@ -13,6 +13,9 @@ import "unsafe"
// library and should not be used directly.
func runtime_Semacquire(s *uint32)
+// SemacquireMutex is like Semacquire, but for profiling contended Mutexes.
+func runtime_SemacquireMutex(*uint32)
+
// Semrelease atomically increments *s and notifies a waiting goroutine
// if one is blocked in Semacquire.
// It is intended as a simple wakeup primitive for use by the synchronization