mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-16 10:50:01 +07:00
chore: Add a global config to enable pprof (#532)
Co-authored-by: dae-prow[bot] <136105375+dae-prow[bot]@users.noreply.github.com>
This commit is contained in:
19
cmd/run.go
19
cmd/run.go
@ -25,6 +25,8 @@ import (
|
||||
"github.com/daeuniverse/outbound/protocol/direct"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/daeuniverse/dae/cmd/internal"
|
||||
"github.com/daeuniverse/dae/common"
|
||||
"github.com/daeuniverse/dae/common/consts"
|
||||
@ -124,6 +126,13 @@ func Run(log *logrus.Logger, conf *config.Config, externGeoDataDirs []string) (e
|
||||
return err
|
||||
}
|
||||
|
||||
var pprofServer *http.Server
|
||||
if conf.Global.PprofPort != 0 {
|
||||
pprofAddr := fmt.Sprintf("localhost:%d", conf.Global.PprofPort)
|
||||
pprofServer = &http.Server{Addr: pprofAddr, Handler: nil}
|
||||
go pprofServer.ListenAndServe()
|
||||
}
|
||||
|
||||
// Serve tproxy TCP/UDP server util signals.
|
||||
var listener *control.Listener
|
||||
sigs := make(chan os.Signal, 1)
|
||||
@ -277,6 +286,16 @@ loop:
|
||||
oldC.AbortConnections()
|
||||
}
|
||||
oldC.Close()
|
||||
|
||||
if pprofServer != nil {
|
||||
pprofServer.Shutdown(context.Background())
|
||||
pprofServer = nil
|
||||
}
|
||||
if newConf.Global.PprofPort != 0 {
|
||||
pprofAddr := fmt.Sprintf("localhost:%d", conf.Global.PprofPort)
|
||||
pprofServer = &http.Server{Addr: pprofAddr, Handler: nil}
|
||||
go pprofServer.ListenAndServe()
|
||||
}
|
||||
case syscall.SIGHUP:
|
||||
// Ignore.
|
||||
continue
|
||||
|
Reference in New Issue
Block a user