From 5161b747991da9137ac33868a1a68478b9149d75 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 18 Apr 2017 10:00:09 -0700 Subject: [PATCH] pkg/debugutil: add 'mutex' profiler (Go 1.8+) Signed-off-by: Gyu-Ho Lee --- pkg/debugutil/pprof.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/debugutil/pprof.go b/pkg/debugutil/pprof.go index 2e87124b8..8d5544a3d 100644 --- a/pkg/debugutil/pprof.go +++ b/pkg/debugutil/pprof.go @@ -17,12 +17,19 @@ package debugutil import ( "net/http" "net/http/pprof" + "runtime" ) const HTTPPrefixPProf = "/debug/pprof" // PProfHandlers returns a map of pprof handlers keyed by the HTTP path. func PProfHandlers() map[string]http.Handler { + // set only when there's no existing setting + if runtime.SetMutexProfileFraction(-1) == 0 { + // 1 out of 5 mutex events are reported, on average + runtime.SetMutexProfileFraction(5) + } + m := make(map[string]http.Handler) m[HTTPPrefixPProf+"/"] = http.HandlerFunc(pprof.Index) @@ -34,6 +41,7 @@ func PProfHandlers() map[string]http.Handler { m[HTTPPrefixPProf+"/goroutine"] = pprof.Handler("goroutine") m[HTTPPrefixPProf+"/threadcreate"] = pprof.Handler("threadcreate") m[HTTPPrefixPProf+"/block"] = pprof.Handler("block") + m[HTTPPrefixPProf+"/mutex"] = pprof.Handler("mutex") return m }