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:
/gray
2024-06-16 14:41:52 +08:00
committed by GitHub
parent 795bd0560e
commit 137e8f2278
3 changed files with 23 additions and 0 deletions

View File

@ -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