pprof cannot locate source code for the list command in common Go setups
- Dominant language
- Go
- Stars
- 9.3k
- Forks
- 671
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 10
Description
The current heuristic for locating the source code for profile functions doesn't work in the following cases when running pprof with default options:
- It cannot find source code for standard Go packages. Users need to specify -source_path=`go env GOROOT` as a workaround.
- It cannot find source code for external modules. Users need to specify -source_path=`go env GOMODCACHE` as a workaround. But this workaround stops working if external module names contain uppercase chars. For example, github.com/FooBar/Baz, because Go stores sources for such module names into $GOMODCACHE/github.com/!foo!bar/!baz directory according to https://go.dev/ref/mod#module-cache, while pprof is unaware of such a conversion.
- It cannot find source code at the vendor directory. Users need to specify -source_path=`pwd`/vendor as a workaround. But this workaround doesn't work for vendored modules, since their names contain module version in the form module_name@version, while the source code for the module_name is stored inside vendor/module_name directory.
- It cannot find source code for profiles obtained from Go executables built with -trimpath command-line flag, if their sources are put in the directory with the name other than the module name.
This significantly reduces pprof usability, since it is very hard to inspect sources with list command. Users have to create horrible hacks with -source_path and -trim_path command-line flags such as VictoriaMetrics/VictoriaLogs#893, but these hacks do not cover properly all the cases mentioned above.
It would be great if pprof could properly detect source code in all the cases mentioned above with default settings, without the need to specify -trim_path and -source_path command-line flags.
Contributor guide
Research direction
Start with the pprof list command and its default source lookup, then reproduce the standard-library, external-module, vendor, uppercase-module, and -trimpath cases described here. Done means list locates source without -source_path or -trim_path, including Go's module-cache encoding and vendored module versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100