Documentation
¶
Overview ¶
Package heapdump parses the binary format written by runtime/debug.WriteHeapDump (see runtime/heapdump.go) into a normalized heapsnapshot.HeapSnapshot. The parser is intentionally independent of Delve and never tries to load the full heap dump into memory.
Index ¶
Constants ¶
const Header = "go1.7 heap dump"
Header is the heap dump file header emitted by runtime.WriteHeapDump. The trailing newline is part of the marker.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
func Parse(r io.Reader, opts Options) (*heapsnapshot.HeapSnapshot, error)
Parse reads a heap dump from r and returns the normalized snapshot.
The reader is consumed in stream order; the caller does not need to preload the entire dump.
Types ¶
type ContentResolver ¶
type ContentResolver struct {
// contains filtered or unexported fields
}
ContentResolver lazily fetches heap object content bytes from the original dump file. ParseLazyContents records (addr -> file offset, length) for every heap object record it sees; consumers (notably internal/heaplabels) Read bytes by virtual address and the resolver translates the lookup into an io.ReaderAt call on the underlying file.
A ContentResolver does not own the underlying io.ReaderAt. The caller must keep it open and valid for the resolver's lifetime.
func ParseLazyContents ¶
func ParseLazyContents(stream io.Reader, ra io.ReaderAt, opts Options) (*heapsnapshot.HeapSnapshot, *ContentResolver, error)
ParseLazyContents parses a heap dump from stream and returns a snapshot whose objects do not retain Contents bytes, together with a ContentResolver that can fetch any object's bytes on demand via ra.
stream is consumed sequentially during Parse; ra must reference the same byte sequence (typically: pass the same *os.File for both, since *os.File implements both interfaces and ReadAt is independent of the file's current read offset on every supported platform).
The returned resolver must not outlive ra. Callers that pass an *os.File must keep it open until the last call into the resolver.
opts.KeepObjectContents is forced to false; passing true is silently ignored because the entire point of ParseLazyContents is to avoid retaining content bytes in the Go heap.
func (*ContentResolver) Name ¶
func (c *ContentResolver) Name() string
Name identifies this source in diagnostic output. Matches the addrspace.NamedReader convention used elsewhere in the codebase.
func (*ContentResolver) ObjectCount ¶
func (c *ContentResolver) ObjectCount() int
ObjectCount reports the number of heap objects indexed by the resolver.
func (*ContentResolver) Read ¶
func (c *ContentResolver) Read(addr, size uint64) ([]byte, bool)
Read returns size bytes at virtual address addr. Reads spanning the payload of a single heap object are supported, including interior addresses (addr strictly greater than the containing object's base). Cross-object reads, addr==0 with size>0, and out-of-bounds requests return ok=false.
func (*ContentResolver) ReadAtAddr ¶
func (c *ContentResolver) ReadAtAddr(addr, size uint64) ([]byte, bool)
ReadAtAddr matches the addrspace.Reader signature so a ContentResolver can plug into the heaplabels composite reader chain.
type Limits ¶
Limits configures conservative safety bounds for length-prefixed fields. A zero value disables the corresponding limit.
type Options ¶
type Options struct {
// KeepObjectContents retains raw object bytes inside each Object.
// Off by default to avoid bringing back the old per-object memory
// problem. PointerAddrs is always populated regardless.
KeepObjectContents bool
// MaxStringBytes is an upper bound on length-prefixed strings such as
// function names and wait reasons. Zero uses the parser default.
MaxStringBytes uint64
// MaxMemRangeBytes is an upper bound on length-prefixed memory ranges
// (object contents, frame contents, data/bss). Zero means no limit.
MaxMemRangeBytes uint64
// Strict turns recoverable problems (unknown field kinds, out-of-bounds
// offsets) into errors instead of warnings.
Strict bool
}
Options controls Parse behavior.