14c35d776e
Include settings for block and mutex profilers. They are disabled by default, as in Go runtime itself. Signed-off-by: Pavel Karpy <p.karpy@yadro.com> Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
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)
|
|
}
|