mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-07 18:07:23 -05:00
30 lines
751 B
Go
30 lines
751 B
Go
package plugin_pprof
|
|
|
|
import (
|
|
"github.com/v2fly/v2ray-core/v5/main/plugins"
|
|
"net/http"
|
|
"net/http/pprof"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/main/commands/base"
|
|
)
|
|
|
|
var pprofPlugin plugins.Plugin = func(cmd *base.Command) func() error {
|
|
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)
|
|
}
|