@@ -17,6 +17,7 @@ import (
1717 "math/rand"
1818 "net"
1919 "net/http"
20+ "net/http/pprof"
2021 "os"
2122 "os/exec"
2223 "os/signal"
5758type Config struct {
5859 AddrHTTP string
5960 AddrSOCKS string
61+ AddrPprof string
6062 User string
6163 Pass string
6264 ServerUser string
@@ -136,6 +138,7 @@ type proxyapp struct {
136138 certFile string
137139 keyFile string
138140 httpServerAddr string
141+ pprofAddr string
139142 iface * net.Interface
140143 tproxyAddr string
141144 tproxyAddrUDP string
@@ -244,6 +247,12 @@ func New(conf *Config) *proxyapp {
244247 lvl = zerolog .DebugLevel
245248 }
246249 p .debug = conf .Debug
250+ if conf .AddrPprof != "" {
251+ p .pprofAddr , err = getFullAddress (conf .AddrPprof , "" , false )
252+ if err != nil {
253+ p .logger .Fatal ().Err (err ).Msg ("" )
254+ }
255+ }
247256 // the only way I found to make debug level independent between loggers
248257 l := logger .Level (lvl )
249258 sl := snifflogger .Level (lvl )
@@ -504,6 +513,9 @@ func New(conf *Config) *proxyapp {
504513 if p .tproxyAddrUDP != "" {
505514 p .logger .Info ().Msgf ("TPROXY (UDP): %s" , p .tproxyAddrUDP )
506515 }
516+ if p .pprofAddr != "" {
517+ p .logger .Info ().Msgf ("PPROF: %s" , p .pprofAddr )
518+ }
507519 return & p
508520}
509521
@@ -512,6 +524,15 @@ func (p *proxyapp) Run() {
512524 quit := make (chan os.Signal , 1 )
513525 p .closeConn = make (chan bool )
514526 signal .Notify (quit , os .Interrupt )
527+ if p .pprofAddr != "" {
528+ sm := http .NewServeMux ()
529+ sm .HandleFunc ("/debug/pprof/" , pprof .Index )
530+ sm .HandleFunc ("/debug/pprof/cmdline" , pprof .Cmdline )
531+ sm .HandleFunc ("/debug/pprof/profile" , pprof .Profile )
532+ sm .HandleFunc ("/debug/pprof/symbol" , pprof .Symbol )
533+ sm .HandleFunc ("/debug/pprof/trace" , pprof .Trace )
534+ go http .ListenAndServe (p .pprofAddr , sm )
535+ }
515536 if p .arpspoofer != nil {
516537 go p .arpspoofer .Start ()
517538 }
0 commit comments