From 83657a194209984dd8e59f617b57aa97dce6112d Mon Sep 17 00:00:00 2001 From: Luca Moser <moser.luca@gmail.com> Date: Tue, 21 Apr 2020 10:47:30 +0200 Subject: [PATCH] Makes pprof profiling a plugin (#342) * makes pprof profiling a plugin * Update plugins/profiling/plugin.go Co-Authored-By: Angelo Capossele <angelocapossele@gmail.com> * Update pluginmgr/core/plugins.go Co-Authored-By: Angelo Capossele <angelocapossele@gmail.com> Co-authored-by: Angelo Capossele <angelocapossele@gmail.com> --- main.go | 3 --- pluginmgr/core/plugins.go | 2 ++ plugins/profiling/plugin.go | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 plugins/profiling/plugin.go diff --git a/main.go b/main.go index 05169518..68195928 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "net/http" _ "net/http/pprof" "github.com/iotaledger/goshimmer/pluginmgr/core" @@ -13,8 +12,6 @@ import ( ) func main() { - go http.ListenAndServe("localhost:6061", nil) // pprof Server for Debbuging Mutexes - node.Run( core.PLUGINS, research.PLUGINS, diff --git a/pluginmgr/core/plugins.go b/pluginmgr/core/plugins.go index cb4692f7..ecb28954 100644 --- a/pluginmgr/core/plugins.go +++ b/pluginmgr/core/plugins.go @@ -13,6 +13,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/messagelayer" "github.com/iotaledger/goshimmer/plugins/metrics" "github.com/iotaledger/goshimmer/plugins/portcheck" + "github.com/iotaledger/goshimmer/plugins/profiling" "github.com/iotaledger/hive.go/node" ) @@ -23,6 +24,7 @@ var PLUGINS = node.Plugins( logger.PLUGIN, cli.PLUGIN, portcheck.PLUGIN, + profiling.Plugin, database.PLUGIN, autopeering.PLUGIN, messagelayer.PLUGIN, diff --git a/plugins/profiling/plugin.go b/plugins/profiling/plugin.go new file mode 100644 index 00000000..6e823650 --- /dev/null +++ b/plugins/profiling/plugin.go @@ -0,0 +1,26 @@ +package profiling + +import ( + "net/http" + _ "net/http/pprof" + + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/hive.go/node" + flag "github.com/spf13/pflag" +) + +var ( + Plugin = node.NewPlugin("Profiling", node.Enabled, configure, run) +) + +const CfgProfilingBindAddress = "profiling.bindAddress" + +func init() { + flag.String(CfgProfilingBindAddress, "localhost:6061", "bind address for the pprof server") +} + +func configure(_ *node.Plugin) {} + +func run(_ *node.Plugin) { + go http.ListenAndServe(config.Node.GetString(CfgProfilingBindAddress), nil) +} -- GitLab