mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-857] Add generalized profiler package and use it everwhere * [NOD-857] Dependency-inject log into profiling.Start()
25 lines
588 B
Go
25 lines
588 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(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))
|
|
})
|
|
}
|