1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-23 09:46:55 -05:00
v2fly/main/plugins/plugin_pprof/plugin_pprof.go

30 lines
751 B
Go
Raw Normal View History

package plugin_pprof
2024-08-21 22:50:05 -04:00
import (
"github.com/v2fly/v2ray-core/v5/main/plugins"
2024-08-21 22:50:05 -04:00
"net/http"
"net/http/pprof"
"github.com/v2fly/v2ray-core/v5/main/commands/base"
)
var pprofPlugin plugins.Plugin = func(cmd *base.Command) func() error {
2024-08-21 22:50:05 -04:00
addr := cmd.Flag.String("pprof", "", "")
return func() error {
if *addr != "" {
h := http.NewServeMux()
h.HandleFunc("/debug/pprof/", pprof.Index)
h.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
h.HandleFunc("/debug/pprof/profile", pprof.Profile)
h.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
h.HandleFunc("/debug/pprof/trace", pprof.Trace)
return (&http.Server{Addr: *addr, Handler: h}).ListenAndServe()
}
return nil
}
}
func init() {
plugins.RegisterPlugin(pprofPlugin)
2024-08-21 22:50:05 -04:00
}