From 2ee24998ba36986ccbc88a5cbabd2dd78244783e Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 2 Oct 2020 16:18:38 +0300 Subject: [PATCH] [#68] Add go pprof to neofs-storage Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 12 ++++++++++++ cmd/neofs-node/main.go | 2 ++ cmd/neofs-node/pprof.go | 15 +++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 cmd/neofs-node/pprof.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 73ce273453..eab122b9df 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -21,6 +21,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/network" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" "github.com/nspcc-dev/neofs-node/pkg/util/logger" + "github.com/nspcc-dev/neofs-node/pkg/util/profiler" "github.com/pkg/errors" "github.com/spf13/viper" "go.uber.org/zap" @@ -35,6 +36,11 @@ const ( cfgLogInitSampling = "logger.sampling.initial" cfgLogThereafterSampling = "logger.sampling.thereafter" + // pprof keys + cfgProfilerEnable = "pprof.enabled" + cfgProfilerAddr = "pprof.address" + cfgProfilerTTL = "pprof.shutdown_ttl" + // config keys for cfgNodeInfo cfgNodeKey = "node.key" cfgBootstrapAddress = "node.address" @@ -97,6 +103,8 @@ type cfg struct { localAddr *network.Address cfgObject cfgObject + + profiler profiler.Profiler } type cfgGRPC struct { @@ -269,6 +277,10 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgLogTrace, "fatal") v.SetDefault(cfgLogInitSampling, 1000) v.SetDefault(cfgLogThereafterSampling, 1000) + + v.SetDefault(cfgProfilerEnable, false) + v.SetDefault(cfgProfilerAddr, ":6060") + v.SetDefault(cfgProfilerTTL, "30s") } func (c *cfg) LocalAddress() *network.Address { diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 0cea0b023b..b496a85161 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -37,9 +37,11 @@ func init_(c *cfg) { initContainerService(c) initSessionService(c) initObjectService(c) + initProfiler(c) } func bootUp(c *cfg) { + serveProfiler(c) serveGRPC(c) bootstrapNode(c) } diff --git a/cmd/neofs-node/pprof.go b/cmd/neofs-node/pprof.go new file mode 100644 index 0000000000..ba4b4950c8 --- /dev/null +++ b/cmd/neofs-node/pprof.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/nspcc-dev/neofs-node/pkg/util/profiler" +) + +func initProfiler(c *cfg) { + c.profiler = profiler.NewProfiler(c.log, c.viper) +} + +func serveProfiler(c *cfg) { + if c.profiler != nil { + c.profiler.Start(c.ctx) + } +}