我有一个现有的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/时,我收到了404页面未找到
的错误信息。在本地机器上使用
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
/debug/pprof/
,就会有几个链接导致404页面。特别是heap
和allocs
404。正如你上面展示的那样,我没有看到这些路径的路由在net/http/pprof/pprof.go
的init()
函数中提供。我该如何使它们可访问?您是否知道我如何联系@Dave C以获取这些信息? - Andrew Brouter.PathPrefix("/debug/").Handler(http.DefaultServeMux)
,则会添加堆端点。如果应用init
处理程序,则不会添加。不确定为什么... - andig