/** * Memory Profiler - Detailed memory leak detection for MicroPDF * * Provides comprehensive memory profiling capabilities: * - Handle allocation tracking with stack traces * - Leak detection for unreleased handles * - Memory usage statistics by type * - WeakRef-based leak detection * * @example * ```typescript * import { enableProfiling, getLeakReport } from 'micropdf/profiler'; * * enableProfiling(true); * // ... use MicroPDF ... * const report = getLeakReport(60000); // Leaks older than 60s * console.log(report.toString()); * ``` */ /** Resource types being tracked */ export declare enum ResourceType { Context = 0, Buffer = 1, Stream = 2, Pixmap = 3, Document = 4, Page = 5, Font = 6, Image = 7, Path = 8, Text = 9, Device = 10, DisplayList = 11, Colorspace = 12, PdfObject = 13, Outline = 14, Link = 15, Annotation = 16, StextPage = 17, Cookie = 18, Archive = 19, Other = 255 } export declare function getResourceTypeName(type: ResourceType): string; /** Record of a single allocation */ export interface AllocationRecord { handle: number; resourceType: ResourceType; sizeBytes: number; allocatedAt: Date; stackTrace?: string; tag?: string; } /** Statistics for a specific resource type */ export interface TypeStats { currentCount: number; currentBytes: number; totalAllocated: number; totalDeallocated: number; totalBytesAllocated: number; totalBytesDeallocated: number; peakCount: number; peakBytes: number; } /** Global statistics snapshot */ export interface GlobalStats { totalHandlesCreated: number; totalHandlesDestroyed: number; currentHandles: number; currentBytes: number; peakHandles: number; peakBytes: number; uptimeMs: number; } /** Leak detection report */ export interface LeakReport { generatedAt: Date; minAgeThresholdMs: number; totalPotentialLeaks: number; leaksByType: Map; globalStats: GlobalStats; } /** * Memory profiler for tracking handle allocations and detecting leaks */ export declare class MemoryProfiler { private enabled; private captureStackTraces; private allocations; private statsByType; private startTime; private totalCreated; private totalDestroyed; private currentHandles; private currentBytes; private peakHandles; private peakBytes; private readonly _registry?; constructor(); /** Enable or disable profiling */ setEnabled(enabled: boolean): void; /** Enable or disable stack trace capture */ setStackTraceCapture(enabled: boolean): void; /** Check if profiling is enabled */ isEnabled(): boolean; /** Record a new allocation */ recordAllocation(handle: number, resourceType: ResourceType, sizeBytes: number, tag?: string): void; /** Record a deallocation */ recordDeallocation(handle: number): AllocationRecord | undefined; /** Register an object for GC tracking */ registerForGCTracking(target: object, handle: number, resourceType: ResourceType): void; /** Get all currently live allocations */ getLiveAllocations(): AllocationRecord[]; /** Get allocations older than minAgeMs (potential leaks) */ getPotentialLeaks(minAgeMs: number): AllocationRecord[]; /** Get statistics by resource type */ getStatsByType(): Map; /** Get global statistics */ getGlobalStats(): GlobalStats; /** Reset all profiling data */ reset(): void; /** Generate a leak report */ generateLeakReport(minAgeMs: number): LeakReport; } /** Get the global memory profiler instance */ export declare function getProfiler(): MemoryProfiler; /** Enable or disable memory profiling */ export declare function enableProfiling(enabled: boolean): void; /** Enable or disable stack trace capture */ export declare function enableStackTraces(enabled: boolean): void; /** Check if profiling is enabled */ export declare function isProfilingEnabled(): boolean; /** Track an allocation */ export declare function trackAllocation(handle: number, resourceType: ResourceType, sizeBytes: number, tag?: string): void; /** Track a deallocation */ export declare function trackDeallocation(handle: number): void; /** Get a leak report */ export declare function getLeakReport(minAgeMs?: number): LeakReport; /** Print a leak report to console */ export declare function printLeakReport(minAgeMs?: number): void; /** Reset the profiler */ export declare function resetProfiler(): void; /** Format a leak report as a string */ export declare function formatLeakReport(report: LeakReport): string; /** Get Node.js process memory usage */ export declare function getProcessMemory(): { heapUsed: number; heapTotal: number; external: number; rss: number; arrayBuffers: number; }; /** Print Node.js process memory statistics */ export declare function printProcessMemory(): void; /** Force garbage collection if available (requires --expose-gc flag) */ export declare function forceGC(): boolean; /** Take a heap snapshot if v8 is available */ export declare function takeHeapSnapshot(filename: string): Promise; //# sourceMappingURL=profiler.d.ts.map