diff --git a/client/config.go b/client/config.go index 0c160e1..9d7dc21 100644 --- a/client/config.go +++ b/client/config.go @@ -32,6 +32,7 @@ type Config struct { Log string `json:"log"` SnmpLog string `json:"snmplog"` SnmpPeriod int `json:"snmpperiod"` + Pprof bool `json:"pprof"` } func parseJSONConfig(config *Config, path string) error { diff --git a/client/main.go b/client/main.go index f617fae..ea195f0 100644 --- a/client/main.go +++ b/client/main.go @@ -8,6 +8,8 @@ import ( "log" "math/rand" "net" + "net/http" + _ "net/http/pprof" "os" "sync" "time" @@ -236,6 +238,10 @@ func main() { Value: 60, Usage: "snmp collect period, in seconds", }, + cli.BoolFlag{ + Name: "pprof", + Usage: "start profiling server on :6060", + }, cli.StringFlag{ Name: "log", Value: "", @@ -274,6 +280,7 @@ func main() { config.Log = c.String("log") config.SnmpLog = c.String("snmplog") config.SnmpPeriod = c.Int("snmpperiod") + config.Pprof = c.Bool("pprof") if c.String("c") != "" { err := parseJSONConfig(&config, c.String("c")) @@ -352,6 +359,7 @@ func main() { log.Println("scavengettl:", config.ScavengeTTL) log.Println("snmplog:", config.SnmpLog) log.Println("snmpperiod:", config.SnmpPeriod) + log.Println("pprof:", config.Pprof) smuxConfig := smux.DefaultConfig() smuxConfig.MaxReceiveBuffer = config.SockBuf @@ -417,6 +425,9 @@ func main() { chScavenger := make(chan *smux.Session, 128) go scavenger(chScavenger, config.ScavengeTTL) go snmpLogger(config.SnmpLog, config.SnmpPeriod) + if c.Bool("pprof") { + go http.ListenAndServe("0.0.0.0:6060", nil) + } rr := uint16(0) for { p1, err := listener.AcceptTCP() diff --git a/server/config.go b/server/config.go index 0972498..691b4ce 100644 --- a/server/config.go +++ b/server/config.go @@ -29,6 +29,7 @@ type Config struct { Log string `json:"log"` SnmpLog string `json:"snmplog"` SnmpPeriod int `json:"snmpperiod"` + Pprof bool `json:"pprof"` } func parseJSONConfig(config *Config, path string) error { diff --git a/server/main.go b/server/main.go index a230943..4454541 100644 --- a/server/main.go +++ b/server/main.go @@ -8,6 +8,8 @@ import ( "log" "math/rand" "net" + "net/http" + _ "net/http/pprof" "os" "sync" "time" @@ -245,6 +247,10 @@ func main() { Value: 60, Usage: "snmp collect period, in seconds", }, + cli.BoolFlag{ + Name: "pprof", + Usage: "start profiling server on :6060", + }, cli.StringFlag{ Name: "log", Value: "", @@ -280,6 +286,7 @@ func main() { config.Log = c.String("log") config.SnmpLog = c.String("snmplog") config.SnmpPeriod = c.Int("snmpperiod") + config.Pprof = c.Bool("pprof") if c.String("c") != "" { //Now only support json config file @@ -353,6 +360,7 @@ func main() { log.Println("keepalive:", config.KeepAlive) log.Println("snmplog:", config.SnmpLog) log.Println("snmpperiod:", config.SnmpPeriod) + log.Println("pprof:", config.Pprof) if err := lis.SetDSCP(config.DSCP); err != nil { log.Println("SetDSCP:", err) @@ -365,6 +373,10 @@ func main() { } go snmpLogger(config.SnmpLog, config.SnmpPeriod) + if c.Bool("pprof") { + go http.ListenAndServe("0.0.0.0:6060", nil) + } + for { if conn, err := lis.AcceptKCP(); err == nil { log.Println("remote address:", conn.RemoteAddr())