Documentation
¶
Overview ¶
Package memlab provides heap snapshot capture via Chrome DevTools Protocol and analysis via @memlab/heap-analysis for memory leak detection in e2e tests.
Index ¶
- func AssertDeltas(t testing.TB, result *AnalysisResult, thresholds Thresholds)
- func BuildSnapshotArg(snapshots *SnapshotSet) (string, error)
- func CaptureHeapSnapshot(ctx playwright.BrowserContext, page playwright.Page, outPath string) (string, error)
- func EnsureDeps() error
- func SortPairDeltas(pairDeltas []RetainedRpcDelta)
- type AnalysisResult
- type ObjectCounts
- type RetainedRpcDelta
- type RetainedRpcEntry
- type SnapshotAnalysis
- type SnapshotSet
- type Thresholds
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertDeltas ¶
func AssertDeltas(t testing.TB, result *AnalysisResult, thresholds Thresholds)
AssertDeltas fails the test if any delta exceeds its threshold.
func BuildSnapshotArg ¶
func BuildSnapshotArg(snapshots *SnapshotSet) (string, error)
BuildSnapshotArg builds the ordered label=path argument for analyze.js.
func CaptureHeapSnapshot ¶
func CaptureHeapSnapshot(ctx playwright.BrowserContext, page playwright.Page, outPath string) (string, error)
CaptureHeapSnapshot captures a Chrome V8 heap snapshot via CDP HeapProfiler on the given Playwright page. It forces GC first, then triggers a heap snapshot, collects all chunks, and writes them to outPath. Returns the written file path.
func EnsureDeps ¶
func EnsureDeps() error
EnsureDeps runs bun install in the memlab dir if node_modules is missing. Returns an error if installation fails.
func SortPairDeltas ¶
func SortPairDeltas(pairDeltas []RetainedRpcDelta)
SortPairDeltas sorts pair deltas by descending delta, then final count, then name.
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
Snapshots []SnapshotAnalysis `json:"snapshots"`
Deltas ObjectCounts `json:"deltas"`
TopRetained []RetainedRpcEntry `json:"topRetained"`
PairDeltas []RetainedRpcDelta `json:"pairDeltas"`
}
AnalysisResult is the JSON output from analyze.js.
func RunAnalysis ¶
func RunAnalysis(snapshots *SnapshotSet) (*AnalysisResult, error)
RunAnalysis invokes analyze.js with the given snapshot set and returns the parsed result.
type ObjectCounts ¶
type ObjectCounts struct {
ClientRpc int `json:"clientRpc"`
ChannelStream int `json:"channelStream"`
Promise int `json:"promise"`
Generator int `json:"generator"`
OnNext int `json:"onNext"`
}
ObjectCounts holds counts of leak-target objects.
type RetainedRpcDelta ¶
type RetainedRpcDelta struct {
Service string `json:"service"`
Method string `json:"method"`
BaselineCount int `json:"baselineCount"`
FinalCount int `json:"finalCount"`
Delta int `json:"delta"`
}
RetainedRpcDelta is a per-pair retained count delta between first and last snapshots.
type RetainedRpcEntry ¶
type RetainedRpcEntry struct {
Service string `json:"service"`
Method string `json:"method"`
Count int `json:"count"`
}
RetainedRpcEntry is a service/method pair with count.
type SnapshotAnalysis ¶
type SnapshotAnalysis struct {
Label string `json:"label"`
Path string `json:"path"`
Counts ObjectCounts `json:"counts"`
TopRetained []RetainedRpcEntry `json:"topRetained"`
}
SnapshotAnalysis is per-snapshot analysis output.
type SnapshotSet ¶
type SnapshotSet struct {
// Dir is the directory containing the snapshots.
Dir string
// Labels tracks snapshot labels in insertion order.
Labels []string
// Snapshots maps label to file path.
Snapshots map[string]string
}
SnapshotSet holds paths to a set of labeled heap snapshots.
func NewSnapshotSet ¶
func NewSnapshotSet(dir string) *SnapshotSet
NewSnapshotSet creates a new SnapshotSet writing to dir.
func (*SnapshotSet) CaptureSnapshot ¶
func (s *SnapshotSet) CaptureSnapshot(ctx playwright.BrowserContext, page playwright.Page, label string) error
CaptureSnapshot captures a single labeled snapshot into the set.
func (*SnapshotSet) Path ¶
func (s *SnapshotSet) Path(label string) string
Path returns the snapshot file path for a label.
func (*SnapshotSet) SnapshotLabels ¶
func (s *SnapshotSet) SnapshotLabels() []string
SnapshotLabels returns the snapshot labels in insertion order. Use the Snapshots map for path lookup.
type Thresholds ¶
Thresholds defines per-type delta thresholds for leak assertions.
func DefaultThresholds ¶
func DefaultThresholds() Thresholds
DefaultThresholds returns conservative initial thresholds. Calibrate after first successful run.