英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论