func init() { if os.Getenv("PPROF_SYNC") != "" { enabled = true } if enabled { lockHolders = pprof.NewProfile("lockHolders") lockBlockers = pprof.NewProfile("lockBlockers") } }
func Enable() { enableMu.Lock() defer enableMu.Unlock() if enabled { return } lockTimes = make(map[[32]uintptr]time.Duration) lockHolders = pprof.NewProfile("lockHolders") lockBlockers = pprof.NewProfile("lockBlockers") http.DefaultServeMux.HandleFunc("/debug/lockTimes", func(w http.ResponseWriter, r *http.Request) { PrintLockTimes(w) }) enabled = true }
package pproffd import ( "io" "net" "os" "runtime/pprof" ) var p = pprof.NewProfile("fds") type fd int func (me *fd) Closed() { p.Remove(me) } func Add(skip int) (ret *fd) { ret = new(fd) p.Add(ret, skip+2) return } type closeWrapper struct { fd *fd c io.Closer } func (me closeWrapper) Close() error { me.fd.Closed() return me.c.Close()