/** * Performance Profiling Utility * * Advanced performance profiling with detailed operation tracking, * memory usage analysis, and bottleneck identification. */ import { type PerformanceEntry } from 'perf_hooks'; export interface PerformanceReport { averageDuration: number; cpuStats: { averageSystemTime: number; averageUserTime: number; totalSystemTime: number; totalUserTime: number; }; memoryStats: { averageDelta: { external: number; heapTotal: number; heapUsed: number; rss: number; }; peakUsage: NodeJS.MemoryUsage; }; performanceEntries: PerformanceEntry[]; slowestOperations: Array<{ duration: number; labels?: Record; operation: string; }>; timestamp: number; totalProfiles: number; } export interface ProfileResult { cpuUsage?: { after: NodeJS.CpuUsage; before: NodeJS.CpuUsage; delta: { system: number; user: number; }; }; duration: number; endTime: number; labels?: Record; memoryUsage?: { after: NodeJS.MemoryUsage; before: NodeJS.MemoryUsage; delta: { external: number; heapTotal: number; heapUsed: number; rss: number; }; }; operation: string; startTime: number; } export interface ProfilingOptions { enableCpuProfiling?: boolean; enableMemoryProfiling?: boolean; enablePerformanceObserver?: boolean; maxProfileHistory?: number; sampleInterval?: number; } /** * Performance Profiler Class * * Provides comprehensive performance profiling capabilities including * timing, memory usage, CPU usage, and performance monitoring. */ export declare class PerformanceProfiler { private logger; private metricsCollector; private monitoringInterval?; private options; private performanceObserver?; private profiles; constructor(options?: ProfilingOptions); /** * Profile an async operation with detailed metrics */ profileAsync(operation: string, fn: () => Promise, labels?: Record): Promise; /** * Profile a sync operation with detailed metrics */ profileSync(operation: string, fn: () => T, labels?: Record): T; /** * Start continuous monitoring */ startMonitoring(intervalMs?: number): void; /** * Stop continuous monitoring */ stopMonitoring(): void; /** * Take a system performance snapshot */ takeSystemSnapshot(): void; /** * Generate a comprehensive performance report */ generateReport(): PerformanceReport; /** * Get recent profiles for a specific operation */ getRecentProfiles(operation?: string, limit?: number): ProfileResult[]; /** * Clear all profiling data */ clearProfiles(): void; /** * Get profiler statistics */ getStats(): { averageDuration: number; cpuProfiles: number; memoryProfiles: number; newestProfile: number; oldestProfile: number; totalProfiles: number; }; /** * Destroy the profiler and clean up resources */ destroy(): void; /** * Record a profile result */ private recordProfile; /** * Setup performance observer for automatic tracking */ private setupPerformanceObserver; } /** * Get the global performance profiler instance */ export declare function getPerformanceProfiler(options?: ProfilingOptions): PerformanceProfiler; /** * Set a custom global performance profiler instance */ export declare function setPerformanceProfiler(profiler: PerformanceProfiler): void; /** * Convenience functions for global profiling */ export declare function generatePerformanceReport(): PerformanceReport; export declare function profileAsync(operation: string, fn: () => Promise, labels?: Record): Promise; export declare function profileSync(operation: string, fn: () => T, labels?: Record): T; export declare function startSystemMonitoring(intervalMs?: number): void; /** * Decorator for profiling class methods */ export declare function profileMethod(labels?: Record): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; //# sourceMappingURL=performance-profiler.d.ts.map