performance.py

performance.py – Performance monitoring, profiling, and garbage collection.

Provides:
- PerformanceMonitor: FPS tracking, hardware info, and task timing.
- GarbageCollector: automatic cleanup of caches.
- Integration with BackgroundTaskManager for per‑task CPU/memory metrics.

class TimeProfile

Description

No documentation

Attributes
end: Any = stop
Methods
def __init__(self: Any, category: str = '', max_history: int = 60) -> Any
No documentation
def start(self: Any) -> Any
No documentation
def stop(self: Any) -> Any
No documentation
def _insert_new_history(self: Any) -> Any
No documentation
def duration(self: Any) -> float
No documentation
def record_current(self: Any) -> Any
No documentation

class PerformanceProfiler

Description

No documentation

Methods
def __init__(self: Any, max_history: int = 100) -> Any
No documentation
def enable(self: Any, enabled: bool = True) -> Any
No documentation
def disable(self: Any) -> Any
No documentation
def is_enabled(self: Any) -> bool
No documentation
def get_timer(self: Any, category: str) -> TimeProfile
No documentation
def get_all_timers(self: Any) -> Dict[str, TimeProfile]
No documentation
def get_timers_list(self: Any) -> List[TimeProfile]
No documentation
def start_timer(self: Any, category: str) -> Any
No documentation
def stop_timer(self: Any, category: str) -> Any
No documentation
def create_timer(self: Any, category: str) -> Any
No documentation
def begin_frame(self: Any) -> Any
No documentation
def end_frame(self: Any) -> Any
No documentation
def get_frame_timings(self: Any) -> Dict[str, float]
No documentation
def get_timing_stats(self: Any, category_prefix: str) -> Dict[str, Any]
No documentation

class PerformanceMonitor

Description

No documentation

Methods
def __init__(self: Any, history_size: int = 300) -> Any
No documentation
def start_task_timer(self: Any, task_id: str) -> Any
Start measuring CPU time and memory for a background task.
def end_task_timer(self: Any, task_id: str) -> Optional[Dict[str, float]]
Stop measuring and return {'cpu_ms': ..., 'mem_bytes': ...}.
def get_task_metrics(self: Any, task_id: str) -> Optional[Dict[str, float]]
Return the last recorded metrics for a task.
def clear_task_metrics(self: Any) -> Any
Clear all stored task metrics.
def get_frame_timing_breakdown(self: Any) -> Dict[str, float]
No documentation
def get_performance_summary(self: Any) -> Dict[str, Any]
No documentation
def enable_profiling(self: Any, enabled: bool = True) -> Any
No documentation
def is_profiling_enabled(self: Any) -> bool
No documentation
def create_timer(self: Any, category: str) -> Any
No documentation
def start_timer(self: Any, category: str) -> Any
No documentation
def end_timer(self: Any, category: str) -> Any
No documentation
def get_all_timers(self: Any) -> Dict[str, TimeProfile]
No documentation
def get_list_timers(self: Any) -> List[TimeProfile]
No documentation
def timers_names(self: Any) -> List[str]
No documentation
def get_update_timing_stats(self: Any) -> Dict[str, Any]
No documentation
def get_timing(self: Any, category: str) -> Optional[TimeProfile]
No documentation
def get_render_timing_stats(self: Any) -> Dict[str, Any]
No documentation
def get_hardware_info(self: Any) -> Dict[str, str]
No documentation
def update_frame(self: Any) -> Any
No documentation
def end_frame(self: Any) -> Any
No documentation
def get_stats(self: Any) -> Dict[str, float]
No documentation
def _getMemUsageClass(self: Any, classM: Any, humanize: bool = True) -> Dict[str, Any]
Workaround to access internal usage data of a class instance.
Used by the UI demo; returns sizes of attributes in bytes (or humanised).
def _get_empty_stats(self: Any) -> Dict[str, float]
No documentation

class GarbageCollector

Description

No documentation

Methods
def __init__(self: Any, engine: Any = None) -> Any
No documentation
def mark_font_unused(self: Any, font: Any) -> Any
No documentation
def mark_surface_unused(self: Any, surface: Any) -> Any
No documentation
def cleanup(self: Any, force: bool = False) -> Any
No documentation
Back to Utils Module