OSDN Git Service

Add go profiling programs (#109)
authorGuanghua Guo <1536310027@qq.com>
Fri, 17 Nov 2017 06:08:48 +0000 (14:08 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 17 Nov 2017 06:08:48 +0000 (14:08 +0800)
cmd/bytomd/commands/run_node.go
node/node.go

index a816f9f..42c45af 100644 (file)
@@ -19,6 +19,8 @@ var runNodeCmd = &cobra.Command{
 }
 
 func init() {
+       runNodeCmd.Flags().String("prof_laddr", config.ProfListenAddress, "Use http to profile bytomd programs")
+
        // p2p flags
        runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
        runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
index 32ca2f7..5f369ff 100644 (file)
@@ -261,14 +261,14 @@ func NewNode(config *cfg.Config) *Node {
                sw.AddReactor("PEX", pexReactor)
        }
 
-       // add the event switch to all services
-       // they should all satisfy events.Eventable
-       //SetEventSwitch(eventSwitch, bcReactor, mempoolReactor, consensusReactor)
-
        // run the profile server
        profileHost := config.ProfListenAddress
        if profileHost != "" {
-               // to do: start profile host
+               // Profiling bytomd programs.see (https://blog.golang.org/profiling-go-programs)
+               // go tool pprof http://profileHose/debug/pprof/heap
+               go func() {
+                       http.ListenAndServe(profileHost, nil)
+               } ()
        }
 
        node := &Node{