duangang4940 2015-05-31 18:09
浏览 200
已采纳

无法在现有服务器上使用Go工具pprof

I have an existing http server which I would like to profile. I have included _ "net/http/pprof"to my imports, and I already have http server running:

router := createRouter()
server := &http.Server {
    Addr:           ":8080",
    Handler:        router,
    ReadTimeout:    15*time.Second,
    WriteTimeout:   15*time.Second,
//  MaxHeaderBytes: 4096,
}

log.Fatal(server.ListenAndServe())

When I'm trying to access http://localhost:8080/debug/pprof/ I get 404 page not found.

That's what I get when using go tool pprof on a local machine:

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

Same for a remote client:

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
  • 写回答

3条回答 默认 最新

  • doujuan9698 2015-05-31 18:47
    关注

    It's not explicitly mentioned in the documentation, but net/http/pprof only registers its handlers with http.DefaultServeMux.

    From the source:

    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))
    }
    

    If you're not using the default mux you just have to register any/all of those you want with whatever mux you're using, e.g. something like mymux.HandleFunc("…", pprof.Index), etc.

    Alternatively you can listen on a separate port (also possibly bound to only localhost if desired) with the default mux as you've shown.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line