drecy22400 2012-12-04 01:06 采纳率: 0%
浏览 114
已采纳

如何在Go程序中使用pprof

How to use pprof in Go program?

There is a Go package named net/http/pprof,but I can't use it.

The document says go tool pprof http://localhost:6060/debug/pprof/heap ,which does not work.

And,what does the below _ mean?

import _ "net/http/pprof"

  • 写回答

2条回答 默认 最新

  • donglin4636 2012-12-10 23:52
    关注

    Based on your comment, the issue might be that you're not using the correct port number.

    If you are running an http server at http://localhost:9997, then I think you want to run the command with http://localhost:9997:

    $ go tool pprof http://localhost:9997/debug/pprof/heap
    

    According to the net/http/pprof pkg doc page, if your application is already running an http server you do not need to start one and only need to include the import _ "net/http/pprof" somewhere in your program. http://localhost:6060 is the server started as an example and the host and port are arbitrary.

    import _ "net/http/pprof" means the package is imported but you do not use any of its exported identifiers. According to the go language spec, this will import the package solely for its side effects. These side effects involve, I think, the execution of the init() functions defined in the package's source files and, apparently, registered variables.

    Also, you might find this blog post helpful:

    http://blog.golang.org/2011/06/profiling-go-programs.html

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部