profiler
High-performance thread-safe telemetry and profiling engine.
The Profiler provides advanced metrics collection lock-free across all background ThreadPool worker processes and the primary Pygame execution loop. It tracks function execution times bound by strict memory caps to prevent tracking leaks and dumps fully aggregated JSON reports upon safe shutdown or fatal application crashes.
- class profiler.ThreadSampleBuffer(max_samples)[source]
Bases:
objectIsolated, memory-bounded buffer dedicated to a specific thread’s metrics.
Prevents data contention between threads by allocating isolated Deques for profiling categories. Ensures thread-safe metric aggregation.
- Parameters:
max_samples (int) – The maximum number of profiling samples to retain per category.
- class profiler.Profiler(max_samples_per_category=10000)[source]
Bases:
objectProduction-grade game telemetry system.
Features: - Zero lock-contention during chunk generation/rendering. - No memory leaks (Bounded memory footprints). - Perfect multi-thread data aggregation (No data loss on thread exit). - Safe, synchronous, non-corrupting shutdown reports.
- Parameters:
max_samples_per_category (int) – Limit on tracking samples to bound memory footprint.
- record(category, elapsed_time)[source]
Records metrics completely lock-free relative to other concurrent threads.