capture

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package capture writes the calling process's heap dump to a temp file and returns it positioned at offset 0. It is used by dev tools and tests that need a live heap dump without the snapshot-tar bundle format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureOptions

type CaptureOptions struct {
	// GCBeforeHeapDump runs runtime.GC() before WriteHeapDump.
	GCBeforeHeapDump bool

	// HeapDumpWriter writes the heap dump. Defaults to
	// RuntimeHeapDumpWriter when nil.
	HeapDumpWriter HeapDumpWriter

	// GC is the GC trigger. Defaults to runtime.GC when nil.
	GC func()
}

CaptureOptions configures Capture. The zero value is useful: it selects RuntimeHeapDumpWriter and skips the GC.

type Captured

type Captured struct {
	HeapDump     *os.File
	HeapDumpSize int64
	// contains filtered or unexported fields
}

Captured holds a heap dump open as a seeked-to-zero temp file. Call Cleanup when done.

func Capture

func Capture(ctx context.Context, opts CaptureOptions) (*Captured, error)

Capture writes a heap dump to a temp file and returns it positioned at offset 0. The caller must invoke Cleanup when done.

func (*Captured) Cleanup

func (c *Captured) Cleanup()

Cleanup closes the heap dump file and removes the backing temp dir. Safe to call more than once.

type HeapDumpWriter

type HeapDumpWriter interface {
	WriteHeapDump(fd uintptr) error
}

HeapDumpWriter writes the calling process heap dump to the file identified by fd.

type RuntimeHeapDumpWriter

type RuntimeHeapDumpWriter struct{}

RuntimeHeapDumpWriter is the production HeapDumpWriter: it calls debug.WriteHeapDump with the supplied file descriptor.

func (RuntimeHeapDumpWriter) WriteHeapDump

func (RuntimeHeapDumpWriter) WriteHeapDump(fd uintptr) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL