summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-03-01 16:10:38 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-29 15:34:28 -0800
commite2171a0ca07b38932a3478dea0dfd2d9fb97b83f (patch)
treeae2e0012f41f3d6f438d9144f549d6fcf0d6fd19
parent496f0b6d26daf5eb60f662cb47ba44b31d91e1cd (diff)
cli: add an options to enable profiling
$ gobgp -r 10000 monitor global rib this will enable profiling through tcp port 10000 $ go tool pprof 'http://localhost:10000/debug/pprof/profile?seconds=10' Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/cmd/root.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/gobgp/cmd/root.go b/gobgp/cmd/root.go
index 58028881..dcd69d8b 100644
--- a/gobgp/cmd/root.go
+++ b/gobgp/cmd/root.go
@@ -16,8 +16,12 @@
package cmd
import (
+ "fmt"
api "github.com/osrg/gobgp/api"
"github.com/spf13/cobra"
+ "net/http"
+ _ "net/http/pprof"
+ "os"
)
var globalOpts struct {
@@ -28,6 +32,7 @@ var globalOpts struct {
Json bool
GenCmpl bool
BashCmplFile string
+ PprofPort int
}
var cmds []string
@@ -38,6 +43,15 @@ func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "gobgp",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
+ if globalOpts.PprofPort > 0 {
+ go func() {
+ if err := http.ListenAndServe(fmt.Sprintf("localhost:%d", globalOpts.PprofPort), nil); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ }()
+ }
+
if !globalOpts.GenCmpl {
conn := connGrpc()
client = api.NewGobgpApiClient(conn)
@@ -59,6 +73,7 @@ func NewRootCmd() *cobra.Command {
rootCmd.PersistentFlags().BoolVarP(&globalOpts.Quiet, "quiet", "q", false, "use quiet")
rootCmd.PersistentFlags().BoolVarP(&globalOpts.GenCmpl, "gen-cmpl", "c", false, "generate completion file")
rootCmd.PersistentFlags().StringVarP(&globalOpts.BashCmplFile, "bash-cmpl-file", "", "gobgp-completion.bash", "bash cmpl filename")
+ rootCmd.PersistentFlags().IntVarP(&globalOpts.PprofPort, "pprof-port", "r", 0, "pprof port")
globalCmd := NewGlobalCmd()
neighborCmd := NewNeighborCmd()