Skip to content

Commit

Permalink
Add global config to enable pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 committed Jun 10, 2024
1 parent ec7cf06 commit 9d207b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -270,6 +279,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
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Global struct {
SniffingTimeout time.Duration `mapstructure:"sniffing_timeout" default:"100ms"`
TlsImplementation string `mapstructure:"tls_implementation" default:"tls"`
UtlsImitate string `mapstructure:"utls_imitate" default:"chrome_auto"`
PprofPort uint16 `mapstructure:"pprof_port" default:"0"`
}

type Utls struct {
Expand Down
3 changes: 3 additions & 0 deletions example.dae
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ global {
# The Client Hello ID for uTLS to imitate. This takes effect only if tls_implementation is utls.
# See more: https://github.com/daeuniverse/dae/blob/331fa23c16/component/outbound/transport/tls/utls.go#L17
utls_imitate: chrome_auto

# Set non-zero value to enable pprof.
pprof_port: 6060
}

# Subscriptions defined here will be resolved as nodes and merged as a part of the global node pool.
Expand Down

0 comments on commit 9d207b5

Please sign in to comment.