kaspad/util/profiling/profiling.go
Ori Newman 7e81757e2f
[NOD-1161] Name goroutines and log them by the name (#804)
* [NOD-1161] Name goroutines and log them by the name

* [NOD-1161] Fix some goroutine names
2020-07-20 13:00:23 +03:00

25 lines
607 B
Go

package profiling
import (
"net"
"net/http"
// Required for profiling
_ "net/http/pprof"
"github.com/kaspanet/kaspad/logs"
"github.com/kaspanet/kaspad/util/panics"
)
// Start starts the profiling server
func Start(port string, log *logs.Logger) {
spawn := panics.GoroutineWrapperFunc(log)
spawn("profiling.Start", func() {
listenAddr := net.JoinHostPort("", port)
log.Infof("Profile server listening on %s", listenAddr)
profileRedirect := http.RedirectHandler("/debug/pprof", http.StatusSeeOther)
http.Handle("/", profileRedirect)
log.Error(http.ListenAndServe(listenAddr, nil))
})
}