diff --git a/client/config.go b/client/config.go index 3d807b60c..def0aaf53 100644 --- a/client/config.go +++ b/client/config.go @@ -37,6 +37,7 @@ type Config struct { SnmpPeriod int `json:"snmpperiod"` Quiet bool `json:"quiet"` TCP bool `json:"tcp"` + Pprof bool `json:"pprof"` } func parseJSONConfig(config *Config, path string) error { diff --git a/client/default.pgo b/client/default.pgo new file mode 100644 index 000000000..f2168c53a Binary files /dev/null and b/client/default.pgo differ diff --git a/client/main.go b/client/main.go index 1f6709cb8..728780a55 100644 --- a/client/main.go +++ b/client/main.go @@ -7,6 +7,8 @@ import ( "log" "math/rand" "net" + "net/http" + _ "net/http/pprof" "os" "time" @@ -243,6 +245,10 @@ func main() { Value: "", // when the value is not empty, the config path must exists Usage: "config from json file, which will override the command from shell", }, + cli.BoolFlag{ + Name: "pprof", + Usage: "start profiling server on :6060", + }, } myApp.Action = func(c *cli.Context) error { config := Config{} @@ -276,6 +282,7 @@ func main() { config.SnmpPeriod = c.Int("snmpperiod") config.Quiet = c.Bool("quiet") config.TCP = c.Bool("tcp") + config.Pprof = c.Bool("pprof") if c.String("c") != "" { err := parseJSONConfig(&config, c.String("c")) @@ -341,6 +348,7 @@ func main() { log.Println("snmpperiod:", config.SnmpPeriod) log.Println("quiet:", config.Quiet) log.Println("tcp:", config.TCP) + log.Println("pprof:", config.Pprof) // parameters check if config.SmuxVer > maxSmuxVer { @@ -443,6 +451,11 @@ func main() { // start snmp logger go generic.SnmpLogger(config.SnmpLog, config.SnmpPeriod) + // start pprof + if config.Pprof { + go http.ListenAndServe(":6060", nil) + } + // start scavenger chScavenger := make(chan timedSession, 128) go scavenger(chScavenger, &config)