golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.36k stars 17.71k forks source link

cmd/pprof: use $GOPATH for source file lookup #23376

Open phemmer opened 6 years ago

phemmer commented 6 years ago

What version of Go are you using (go version)?

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/Users/phemmer/.go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/phemmer/.go:/tmp/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xk/jhvsfjg14zqfgtwvm0kpsy61p_63g5/T/go-build517300090=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

Attempted to profile a heap dump from a binary built on another host and use list foo

What did you expect to see?

The source code with corresponding data for each line.

What did you see instead?

(pprof) list unmarshalBinary
Total: 1.95GB
ROUTINE ======================== github.com/influxdata/kapacitor/vendor/github.com/influxdata/influxdb/models.(*point).unmarshalBinary in /root/go/src/github.com/influxdata/kapacitor/vendor/github.com/influxdata/influxdb/models/points.go
    1.49GB     1.49GB (flat, cum) 76.51% of Total
 Error: open /root/go/src/github.com/influxdata/kapacitor/vendor/github.com/influxdata/influxdb/models/points.go: no such file or directory

On my local system, this source code can instead be found in /Users/phemmer/.go/....

Ref #13231 which is related, but I can't use $GOROOT, as I don't have a full go toolkit in my home directory, only application source.

ianlancetaylor commented 6 years ago

CC @matloob @rauls5382

constant-null commented 6 years ago

Have similar issue, i have binaries built by CI where $GOPATH set to /go. When we get profile file from remote host and try to use it locally with different GOPATH set, the described error occurs.

It is possible to create simlink ($GOPATH -> /go), to trick pprof so it start working correctly, but it is requiring root privileges and not very convenient.

ardan-bkennedy commented 6 years ago

I just ran into this issue today in class :(. Is there any other solution?

rauls5382 commented 6 years ago

FWIW this was fixed in upstream pprof by using heuristics to automatically trim the paths in the profiles, and adding a new trim_path option for when the heuristics fail.

https://github.com/google/pprof/pull/366

ardan-bkennedy commented 6 years ago

Brilliant and Thank You!

marwan-at-work commented 6 years ago

im currently on the same machine, not on a different one. And I can't run -web. This is what I get when I run pprof -web cpu.prof

FATAL[0000] couldn't read file: /Users/xxx/go/src/github.com/marwan-at-work/xxx/var/folders/n4/35bgdnkd6vlgqrdzbyl0x1ycmhcndx/T/pprof002.svg error=open /Users/xxx/go/src/github.com/marwan-at-work/xxx/var/folders/n4/35bgdnkd6vlgqrdzbyl0x1ycmhcndx/T/pprof002.svg: no such file or directory
pprof: exit status 1

Same thing when I do -weblist <arg> from inside the pprof cli.

phemmer commented 6 years ago

@marwan-at-work Please open a different issue. That's not what this one is about.