/** * @file Performance Monitor * @description Enterprise-grade performance monitoring with metrics collection, * profiling, and web vitals tracking */ /** * Performance metric types */ export type MetricType = 'timing' | 'counter' | 'gauge' | 'histogram'; /** * Performance metric entry */ export interface PerformanceMetric { name: string; type: MetricType; value: number; timestamp: number; tags?: Record; unit?: string; } /** * Histogram bucket */ interface HistogramBucket { le: number; count: number; } /** * Histogram data */ export interface HistogramData { buckets: HistogramBucket[]; sum: number; count: number; min: number; max: number; avg: number; p50: number; p90: number; p99: number; } /** * Performance monitor configuration */ export interface PerformanceMonitorConfig { /** Enable performance monitoring */ enabled?: boolean; /** Sample rate (0-1) */ sampleRate?: number; /** Buffer size before flush */ bufferSize?: number; /** Flush interval (ms) */ flushInterval?: number; /** Metric reporter function */ reporter?: (metrics: PerformanceMetric[]) => void | Promise; /** Default tags for all metrics */ defaultTags?: Record; } /** * Performance monitor class */ export declare class PerformanceMonitor { private config; private buffer; private counters; private gauges; private histograms; private flushTimer; private marks; constructor(config?: PerformanceMonitorConfig); /** * Record a timing metric */ timing(name: string, value: number, tags?: Record): void; /** * Increment a counter */ increment(name: string, value?: number, tags?: Record): void; /** * Decrement a counter */ decrement(name: string, value?: number, tags?: Record): void; /** * Set a gauge value */ gauge(name: string, value: number, tags?: Record): void; /** * Record a histogram value */ histogram(name: string, value: number, tags?: Record): void; /** * Get histogram statistics */ getHistogramStats(name: string): HistogramData | null; /** * Mark a point in time for later measurement */ mark(name: string): void; /** * Measure time since a mark */ measure(name: string, markName: string, tags?: Record): number; /** * Create a timer function */ startTimer(name: string, tags?: Record): () => number; /** * Time an async function */ timeAsync(name: string, fn: () => Promise, tags?: Record): Promise; /** * Time a sync function */ timeSync(name: string, fn: () => T, tags?: Record): T; /** * Flush metrics buffer */ flush(): Promise; /** * Get all current counter values */ getCounters(): Map; /** * Get all current gauge values */ getGauges(): Map; /** * Reset all metrics */ reset(): void; /** * Dispose the monitor */ dispose(): void; /** * Start periodic flush timer */ private startFlushTimer; /** * Check if metric should be sampled */ private shouldSample; /** * Record histogram internally */ private recordHistogram; /** * Add metric to buffer */ private addMetric; /** * Generate key from name and tags */ private getKey; } /** * Web Vitals metrics */ export interface WebVitals { /** Largest Contentful Paint */ LCP?: number; /** First Input Delay */ FID?: number; /** Cumulative Layout Shift */ CLS?: number; /** First Contentful Paint */ FCP?: number; /** Time to First Byte */ TTFB?: number; /** Interaction to Next Paint */ INP?: number; } /** * Web Vitals collector */ export declare class WebVitalsCollector { private vitals; private callbacks; private observer; /** * Start collecting web vitals */ start(): void; /** * Get current vitals */ getVitals(): WebVitals; /** * Subscribe to vitals updates */ subscribe(callback: (vitals: WebVitals) => void): () => void; /** * Stop collecting */ stop(): void; /** * Observe paint timing */ private observePaintTiming; /** * Observe layout shift */ private observeLayoutShift; /** * Observe LCP */ private observeLCP; /** * Observe first input */ private observeFirstInput; /** * Notify subscribers */ private notify; } /** * Resource timing utilities */ export declare const resourceTiming: { /** * Get all resource timing entries */ getEntries(): PerformanceResourceTiming[]; /** * Get entries by type */ getEntriesByType(type: "script" | "link" | "img" | "fetch" | "xmlhttprequest"): PerformanceResourceTiming[]; /** * Get slow resources */ getSlowResources(threshold?: number): PerformanceResourceTiming[]; /** * Get total transfer size */ getTotalTransferSize(): number; /** * Get resource summary */ getSummary(): { count: number; totalSize: number; slowCount: number; avgDuration: number; byType: Record; }; /** * Clear resource timing buffer */ clearBuffer(): void; }; /** * Long task observer */ export declare class LongTaskObserver { private observer; private tasks; private callbacks; /** * Start observing long tasks */ start(): void; /** * Stop observing */ stop(): void; /** * Subscribe to long task events */ subscribe(callback: (task: { startTime: number; duration: number; attribution: string; }) => void): () => void; /** * Get all recorded long tasks */ getTasks(): Array<{ startTime: number; duration: number; attribution: string; }>; /** * Get task statistics */ getStats(): { count: number; totalDuration: number; avgDuration: number; maxDuration: number; }; /** * Clear recorded tasks */ clear(): void; /** * Notify callbacks */ private notifyCallbacks; } /** * Global performance monitor singleton */ export declare const performanceMonitor: PerformanceMonitor; /** * Global web vitals collector */ export declare const webVitals: WebVitalsCollector; /** * Global long task observer */ export declare const longTaskObserver: LongTaskObserver; export {};