Skip to content

Commit

Permalink
Add pprof flag
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Feb 12, 2020
1 parent 006e5e1 commit d0e4ea9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cmd/minter/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,38 @@ import (
rpc "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/store"
tmTypes "github.com/tendermint/tendermint/types"
"net/http"
_ "net/http/pprof"
"os"
)

var RunNode = &cobra.Command{
Use: "node",
Short: "Run the Minter node",
RunE: func(cmd *cobra.Command, args []string) error {
return runNode()
return runNode(cmd)
},
}

func runNode() error {
func runNode(cmd *cobra.Command) error {
logger := log.NewLogger(cfg)

pprofOn, err := cmd.Flags().GetBool("pprof")
if err != nil {
return err
}

if pprofOn {
pprofMux := http.DefaultServeMux
http.DefaultServeMux = http.NewServeMux()
go func() {
logger.Error((&http.Server{
Addr: "localhost:6060",
Handler: pprofMux,
}).ListenAndServe().Error())
}()
}

tmConfig := config.GetTmConfig(cfg)

if err := tmos.EnsureDir(utils.GetMinterHome()+"/config", 0777); err != nil {
Expand All @@ -52,7 +72,6 @@ func runNode() error {
}

app := minter.NewMinterBlockchain(cfg)
logger := log.NewLogger(cfg)

// update BlocksTimeDelta in case it was corrupted
updateBlocksTimeDelta(app, tmConfig)
Expand Down
1 change: 1 addition & 0 deletions cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {

rootCmd.PersistentFlags().StringVar(&utils.MinterHome, "home-dir", "", "base dir (default is $HOME/.minter)")
rootCmd.PersistentFlags().StringVar(&utils.MinterConfig, "config", "", "path to config (default is $(home-dir)/config/config.toml)")
rootCmd.PersistentFlags().Bool("pprof", false, "enable pprof")

if err := rootCmd.Execute(); err != nil {
panic(err)
Expand Down

0 comments on commit d0e4ea9

Please sign in to comment.