-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/report: make openSourceFile cognizant of Go modules #612
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"os" | ||
"path/filepath" | ||
"regexp" | ||
"runtime" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
|
@@ -917,8 +918,19 @@ func openSourceFile(path, searchPath, trim string) (*os.File, error) { | |
f, err := os.Open(path) | ||
return f, err | ||
} | ||
possibleBases := filepath.SplitList(searchPath) | ||
if gopath := os.Getenv("GOPATH"); gopath != "" { | ||
// We can also look through: | ||
// * $GOPATH/pkg/mod | ||
// * runtime.GOROOT()/src | ||
// in case the file originates from Go modules. | ||
// See https://github.com/google/pprof/issues/611. | ||
possibleBases = append(possibleBases, | ||
filepath.Join(gopath, "pkg", "mod"), | ||
filepath.Join(runtime.GOROOT(), "src")) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps nitpicking slightly, but this is not entirely correct; the only way to reliably find these out would be to run Using just |
||
// Scan each component of the path. | ||
for _, dir := range filepath.SplitList(searchPath) { | ||
for _, dir := range possibleBases { | ||
// Search up for every parent of each possible path. | ||
for { | ||
filename := filepath.Join(dir, path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative would be to somehow make sure that the SourcePath field in options is set correctly earlier?
And if it is the case that all/most Go users are using "go tool pprof" then perhaps we can just arrange for the Go invocation code to pass the right source path settings? Or are you worried about "pprof" invocations that are not via "go tool pprof"?