企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ package main import ( "fmt" "net/http" "net/http/pprof" ) func main() { Init([]string{"localhost: 1234"}) // http访问 ip+端口 ch := make(chan int, 10) <-ch } // StartPprof start http pprof. func Init(pprofBind []string) { pprofServeMux := http.NewServeMux() /* func Index(w http.ResponseWriter, r *http.Request) Index回复请求要求的pprof格式的剖面。例如,"/debug/pprof/heap"会回复"heap"剖面。Index会回复"/debug/pprof/" 请求一个列出所有可用的剖面的HTML页面。 */ pprofServeMux.HandleFunc("/debug/pprof/", pprof.Index) /* func Cmdline(w http.ResponseWriter, r *http.Request) Cmdline回应执行中程序的命令行,采用NUL字节分隔的参数。本包将它注册在/debug/pprof/cmdline。 */ pprofServeMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) /* func Profile(w http.ResponseWriter, r *http.Request) Profile回复pprof格式的CPU剖面。本包将它注册在/debug/pprof/profile。 */ pprofServeMux.HandleFunc("/debug/pprof/profile", pprof.Profile) /* func Symbol(w http.ResponseWriter, r *http.Request) Symbol查看请求中列出的程序计数器,回复一个映射程序计数器到函数名的表格。本包将它注册在/debug/pprof/symbol。 */ pprofServeMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) for _, addr := range pprofBind { go func() { if err := http.ListenAndServe(addr, pprofServeMux); err != nil { fmt.Printf("http.ListenAndServe(\"%s\", pprofServeMux) error(%v)", addr, err) panic(err) } }() } } ~~~