-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
We propose to extend runtime/pprof API to allow users to choose whether to
include symbol info in the profile output.
Background
Since Go1.9, profile outputs include symbol information
(https://golang.org/doc/go1.9#go-tool-pprof) so they can be interpreted
without the binary. Symbolization is done by the profiled binary and we
observed in some cases, such symbolization work in the profiled target
binary is not desirable.
For example,
- we may want to avoid adding extra load to a busy server when
debugging CPU overload issue. - symbol information may be available in different sources (binary, external
symbolization service, etc) and users may favor to use them instead. - currently runtime delegates symbolization of non-Go symbols to cgoSymbolizer and its efficiency
is sometimes not easy to control.
The pprof tool still supports retrieving symbol information from external sources
when it finds the fetched profile lacks symbol information.
API changes
runtime/pprof: In the scope of this proposal we care only about controlling
symbolization, but one can imagine that we may want to support more customization
in profiling (for example, filtering, choosing different output formats, debug levels,
changing CPU profiling rate, etc). In order to support the future extension easily, we
propose to add profile parameter types.
Then, StartCPUProfile and Profile.WriteTo are variations that take those new parameter
types.
package pprof
// CPUProfileParam is a set of parameters to configure CPU profiling.
type CPUProfileParam struct {
ProfileParam
// Place for future CPU profile-specific parameters
}
// ProfileParam is a set of parameters to configure profile output generation.
type ProfileParam struct {
NoSymbol bool
}
// StartCPUProfileWithParam is like StartCPUProfile but it allow to configure
// profiling and its output generation.
func StartCPUProfileWithParam(w io.Writer, param CPUProfileParam) error
// WriteToWithParam is like WriteTo, but it allows to configure profile output generation.
func (* Profile) WriteToWithParam(w io.Writer, param ProfileParam) error
net/http/pprof:
Profile handlers can take a new 'nosymbol' form value. If it is set to non-zero integer
value, profile output will not include symbol information.
There will be no change affecting existing API users.
Implementation
Implementation is trivial - we skip symbolization that had been done while formatting
the output. The pprof tool can perform symbolization correctly as long as the Location
entries of the output proto contain correct Address and Mapping information.
One caveat is that currently expansion of inlined frames are also handled by
runtime.CallersFrames used for symbolization. There is no way to perform expansion
without symbolization. Once the correct DWARF debug information for inlined frames
work (in progress targetting for 1.10) is done, the DWARF reader can expand them
using the PCs.