mini_arcade_core.utils.profiler

Game core module defining the Game class and configuration.

Attributes

Classes

Ansi

ANSI escape codes for terminal text formatting.

FrameTimingReport

Report of frame timing data.

FrameTimingFormatter

Formats a FrameTimingReport into a colored, multi-line table string.

FrameTimerConfig

Configuration for FrameTimer.

FrameTimer

Simple frame timer for marking and reporting time intervals.

Module Contents

mini_arcade_core.utils.profiler.perf_logger
class mini_arcade_core.utils.profiler.Ansi(*args, **kwds)

Bases: enum.Enum

ANSI escape codes for terminal text formatting.

cvar RESET (str): Reset all formatting. cvar BOLD (str): Bold text. cvar DIM (str): Dim text. cvar RED (str): Red text. cvar GREEN (str): Green text. cvar YELLOW (str): Yellow text. cvar CYAN (str): Cyan text. cvar MAGENTA (str): Magenta text. cvar WHITE (str): White text.

RESET = '\x1b[0m'
BOLD = '\x1b[1m'
DIM = '\x1b[2m'
RED = '\x1b[91m'
GREEN = '\x1b[92m'
YELLOW = '\x1b[93m'
CYAN = '\x1b[96m'
MAGENTA = '\x1b[95m'
WHITE = '\x1b[97m'
class mini_arcade_core.utils.profiler.FrameTimingReport

Report of frame timing data.

Variables:
  • (int) (frame_index) – Index of the frame.

  • float]) (diffs_ms (Dict[str,) – Dictionary of time differences in milliseconds.

  • (float) (budget_ms) – Total time in milliseconds.

  • (float) – Frame budget in milliseconds.

frame_index: int
diffs_ms: Dict[str, float]
total_ms: float
budget_ms: float
class mini_arcade_core.utils.profiler.FrameTimingFormatter

Formats a FrameTimingReport into a colored, multi-line table string. Keeps FrameTimer lean and avoids pylint complexity in the timer itself.

Variables:
  • (int) (top_n) – Target frames per second for budget calculation.

  • (int) – Number of top time-consuming segments to display.

  • (float) (min_ms) – Minimum time in milliseconds to include in the top list.

  • ...]) (phases (tuple[tuple[str, str],) – Tuples of (display name, mark key) for table columns.

target_fps: int = 60
top_n: int = 6
min_ms: float = 0.05
phases: tuple[tuple[str, str], Ellipsis] = (('events', 'frame_start->events_polled'), ('input', 'events_polled->input_built'), ('tick',...
make_report(frame_index: int, diffs_ms: Dict[str, float]) FrameTimingReport

Create a FrameTimingReport from the given diffs.

Parameters:
  • frame_index (int) – Index of the frame.

  • diffs_ms (Dict[str, float]) – Dictionary of time differences in milliseconds.

Returns:

FrameTimingReport instance.

Return type:

FrameTimingReport

format(report: FrameTimingReport) str

Format the FrameTimingReport into a colored string.

Parameters:

report (FrameTimingReport) – FrameTimingReport instance.

Returns:

Formatted string.

Return type:

str

class mini_arcade_core.utils.profiler.FrameTimerConfig

Configuration for FrameTimer.

Variables:
  • (bool) (enabled) – Whether timing is enabled.

  • (int) (report_every) – Number of frames between reports.

enabled: bool = False
report_every: int = 60
class mini_arcade_core.utils.profiler.FrameTimer

Simple frame timer for marking and reporting time intervals.

Variables:
  • (FrameTimerConfig) (config) – Configuration for the timer.

  • (FrameTimingFormatter) (formatter) – Formatter for timing reports.

  • float]) (marks (Dict[str,) – Recorded time marks.

config: FrameTimerConfig
formatter: FrameTimingFormatter
marks: Dict[str, float]
clear()

Clear all recorded marks.

mark(name: str)

Record a time mark with the given name.

Parameters:

name (str) – Name of the mark.

report_ms() Dict[str, float]

Returns diffs between consecutive marks in insertion order.

Returns:

Dictionary mapping “start->end” to time difference in milliseconds.

Return type:

Dict[str, float]

should_report(frame_index: int) bool

Determine if a report should be emitted for the given frame index.

Parameters:

frame_index (int) – Current frame index.

Returns:

True if a report should be emitted, False otherwise.

Return type:

bool

emit(frame_index: int)

Emit a timing report to the performance logger.

Parameters:

frame_index (int) – Current frame index.