2020-10-02 13:18:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-05-11 22:59:05 +00:00
|
|
|
"context"
|
|
|
|
|
2021-06-01 11:13:44 +00:00
|
|
|
profilerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/profiler"
|
2021-05-11 22:59:05 +00:00
|
|
|
httputil "github.com/nspcc-dev/neofs-node/pkg/util/http"
|
|
|
|
"go.uber.org/zap"
|
2020-10-02 13:18:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func initProfiler(c *cfg) {
|
2022-07-13 09:17:37 +00:00
|
|
|
if !profilerconfig.Enabled(c.appCfg) {
|
|
|
|
c.log.Info("pprof is disabled")
|
2021-05-11 22:59:05 +00:00
|
|
|
return
|
2020-10-02 13:18:38 +00:00
|
|
|
}
|
2021-05-11 22:59:05 +00:00
|
|
|
|
|
|
|
var prm httputil.Prm
|
|
|
|
|
2022-07-13 09:17:37 +00:00
|
|
|
prm.Address = profilerconfig.Address(c.appCfg)
|
2021-05-11 22:59:05 +00:00
|
|
|
prm.Handler = httputil.Handler()
|
|
|
|
|
|
|
|
srv := httputil.New(prm,
|
|
|
|
httputil.WithShutdownTimeout(
|
2021-06-01 11:13:44 +00:00
|
|
|
profilerconfig.ShutdownTimeout(c.appCfg),
|
2021-05-11 22:59:05 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
c.workers = append(c.workers, newWorkerFromFunc(func(context.Context) {
|
2022-05-25 16:18:36 +00:00
|
|
|
runAndLog(c, "profiler", false, func(c *cfg) {
|
|
|
|
fatalOnErr(srv.Serve())
|
|
|
|
})
|
2021-05-11 22:59:05 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
c.closers = append(c.closers, func() {
|
2021-08-04 14:44:37 +00:00
|
|
|
c.log.Debug("shutting down profiling service")
|
|
|
|
|
2021-05-11 22:59:05 +00:00
|
|
|
err := srv.Shutdown()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Debug("could not shutdown pprof server",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
2021-08-04 14:44:37 +00:00
|
|
|
|
|
|
|
c.log.Debug("profiling service has been stopped")
|
2021-05-11 22:59:05 +00:00
|
|
|
})
|
2020-10-02 13:18:38 +00:00
|
|
|
}
|