UNPKG

@ai-capabilities-suite/mcp-debugger-core

Version:

Core debugging engine for Node.js and TypeScript applications. Provides Inspector Protocol integration, breakpoint management, variable inspection, execution control, profiling, hang detection, and source map support.

153 lines (152 loc) 3.95 kB
import { InspectorClient } from './inspector-client'; /** * Heap snapshot node */ export interface HeapSnapshotNode { type: string; name: string; id: number; selfSize: number; edgeCount: number; traceNodeId?: number; } /** * Heap snapshot edge (reference between objects) */ export interface HeapSnapshotEdge { type: string; name: string; toNode: number; } /** * Heap snapshot data structure */ export interface HeapSnapshot { snapshot: { meta: { node_fields: string[]; node_types: string[][]; edge_fields: string[]; edge_types: string[][]; }; node_count: number; edge_count: number; }; nodes: number[]; edges: number[]; strings: string[]; } /** * Memory usage statistics */ export interface MemoryUsage { usedSize: number; totalSize: number; timestamp: number; } /** * Memory leak detection result */ export interface MemoryLeakAnalysis { isLeaking: boolean; growthRate: number; snapshots: MemoryUsage[]; suspiciousObjects: Array<{ type: string; count: number; totalSize: number; growthRate: number; }>; } /** * Memory usage report */ export interface MemoryReport { totalHeapSize: number; usedHeapSize: number; heapSizeLimit: number; mallocedMemory: number; peakMallocedMemory: number; objectTypes: Array<{ type: string; count: number; size: number; percentage: number; }>; } /** * Memory Profiler for capturing heap snapshots and detecting memory leaks * Uses the HeapProfiler domain of Chrome DevTools Protocol */ export declare class MemoryProfiler { private inspector; private tracking; private snapshots; private memoryUsageHistory; constructor(inspector: InspectorClient); /** * Enable heap profiling */ enable(): Promise<void>; /** * Disable heap profiling */ disable(): Promise<void>; /** * Take a heap snapshot * @returns The heap snapshot data */ takeHeapSnapshot(): Promise<HeapSnapshot>; /** * Start tracking memory allocation over time * @param samplingInterval Sampling interval in bytes (default: 32768) */ startTrackingHeapObjects(samplingInterval?: number): Promise<void>; /** * Stop tracking memory allocation * @param reportProgress Whether to report progress * @returns The final heap snapshot */ stopTrackingHeapObjects(reportProgress?: boolean): Promise<HeapSnapshot>; /** * Get current memory usage statistics * @returns Memory usage information */ getMemoryUsage(): Promise<MemoryUsage>; /** * Collect garbage to clean up unreferenced objects */ collectGarbage(): Promise<void>; /** * Detect memory leaks by analyzing heap growth over time * Takes multiple snapshots and compares them * @param durationMs Duration to monitor in milliseconds * @param intervalMs Interval between snapshots in milliseconds * @returns Memory leak analysis */ detectMemoryLeaks(durationMs?: number, intervalMs?: number): Promise<MemoryLeakAnalysis>; /** * Generate a memory usage report from a heap snapshot * @param snapshot The heap snapshot to analyze * @returns Memory usage report */ generateMemoryReport(snapshot?: HeapSnapshot): Promise<MemoryReport>; /** * Format memory report as a human-readable string * @param report The memory report to format * @returns Formatted string */ formatMemoryReport(report: MemoryReport): string; /** * Get all captured snapshots */ getSnapshots(): HeapSnapshot[]; /** * Get memory usage history */ getMemoryUsageHistory(): MemoryUsage[]; /** * Clear all captured snapshots and history */ clearHistory(): void; }