mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00

Allows to dynamically change the MutexProfileFraction to enable and disable mutex profiling. It should be very useful for detecting deadlocks, lock contention and general concurrency problems. How to use: To enable run: curl -X POST -v 'localhost:5001/debug/pprof-mutex/?fraction=10 To disable: curl -X POST -v 'localhost:5001/debug/pprof-mutex/?fraction=0' Fraction defines which fraction of events will be profiled. Higher it is the lower performance impact but less reliable the result. To fetch the result use: go tool pprof $PATH_TO_IPFS_BIN http://localhost:5001/debug/pprof/mutex License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package corehttp
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"runtime"
|
|
"strconv"
|
|
|
|
core "github.com/ipfs/go-ipfs/core"
|
|
)
|
|
|
|
// MutexFractionOption allows to set runtime.SetMutexProfileFraction via HTTP
|
|
// using POST request with parameter 'fraction'.
|
|
func MutexFractionOption(path string) ServeOption {
|
|
return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
|
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
if err := r.ParseForm(); err != nil {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
w.Write([]byte(err.Error()))
|
|
return
|
|
}
|
|
|
|
asfr := r.Form.Get("fraction")
|
|
if len(asfr) == 0 {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
fr, err := strconv.Atoi(asfr)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
w.Write([]byte(err.Error()))
|
|
return
|
|
}
|
|
log.Infof("Setting MutexProfileFraction to %d", fr)
|
|
runtime.SetMutexProfileFraction(fr)
|
|
})
|
|
|
|
return mux, nil
|
|
}
|
|
}
|