profile: fix legacy format Go heap profile parsing (#382)
This CL fixes a long-lasting bug that prevented pprof from recognizing
Legacy heap profile produced by Go. Go reports four types of samples
at once so the profile includes alloc_objects, alloc_space,
inuse_objects, and inuse_space. The bug caused pprof to misclassify Go
heap profile data and prevent selection of correct filtering/pruning
patterns in analysis.
Update golang/go#25096
Tested with the profile samples included in golang.org/issues/25096
(pprof hides the runtime functions with this change)
Add GetBase support for ASLR kernel mappings (#371)
Add GetBase support for kernel mappings as reported by Linux Perf
Linux Perf reports kernel mappings with an offset == start.
Currently GetBase() cannot handle such a case.
This behavior can be seen from a perf.report data with samples in the kernel:
$ sudo perf report -D perf.data | grep MMAP
0 0x108 [0x50]: PERF_RECORD_MMAP -1/0: [0xffffffffaf800000(0x1087a000) @ 0xffffffffaf800000]: x [kernel.kallsyms]_text
internal/driver: skip tests requiring tcp on js (#373)
This commit upstreams the changes made in golang.org/cl/110096. As the
change says, it is acceptable for the new js/wasm target to only support
what nacl supports right now.
Add "trim path" option which can be used to relocate sources. (#366)
Add "trim path" option which can be used to relocate sources.
When pprof is asked to show annotated source for a profile collected on
another machine for a Go program, the profile contains absolute paths
which may not exist on the local machine. In that case pprof currently
fails to locate the source with no option to help it. The new option
adds a way to specify one or several source path prefixes that should be
trimmed from the source paths in the profile before applying the search
using search path option.
For example, taking the example from the issue where the source file
path in the profile is
/home/teamcitycpp/agent09/work/56cbaf9067/_gopath/src/badoo/lakafka/main.go
and the local path is /home/marko/lakafka/main.go. The user may
specify
`-trim-path=/home/teamcitycpp/agent09/work/56cbaf9067/_gopath/src/badoo`
to make pprof find the source. The source path doesn't need to be
specified if the current working dir is anything at or under
`/home/marko/`.
When the trim path is not specified, it is guessed heuristically based
on the basename of configured searched paths. In the example above,
setting `-search-path=/home/marko/lakafka` would be sufficient to
activate the heuristic successfully. Or having the current directory as
`/home/marko/lakafka` since the search path is by default set to the
current working directory. Note that the heuristic currently
does not attempt to walk the configured search paths up like the search
does. This is to keep it simple, use `-trim-path` explicitly in more
complicated cases.
Fixes #262.
Add command-line editing support for interactive pprof (#362)
Add command-line editing support for interactive pprof
This implements basic command-line editing, using
github.com/chzyer/readline. This will not affect the golang
distribution as it uses its own pprof driver, with its own
driver.
Only tested on Linux.
TODO: Implement auto-completion and persistent history.
Update -help to list correct paths searched within PPROF_BINARY_PATH. (#355)
The code was updated in #335 but the doc wasn't updated. Also the doc
didn't include $path which is searched as well, see locateBinaries in
internal/driver/fetch.go.
Switch to use goroutine profile in TestHttpsInsecure. (#350)
Trying to test against /debug/pprof/profile has been giving some flakes
and trouble so far (#146, #253, #328, golang/go#24611, golang/go#22594). While
some of the discussions the failures triggered appear to be useful (such
as whether CPU profiles are expected to be working on Windows XP or
not), that kind of testing is not really in the scope for this
particular test. This change switches the test to use goroutine profile
instead which is hopefully much less dependent on the environment. The
change also makes the test much faster to run.
Previously, the web UI was hard-coded to be served at `/` but
applications which are *embedding* the ui are unlikely to host it there.
This change makes the links between the various ui pages relative,
addressing this problem.
To make sure this doesn't rot, the internal http server now serves the
ui at /ui/ (redirecting there from the root).
I think we can all agree that the ui code and JavaScript is kind of a
haphazard affair. I performed a great deal of clicking around to make
sure the semantics didn't change and interestingly spent some time
trying to fix semantics I later realized weren't actually there: I
thought that when navigating to another page from a focused search (say
`flamegraph?f=x`) the focus would be carried over. This doesn't seem to
be the case, however.
The point being, there's no test coverage and setting it up is way
beyond what I can do here. I'm happy to manually verify whatever
sequence of clicks is suggested, though.
Touches https://github.com/cockroachdb/cockroach/pull/24145.
This fixes a bug introduced in #341 which caused the browser
opening code to be disabled for the standard `pprof -http`
invocation.
Introduce a proper getter on the UI which determines whether
the browser ought to be opened.
* Avoid opening browser when not in terminal
This also reverts e82ee9a, though only in spirit since the revert
did not apply cleanly.
This change may look cosmetic, but note that `plugin.UI` can be
passed in from the outside. This is important for embedding pprof
into an application for easy access to the web ui: with this change,
such an application can pass a non-Terminal `profile.UI` and avoids
the browser code.
* Allow passing in a custom HTTPServer
This allows embedding the pprof ui into an existing application.
See https://github.com/cockroachdb/cockroach/pull/24145 for an example.
* Add tests for source file searching.
* Fix slash handling in tests on Windows.
* Fix test cleanup, it was leaving stale files.
* Fix number of args in Fatalf call
internal/driver: suggest sample_index in case empty default samples (#336)
In the interactive mode, inform users of different sample types
if the profile includes zero samples for selected sample type
by default (or through user-provided sample_index flag value).
The example output may look like
$ pprof mem.prof
Type: inuse_space
Time: Mar 20, 2018 at 11:36am (EDT)
No samples were found with the default sample value type.
Try "sample_index" command to analyze different sample values.
Entering interactive mode (type "help" for commands, "o" for options)
(pprof)
Update golang/go#24443
Update perf_to_profile cli arguments to use flags. (#277) (#332)
Update perf_to_profile cli arguments to use flags. (#277)
Fixes #277
As perf_to_profile uses flags to parse its arguments, modify the call to perf_to_profile to use flags. Also pass the '-f' flag to overwrite the existing output profile file.
Redirect perf_to_profile's stdout/stderr to pprof's stdout/stderr.
Set base address on OSX.
This fixes issue #311. The mapped address of libraries was never considered, nor was the load address of the segments. It also fixes a couple of issues in binutils.go, such as when the tail of the data wasn't handled right when grouping symbols at the same address.
Pass text segment info to GetBase to handle Linux kernel ASLR case. (#299)
When pprof symbolizes kernel addresses in vmlinux binary for a profile
converted using https://github.com/google/perf_data_converter, the
addresses need to be adjusted if kernel ASLR is in effect. So far the
call to GetBase did not pass text segment info to GetBase which
shortcircuited the code to merely return zero adjustment. This change
fixes the call to GetBase to address that.
The added test case is a simulation of what happens with vmlinux, but it
should be pretty close. Including a vmlinux file into the test data does
not appear practical due to the binary size. I verified that the test
failed before the fix and passes after.
Note that the fixed issue is specific to the kernel ASLR as user-mode
ASRL-enabled binaries (i.e. built with -pie / -fpie) have ET_DYN type
which takes a different code path in GetBase which did not have issues
before this fix in practice.
internal/driver: fix new unkeyed composite lit vet warnings (#298)
The current version of go vet does not flag these as noted in
golang/go#23539. A fix is in the works, and will likely be included in
Go 1.11. Make the updated vet tool happy, so that the vendored copy of
pprof in the Go tree can be updated and make the vet trybot happy.
Fixes #297.