UNPKG

xypriss-security

Version:

XyPriss Security is an advanced JavaScript security library designed for enterprise applications. It provides military-grade encryption, secure data structures, quantum-resistant cryptography, and comprehensive security utilities for modern web applicatio

126 lines (122 loc) 3.65 kB
'use strict'; var performanceTimer = require('../../performance/performance-timer.js'); var fortifiedLogger = require('../fortified-logger.js'); /** * Timing Manager - Modular component for performance timing * Part of the minimal modular architecture */ class TimingManager { constructor(functionId) { this.performanceTimer = null; this.functionId = functionId; } /** * Initialize performance timer if needed */ initializeTimer() { if (!this.performanceTimer) { this.performanceTimer = new performanceTimer.PerformanceTimer(`exec_${Date.now()}_${this.functionId}`, false); } } /** * Start timing a specific operation */ startTimer(label, metadata) { this.initializeTimer(); this.performanceTimer.startTimer(label, metadata); } /** * End timing for a specific operation */ endTimer(label, additionalMetadata) { if (!this.performanceTimer) { fortifiedLogger.fortifiedLogger.warn("TIMING", "Performance timer not initialized. Call startTimer first.", { functionId: this.functionId }); return 0; } return this.performanceTimer.endTimer(label, additionalMetadata); } /** * Measure delay between two points */ measureDelay(startPoint, endPoint) { if (!this.performanceTimer) { fortifiedLogger.fortifiedLogger.warn("TIMING", "Performance timer not initialized.", { functionId: this.functionId }); return 0; } return this.performanceTimer.measureDelay(startPoint, endPoint); } /** * Time a function execution */ async timeFunction(label, fn, metadata) { this.initializeTimer(); return await this.performanceTimer.timeFunction(label, fn, metadata); } /** * Get timing statistics */ getTimingStats() { if (!this.performanceTimer) { return { totalMeasurements: 0, completedMeasurements: 0, activeMeasurements: 0, measurements: [], summary: { totalDuration: 0, averageDuration: 0, minDuration: 0, maxDuration: 0, slowestOperation: "", fastestOperation: "", }, }; } return this.performanceTimer.getStats(); } /** * Clear all timing measurements */ clearTimings() { this.performanceTimer?.clear(); } /** * Get measurements by pattern */ getMeasurementsByPattern(pattern) { if (!this.performanceTimer) { return []; } return this.performanceTimer.getMeasurementsByPattern(pattern); } /** * Check if a timer is active */ isTimerActive(label) { if (!this.performanceTimer) { return false; } return this.performanceTimer.isTimerActive(label); } /** * Get active timers */ getActiveTimers() { if (!this.performanceTimer) { return []; } return this.performanceTimer.getActiveTimers(); } /** * Cleanup resources */ destroy() { if (this.performanceTimer) { this.performanceTimer.clear(); this.performanceTimer = null; } fortifiedLogger.fortifiedLogger.debug("TIMING", `Timing manager destroyed for function: ${this.functionId}`); } } exports.TimingManager = TimingManager; //# sourceMappingURL=timing-manager.js.map