UNPKG

@dharshansr/gitgenius

Version:

AI-powered commit message generator with enhanced features

62 lines 2.18 kB
import { performance } from 'perf_hooks'; import { ConfigManager } from '../core/ConfigManager.js'; export class PerformanceMonitor { constructor() { this.metrics = []; this.timers = new Map(); this.configManager = new ConfigManager(); } static getInstance() { if (!PerformanceMonitor.instance) { PerformanceMonitor.instance = new PerformanceMonitor(); } return PerformanceMonitor.instance; } startTimer(operation) { this.timers.set(operation, performance.now()); } endTimer(operation, success = true) { const startTime = this.timers.get(operation); if (startTime) { const duration = performance.now() - startTime; this.recordMetric({ operation, duration, timestamp: Date.now(), success }); this.timers.delete(operation); } } recordMetric(metric) { this.metrics.push(metric); // Keep only last 100 metrics if (this.metrics.length > 100) { this.metrics = this.metrics.slice(-100); } // Store in config for persistence this.configManager.setConfigValue('performanceMetrics', this.metrics); } getAverageTime(operation) { const operationMetrics = this.metrics.filter(m => m.operation === operation && m.success); if (operationMetrics.length === 0) return 0; const total = operationMetrics.reduce((sum, m) => sum + m.duration, 0); return total / operationMetrics.length; } getSuccessRate(operation) { const operationMetrics = this.metrics.filter(m => m.operation === operation); if (operationMetrics.length === 0) return 0; const successful = operationMetrics.filter(m => m.success).length; return (successful / operationMetrics.length) * 100; } getMetrics() { return [...this.metrics]; } clearMetrics() { this.metrics = []; this.configManager.setConfigValue('performanceMetrics', []); } } //# sourceMappingURL=PerformanceMonitor.js.map