pprof在通过http运行时无法定位源代码文件

7

我正在使用"net/http/pprof"在远程服务器上运行golang应用程序的远程分析。
我设置了PPROF_BINARY_PATH环境变量,以便go工具能够在我的计算机上找到本地二进制文件。
当我在go工具pprof cli中使用"list"关键字时,当go工具查找.go源文件时,会出现"没有这样的文件或目录"。

Error: open /go/src/github.com/foo/bar/baz.go: no such file or directory

看起来它正在远程机器的GOPATH中寻找源文件,而该路径为"/go/",而在我的个人机器上,它位于我的主目录中,因此该文件在"."中。

/Users/myuser/go/src/github.com/foo/bar/baz.go

当我将所需的源代码文件复制到我的GOPATH之外并放到go工具正在搜索的目录中时,“list”关键字按预期起作用,但这当然不是最佳选择。

你本地设置了 GOPATH 吗,还是使用默认值? - JimB
我正在使用默认设置,它被配置为$HOME/go/,而远程机器则只是/go。 - OhadBasan
@OhadBasan,您能否添加您在终端上运行的确切命令? - John S Perayil
2个回答

3
menghan@gram:/opt$ go tool pprof --help 2>&1 | grep source_path
    -source_path     Search path for source files

选项--source_path可能会有所帮助。


0

我在命令行中遇到了类似的问题,使用了 trim_path 的组合来删除绝对路径,因为它无法找到要注释的源。

go tool pprof -trim_path=/go/src/ -source_path=. -alloc_objects /tmp/ingest /tmp/heap.profile

(pprof) top3
Showing top 3 nodes out of 81
      flat  flat%   sum%        cum   cum%
  83976474 25.04% 25.04%   84461263 25.18%  github.com/<employer>/encoding/json.decoder.decodeString
  42240178 12.59% 37.63%   97645601 29.11%  github.com/<employer>/encoding/json.decoder.decodeInterface
  41605355 12.40% 50.03%  147466331 43.96%  github.com/<employer>/encoding/json.decoder.decodeMapStringInterface

list github.com/<employer>/encoding/json.decoder.decodeString

before: error: open /go/src/vendor/github.com/<rest of file path> 
after: (lists the code & allocs)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接