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.

115 lines (114 loc) 3.03 kB
import { InspectorClient } from './inspector-client'; /** * CPU profile node representing a function call in the profile */ export interface ProfileNode { id: number; callFrame: { functionName: string; scriptId: string; url: string; lineNumber: number; columnNumber: number; }; hitCount: number; children?: number[]; positionTicks?: Array<{ line: number; ticks: number; }>; } /** * CPU profile data structure */ export interface CPUProfile { nodes: ProfileNode[]; startTime: number; endTime: number; samples?: number[]; timeDeltas?: number[]; } /** * Analyzed profile data with bottleneck information */ export interface ProfileAnalysis { totalTime: number; topFunctions: Array<{ functionName: string; file: string; line: number; selfTime: number; totalTime: number; percentage: number; }>; bottlenecks: Array<{ functionName: string; file: string; line: number; reason: string; impact: number; }>; } /** * Flame graph node for visualization */ export interface FlameGraphNode { name: string; value: number; children?: FlameGraphNode[]; file?: string; line?: number; } /** * CPU Profiler for capturing and analyzing CPU profiles * Uses the Profiler domain of Chrome DevTools Protocol */ export declare class CPUProfiler { private inspector; private profiling; private currentProfile; constructor(inspector: InspectorClient); /** * Start CPU profiling * Enables the Profiler domain and starts collecting CPU profile data */ start(): Promise<void>; /** * Stop CPU profiling and return the profile data * @returns The captured CPU profile */ stop(): Promise<CPUProfile>; /** * Check if profiling is currently active */ isProfiling(): boolean; /** * Get the current profile (if available) */ getCurrentProfile(): CPUProfile | null; /** * Generate a flame graph from the CPU profile * @param profile The CPU profile to convert * @returns Root node of the flame graph */ generateFlameGraph(profile: CPUProfile): FlameGraphNode; /** * Generate a call tree from the CPU profile * Similar to flame graph but organized differently * @param profile The CPU profile to convert * @returns Root node of the call tree */ generateCallTree(profile: CPUProfile): FlameGraphNode; /** * Analyze the CPU profile to identify bottlenecks * @param profile The CPU profile to analyze * @returns Analysis results with top functions and bottlenecks */ analyzeProfile(profile: CPUProfile): ProfileAnalysis; /** * Format profile analysis as a human-readable string * @param analysis The profile analysis to format * @returns Formatted string */ formatAnalysis(analysis: ProfileAnalysis): string; }