package main import ( "runtime" profilerconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/profiler" httputil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/http" ) func initProfilerService(c *cfg) { tuneProfilers(c) pprof, _ := pprofComponent(c) pprof.init(c) } func pprofComponent(c *cfg) (*httpComponent, bool) { var updated bool // check if it has been inited before if c.dynamicConfiguration.pprof == nil { c.dynamicConfiguration.pprof = new(httpComponent) c.dynamicConfiguration.pprof.cfg = c c.dynamicConfiguration.pprof.name = "pprof" c.dynamicConfiguration.pprof.handler = httputil.Handler() c.dynamicConfiguration.pprof.preReload = tuneProfilers updated = true } // (re)init read configuration enabled := profilerconfig.Enabled(c.appCfg) if enabled != c.dynamicConfiguration.pprof.enabled { c.dynamicConfiguration.pprof.enabled = enabled updated = true } address := profilerconfig.Address(c.appCfg) if address != c.dynamicConfiguration.pprof.address { c.dynamicConfiguration.pprof.address = address updated = true } dur := profilerconfig.ShutdownTimeout(c.appCfg) if dur != c.dynamicConfiguration.pprof.shutdownDur { c.dynamicConfiguration.pprof.shutdownDur = dur updated = true } return c.dynamicConfiguration.pprof, updated } func tuneProfilers(c *cfg) { // Disabled by default, see documentation for // runtime.SetBlockProfileRate() and runtime.SetMutexProfileFraction(). blockRate := 0 mutexRate := 0 if profilerconfig.Enabled(c.appCfg) { blockRate = profilerconfig.BlockRate(c.appCfg) mutexRate = profilerconfig.MutexRate(c.appCfg) } runtime.SetBlockProfileRate(blockRate) runtime.SetMutexProfileFraction(mutexRate) }