Skip to content

Commit

Permalink
add default.pgo in client &
Browse files Browse the repository at this point in the history
added an option to enable pprof on client
  • Loading branch information
xtaci committed Aug 11, 2023
1 parent 589fe49 commit 55e6700
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Binary file added client/default.pgo
Binary file not shown.
13 changes: 13 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"math/rand"
"net"
"net/http"
_ "net/http/pprof"
"os"
"time"

Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 55e6700

Please sign in to comment.