add -pprof option for debuging purpose

This commit is contained in:
xtaci
2017-03-12 20:53:53 +08:00
parent ad8683d46c
commit 7df2c447db
4 changed files with 25 additions and 0 deletions
+1
View File
@@ -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 {
+11
View File
@@ -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()
+1
View File
@@ -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 {
+12
View File
@@ -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())