72 lines
1.9 KiB
Python
Executable File
72 lines
1.9 KiB
Python
Executable File
"""XIC Diagnostics — real-time pipeline introspection.
|
|
|
|
Provides VM state snapshots, segment profiling, and execution tracing.
|
|
"""
|
|
|
|
import time
|
|
from typing import Dict, Any, List, Optional
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class VMState:
|
|
registers: Dict[str, Any] = field(default_factory=dict)
|
|
stack: List[Any] = field(default_factory=list)
|
|
mode: str = "unknown"
|
|
instruction_pointer: int = 0
|
|
|
|
|
|
@dataclass
|
|
class TraceEvent:
|
|
event: str
|
|
timestamp: float
|
|
details: Dict[str, Any]
|
|
|
|
|
|
class XICDiagnostics:
|
|
def __init__(self, enabled: bool = True):
|
|
self.enabled = enabled
|
|
self._traces: List[TraceEvent] = []
|
|
self._vm_states: List[VMState] = []
|
|
self._segment_timings: Dict[str, float] = {}
|
|
self._instruction_count: int = 0
|
|
|
|
def trace(self, event: str, details: Optional[Dict[str, Any]] = None) -> None:
|
|
if not self.enabled:
|
|
return
|
|
self._traces.append(TraceEvent(
|
|
event=event,
|
|
timestamp=time.time(),
|
|
details=details or {}
|
|
))
|
|
|
|
def snapshot_vm(self, state: VMState) -> None:
|
|
if not self.enabled:
|
|
return
|
|
self._vm_states.append(state)
|
|
|
|
def record_segment(self, seg_id: str, elapsed: float) -> None:
|
|
self._segment_timings[seg_id] = elapsed
|
|
|
|
def count_instruction(self) -> None:
|
|
self._instruction_count += 1
|
|
|
|
def report(self) -> Dict[str, Any]:
|
|
return {
|
|
"enabled": self.enabled,
|
|
"traces": len(self._traces),
|
|
"instructions": self._instruction_count,
|
|
"segments": len(self._segment_timings),
|
|
"segment_timings": dict(self._segment_timings),
|
|
"vm_snapshots": len(self._vm_states),
|
|
}
|
|
|
|
def clear(self) -> None:
|
|
self._traces.clear()
|
|
self._vm_states.clear()
|
|
self._segment_timings.clear()
|
|
self._instruction_count = 0
|
|
|
|
|
|
xic_diagnostics = XICDiagnostics()
|