Golang分析器无法找到源代码。

huangapple go评论83阅读模式
英文:

Golang profiler cannot find source code

问题

我已经在我的代码中包含了net/http/pprof包。然后我可以轻松地运行pprof分析器(在Debian上):

go tool pprof http://localhost:9000/debug/pprof/profile

诸如top10或生成调用图等命令都能正常工作。然而,一旦我尝试进入一个函数,就会失败:

(pprof) list MyFunc
没有mypkg.MyFunc的源代码信息

我的GOPATH设置为我的项目目录。在构建源代码或运行pprof时,我需要特殊的标志或环境变量吗?

英文:

I've included the net/http/pprof package in my code. I can then comfortably run the pprof profiler (on Debian):

go tool pprof http://localhost:9000/debug/pprof/profile

Commands such as top10 or even generating call graphs work as expected. However, as soon as I try to go into a function, it fails:

(pprof) list MyFunc
No source information for mypkg.MyFunc

My GOPATH is set to my project's directory. Do I need any special flags or environment variables while building my source code or while running pprof?

答案1

得分: 17

通过golang-nuts的帮助找到了答案。我需要指定二进制文件:

go tool pprof mybinary http://localhost:9000/debug/pprof/profile

这样就可以找到源代码,并可以使用"list"命令列出。

英文:

Found the answer with the help of the golang-nuts people. I needed to specify the binary:

go tool pprof mybinary http://localhost:9000/debug/pprof/profile

This way the source code is found and can be listed with the "list" command.

答案2

得分: 0

我在Windows上遇到了与"net/http/pprof"相同的问题。不过,使用"runtime/pprof"代替,并使用pprof.StartCPUProfile / StopCPUProfile解决了这个问题。

英文:

I had the same problem with "net/http/pprof", albeit on windows.
Using "runtime/pprof" instead, with pprof.StartCPUProfile / StopCPUProfile solved it.

huangapple
  • 本文由 发表于 2015年5月4日 02:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/30017522.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定