/** * SMI-689: MemoryProfiler - Memory profiling for benchmark infrastructure * * Features: * - Track memory usage for labeled operations * - Detect memory leaks over threshold * - Get heap snapshots using V8 statistics * - Generate human-readable memory reports * - Baseline comparison for memory regression detection */ import type { MemorySnapshot, MemoryStats, MemoryBaseline, LeakDetectionResult, MemoryRegressionResult } from './types.js'; export type { MemorySnapshot, MemoryStats, MemoryBaseline, LeakDetectionResult, MemoryRegressionResult, } from './types.js'; /** * MemoryProfiler provides comprehensive memory tracking and leak detection * for the benchmark infrastructure. * * @example * ```typescript * const profiler = new MemoryProfiler(); * * profiler.trackMemory('heavy_operation'); * await heavyOperation(); * const stats = profiler.stopTracking('heavy_operation'); * * console.log(`Heap grew by ${stats.heapGrowthPercent}%`); * * // Check for leaks * const leakResult = profiler.detectLeaks(10); * if (leakResult.hasLeaks) { * console.error(leakResult.message); * } * ``` */ export declare class MemoryProfiler { private activeTracking; private completedStats; private baselineManager; private samplingIntervalMs; /** * Create a new MemoryProfiler instance * * @param samplingIntervalMs - Interval in ms for collecting memory samples (default: 100ms) */ constructor(samplingIntervalMs?: number); /** * Start tracking memory for a labeled operation * * @param label - Unique label to identify this tracking session * @throws Error if label is already being tracked * * @example * ```typescript * profiler.trackMemory('database_query'); * ``` */ trackMemory(label: string): void; /** * Stop tracking memory for a labeled operation and return statistics * * @param label - Label of the tracking session to stop * @returns Memory statistics for the tracked operation * @throws Error if label is not being tracked * * @example * ```typescript * const stats = profiler.stopTracking('database_query'); * console.log(`Heap growth: ${stats.heapGrowthPercent}%`); * ``` */ stopTracking(label: string): MemoryStats; /** * Get current heap statistics using V8 * * @returns Current memory snapshot * * @example * ```typescript * const snapshot = profiler.getHeapSnapshot(); * console.log(`Used heap: ${snapshot.usedHeapSize / 1024 / 1024} MB`); * ``` */ getHeapSnapshot(): MemorySnapshot; /** * Detect potential memory leaks across all completed tracking sessions * * @param threshold - Heap growth percentage threshold to consider a leak (default: 10%) * @returns Leak detection result * * @example * ```typescript * const result = profiler.detectLeaks(15); // 15% threshold * if (result.hasLeaks) { * console.error(`Potential leak detected: ${result.message}`); * } * ``` */ detectLeaks(threshold?: number): LeakDetectionResult; /** * Save a baseline for memory regression comparison * * @param label - Label to save as baseline * @throws Error if no completed stats exist for the label */ saveBaseline(label: string): MemoryBaseline; /** * Load baselines from a JSON object * * @param baselines - Object mapping labels to baselines */ loadBaselines(baselines: Record): void; /** * Check for memory regression against baseline * * @param label - Label to check * @param threshold - Regression threshold percentage (default: 10%) * @returns Regression result */ checkRegression(label: string, threshold?: number): MemoryRegressionResult; /** * Generate a human-readable memory report * * @returns Formatted memory report string * * @example * ```typescript * profiler.trackMemory('op1'); * await operation1(); * profiler.stopTracking('op1'); * * console.log(profiler.formatMemoryReport()); * ``` */ formatMemoryReport(): string; /** * Get all completed statistics * * @returns Map of label to MemoryStats */ getCompletedStats(): Map; /** * Get all baselines * * @returns Map of label to MemoryBaseline */ getBaselines(): Map; /** * Export baselines as JSON-serializable object * * @returns Object mapping labels to baselines */ exportBaselines(): Record; /** * Clear all tracking data */ clear(): void; /** * Clear baselines */ clearBaselines(): void; } /** * Default memory profiler instance for convenience */ export declare const defaultMemoryProfiler: MemoryProfiler; //# sourceMappingURL=MemoryProfiler.d.ts.map