extends Node class_name PerformanceMonitoringSystem ## 性能监控和报警系统 ## 实时监控游戏性能并在出现问题时发出警报 # 性能指标类型 enum MetricType { FPS, # 帧率 MEMORY_USAGE, # 内存使用 NETWORK_LATENCY, # 网络延迟 LOAD_TIME, # 加载时间 RENDER_TIME, # 渲染时间 SCRIPT_TIME, # 脚本执行时间 PHYSICS_TIME, # 物理计算时间 AUDIO_LATENCY, # 音频延迟 DISK_IO, # 磁盘IO CPU_USAGE # CPU使用率 } # 性能警报级别 enum AlertLevel { INFO, # 信息 WARNING, # 警告 CRITICAL, # 严重 EMERGENCY # 紧急 } # 性能指标数据结构 class PerformanceMetric: var metric_type: MetricType var value: float var timestamp: float var threshold_warning: float var threshold_critical: float var unit: String func _init(type: MetricType, val: float, warn_threshold: float = 0.0, crit_threshold: float = 0.0, metric_unit: String = ""): metric_type = type value = val timestamp = Time.get_unix_time_from_system() threshold_warning = warn_threshold threshold_critical = crit_threshold unit = metric_unit # 性能警报数据结构 class PerformanceAlert: var alert_id: String var metric_type: MetricType var level: AlertLevel var message: String var value: float var threshold: float var timestamp: float var resolved: bool = false func _init(type: MetricType, alert_level: AlertLevel, msg: String, val: float, thresh: float): alert_id = _generate_alert_id() metric_type = type level = alert_level message = msg value = val threshold = thresh timestamp = Time.get_unix_time_from_system() func _generate_alert_id() -> String: return "alert_%d_%d" % [Time.get_unix_time_from_system(), randi()] # 数据存储 var performance_history: Dictionary = {} # MetricType -> Array[PerformanceMetric] var active_alerts: Array[PerformanceAlert] = [] var resolved_alerts: Array[PerformanceAlert] = [] var monitoring_enabled: bool = true # 监控配置 var monitoring_interval: float = 1.0 # 监控间隔(秒) var history_retention_time: float = 3600.0 # 历史数据保留时间(1小时) var max_history_entries: int = 1000 # 性能阈值配置 var performance_thresholds: Dictionary = { MetricType.FPS: {"warning": 30.0, "critical": 15.0}, MetricType.MEMORY_USAGE: {"warning": 512.0, "critical": 1024.0}, # MB MetricType.NETWORK_LATENCY: {"warning": 200.0, "critical": 500.0}, # ms MetricType.LOAD_TIME: {"warning": 5.0, "critical": 10.0}, # seconds