我有一个现有的 http 服务器,我想对其进行分析。我已经包括了_ "net/http/pprof"
到我的导入,并且我已经运行了 http 服务器:
router := createRouter()
server := &http.Server {
Addr: ":8080",
Handler: router,
ReadTimeout: 15*time.Second,
WriteTimeout: 15*time.Second,
// MaxHeaderBytes: 4096,
}
log.Fatal(server.ListenAndServe())
当我尝试访问时http://localhost:8080/debug/pprof/ http://localhost:8080/debug/pprof/ I get 404 page not found
.
这就是我使用时得到的go tool pprof
在本地机器上:
userver@userver:~/Desktop/gotest$ go tool pprof http://192.168.0.27:8080/
Use of uninitialized value $prefix in concatenation (.) or string at /usr/lib/go/pkg/tool/linux_amd64/pprof line 3019.
Read http://192.168.0.27:8080/pprof/symbol
Failed to get the number of symbols from http://192.168.0.27:8080/pprof/symbol
userver@userver:~/Desktop/gotest$ go tool pprof http://localhost:8080/debug/pprof/profile
Read http://localhost:8080/debug/pprof/symbol
Failed to get the number of symbols from http://localhost:8080/debug/pprof/symbol
对于远程客户端也是如此:
MacBookAir:~ apple$ go tool pprof http://192.168.0.27:8080/
Use of uninitialized value $prefix in concatenation (.) or string at /usr/local/Cellar/go/1.3.2/libexec/pkg/tool/darwin_amd64/pprof line 3027.
Read http://192.168.0.27:8080/pprof/symbol
Failed to get the number of symbols from http://192.168.0.27:8080/pprof/symbol
文档中没有明确提及,但是net/http/pprof https://golang.org/pkg/net/http/pprof仅注册其处理程序http.DefaultServeMux
.
来自source https://github.com/golang/go/blob/release-branch.go1.9/src/net/http/pprof/pprof.go#L72-L76:
func init() {
http.Handle("/debug/pprof/", http.HandlerFunc(Index))
http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline))
http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile))
http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol))
http.Handle("/debug/pprof/trace", http.HandlerFunc(Trace))
}
如果您不使用默认的多路复用器,您只需使用您正在使用的任何多路复用器注册任何/所有您想要的多路复用器,例如就像是mymux.HandleFunc("…", pprof.Index)
, etc.
或者,您可以使用默认多路复用器监听单独的端口(如果需要,也可能仅绑定到本地主机)你已经展示了 https://stackoverflow.com/a/30560860/55504.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)