libretro.api.perf

Performance counter and SIMD feature detection types.

Corresponds to retro_perf_callback, retro_perf_counter, and the RETRO_SIMD_* constants in libretro.h.

See also

PerfDriver

The Protocol that uses these types to expose performance counting functionality to the Core.

libretro.drivers.perf

libretro.py’s included PerfDriver implementations.

Module Attributes

retro_perf_tick_t

A performance counter tick value.

retro_time_t

A timestamp in microseconds.

retro_perf_get_time_usec_t

Return the current system time in microseconds.

retro_perf_get_counter_t

Return the number of ticks elapsed since some unspecified epoch.

retro_get_cpu_features_t

Return a bitmask of detected CPU features.

retro_perf_log_t

Log or display the state of every registered performance counter.

retro_perf_register_t

Register a performance counter with the frontend.

retro_perf_start_t

Start timing a registered performance counter.

retro_perf_stop_t

Stop timing a registered performance counter.

Classes

CpuFeatures

SIMD instruction set flags reported by the host CPU.

retro_perf_callback

Provides functions for performance profiling and CPU feature detection.

retro_perf_counter

A named performance counter for profiling hot code paths within a Core.

class CpuFeatures[source]

Bases: IntFlag

SIMD instruction set flags reported by the host CPU.

Corresponds to the RETRO_SIMD_* constants in libretro.h.

>>> from libretro.api import CpuFeatures
>>> CpuFeatures.SSE
<CpuFeatures.SSE: 1>
SSE = 1
SSE2 = 2
VMX = 4
VMX128 = 8
AVX = 16
NEON = 32
SSE3 = 64
SSSE3 = 128
MMX = 256
MMXEXT = 512
SSE4 = 1024
SSE42 = 2048
AVX2 = 4096
VFPU = 8192
PS = 16384
AES = 32768
VFPV3 = 65536
VFPV4 = 131072
POPCNT = 262144
MOVBE = 524288
CMOV = 1048576
ASIMD = 2097152
__new__(value)
other in self

Returns True if self has at least the same flags set as other.

iter(self)

Returns flags in definition order.

len(self)

Return the number of members (no aliases)

classmethod self[name]

Return the member matching name.

__init__()
class retro_perf_counter[source]

Bases: Structure

A named performance counter for profiling hot code paths within a Core.

Corresponds to retro_perf_counter in libretro.h.

>>> from libretro.api import retro_perf_counter
>>> c = retro_perf_counter()
>>> c.registered
False
ident

Human-readable identifier for this counter.

start

Tick value at the most recent start of measurement.

total

Total accumulated ticks for this counter.

call_cnt

Number of times this counter has been started.

registered

Whether this counter has been registered with the frontend.

__deepcopy__(_)[source]

Return a deep copy of this object, including all strings. Intended for use with copy.deepcopy().

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
retro_perf_get_time_usec_t

Return the current system time in microseconds.

Registered by the frontend and called by the core. The frontend should use the most accurate timer available on the platform.

Returns:

The current time, in microseconds.

Corresponds to retro_perf_get_time_usec_t in libretro.h.

retro_perf_get_counter_t

Return the number of ticks elapsed since some unspecified epoch.

Registered by the frontend and called by the core. The exact meaning of a tick depends on the platform (typically nanoseconds or CPU cycles).

Returns:

The current tick count.

Corresponds to retro_perf_get_counter_t in libretro.h.

retro_get_cpu_features_t

Return a bitmask of detected CPU features.

Registered by the frontend and called by the core to dispatch CPU-specific code paths at runtime.

Returns:

A bitmask of CpuFeatures flags.

Corresponds to retro_get_cpu_features_t in libretro.h.

retro_perf_log_t

Log or display the state of every registered performance counter.

Registered by the frontend and called by the core. The exact presentation is up to the frontend.

Corresponds to retro_perf_log_t in libretro.h.

retro_perf_register_t

Register a performance counter with the frontend.

Registered by the frontend and called by the core once per counter, before the counter is started or stopped.

Parameters:

counter – Pointer to a retro_perf_counter to register. Its ident field must be set; all other fields must be zero or False.

Corresponds to retro_perf_register_t in libretro.h.

retro_perf_start_t

Start timing a registered performance counter.

Registered by the frontend and called by the core right before the code being measured.

Parameters:

counter – Pointer to a retro_perf_counter that has been registered with retro_perf_register_t.

Corresponds to retro_perf_start_t in libretro.h.

retro_perf_stop_t

Stop timing a registered performance counter.

Registered by the frontend and called by the core right after the code being measured; the elapsed time is added to the counter’s total.

Parameters:

counter – Pointer to the same retro_perf_counter that was previously passed to retro_perf_start_t.

Corresponds to retro_perf_stop_t in libretro.h.

class retro_perf_callback[source]

Bases: Structure

Provides functions for performance profiling and CPU feature detection.

Corresponds to retro_perf_callback in libretro.h.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
get_time_usec

Returns the current time in microseconds.

get_cpu_features

Returns a bitmask of CpuFeatures.

get_perf_counter

Returns the current performance counter tick value.

perf_register

Registers a performance counter.

perf_start

Starts a performance counter.

perf_stop

Stops a performance counter.

perf_log

Logs all registered performance counters.

__deepcopy__(_)[source]

Return a deep copy of this object. Intended for use with copy.deepcopy().

>>> import copy
>>> from libretro.api import retro_perf_callback
>>> copy.deepcopy(retro_perf_callback()).get_time_usec is None
True
retro_time_t

A timestamp in microseconds.

retro_perf_tick_t

A performance counter tick value.