Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

odeke-em
Copy link

This change adds $GOPATH/pkg/mod as a possible base to search
from given that Go modules have been the norm since Go1.11 and
we are currently at Go1.16/1.17, hence support for Go modules.

Fixes #611

@google-cla google-cla bot added the cla: yes label Mar 21, 2021
@odeke-em
Copy link
Author

Kindly /cc-ing @ghemawat @aalexand

@codecov-io
Copy link

codecov-io commented Mar 21, 2021

Codecov Report

Merging #612 (075f40d) into master (cbba55b) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #612      +/-   ##
==========================================
+ Coverage   66.94%   66.97%   +0.02%     
==========================================
  Files          78       78              
  Lines       14378    14388      +10     
==========================================
+ Hits         9626     9636      +10     
  Misses       3892     3892              
  Partials      860      860              
Impacted Files Coverage Δ
internal/report/source.go 78.43% <100.00%> (+0.23%) ⬆️
.../github.com/google/pprof/internal/report/source.go 78.43% <0.00%> (+0.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbba55b...075f40d. Read the comment docs.

@odeke-em odeke-em force-pushed the make-openSourceFile-cognizant-of-gomodules branch 2 times, most recently from d11e9de to d6a7932 Compare March 21, 2021 06:05
This change adds $GOPATH/pkg/mod as a possible base to search
from given that Go modules have been the norm since Go1.11 and
we are currently at Go1.16/1.17, hence support for Go modules.

Fixes google#611
@odeke-em odeke-em force-pushed the make-openSourceFile-cognizant-of-gomodules branch from d6a7932 to 075f40d Compare March 21, 2021 06:06
@aalexand
Copy link
Collaborator

@odeke-em Is it possible to add a test that fails before the the change and passes after?

@@ -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 != "" {
Copy link
Contributor

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"?

possibleBases = append(possibleBases,
filepath.Join(gopath, "pkg", "mod"),
filepath.Join(runtime.GOROOT(), "src"))
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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 go env -json GOMODCACHE GOROOT.

Using just os.Getenv("GOPATH") will not see if the user set up their own GOMODCACHE, nor will it work with env vars set with go env -w.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pprof fails to work with Go modules
5 participants