/** * Performance monitoring utilities * * Provides utilities for tracking and logging slow operations (>500ms) * Requirements: 12.4 */ import type { Logger } from './logger.js'; /** * Performance threshold in milliseconds * Operations taking longer than this will be logged as warnings */ export declare const SLOW_OPERATION_THRESHOLD_MS = 500; /** * Performance timer for tracking operation duration */ export declare class PerformanceTimer { private startTime; private readonly operation; private readonly logger; private readonly context?; constructor(operation: string, logger: Logger, context?: Record); /** * End the timer and log if operation was slow * @returns Duration in milliseconds */ end(): number; /** * Get current elapsed time without ending the timer * @returns Elapsed time in milliseconds */ elapsed(): number; /** * Reset the timer to current time */ reset(): void; } /** * Create a performance timer for an operation * * @param operation - Name of the operation being timed * @param logger - Logger instance for logging slow operations * @param context - Optional context to include in logs * @returns Performance timer instance * * @example * const timer = startTimer('parseFile', logger, { filePath: 'src/index.ts' }); * // ... perform operation ... * const duration = timer.end(); // Logs warning if >500ms */ export declare function startTimer(operation: string, logger: Logger, context?: Record): PerformanceTimer; /** * Measure the duration of an async operation and log if slow * * @param operation - Name of the operation * @param logger - Logger instance * @param fn - Async function to measure * @param context - Optional context to include in logs * @returns Result of the function and duration * * @example * const result = await measureAsync('generateEmbedding', logger, async () => { * return await embeddingService.generateEmbedding(text); * }, { textLength: text.length }); */ export declare function measureAsync(operation: string, logger: Logger, fn: () => Promise, context?: Record): Promise; /** * Measure the duration of a synchronous operation and log if slow * * @param operation - Name of the operation * @param logger - Logger instance * @param fn - Function to measure * @param context - Optional context to include in logs * @returns Result of the function * * @example * const result = measureSync('parseAST', logger, () => { * return parser.parse(sourceCode); * }, { fileSize: sourceCode.length }); */ export declare function measureSync(operation: string, logger: Logger, fn: () => T, context?: Record): T; /** * Memory usage snapshot */ export interface MemorySnapshot { rss: number; heapTotal: number; heapUsed: number; external: number; timestamp: number; } /** * Get current memory usage * @returns Memory usage snapshot in bytes */ export declare function getMemoryUsage(): MemorySnapshot; /** * Format memory size in human-readable format * @param bytes - Memory size in bytes * @returns Formatted string (e.g., "123.45 MB") */ export declare function formatMemorySize(bytes: number): string; /** * Log current memory usage * @param logger - Logger instance * @param context - Optional context */ export declare function logMemoryUsage(logger: Logger, context?: Record): void; /** * Track memory usage during an operation * Logs memory before, after, and the delta * * @param operation - Name of the operation * @param logger - Logger instance * @param fn - Async function to track * @param context - Optional context * @returns Result of the function */ export declare function trackMemory(operation: string, logger: Logger, fn: () => Promise, context?: Record): Promise; //# sourceMappingURL=performance.d.ts.map