예제 #1
0
func init() {
	if os.Getenv("PPROF_SYNC") != "" {
		enabled = true
	}
	if enabled {
		lockHolders = pprof.NewProfile("lockHolders")
		lockBlockers = pprof.NewProfile("lockBlockers")
	}
}
예제 #2
0
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
}
예제 #3
0
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()