drecy22400 2012-12-04 09: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-11 07: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条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了