API reference

CpuProfiler Object

CpuProfiler provides a Kotlin interface to the native ImGui CPU Profiler. This allows profiling of frame timing and phase breakdown from Kotlin code.
The CPU profiler integrates with the ImGui debug window to visualize frame timing, detect spikes, and show a timeline of phases.
Example usage:
// In your frame loop:
CpuProfiler.beginFrame()
// Mark different phases
CpuProfiler.markPhase("Physics")
doPhysics()
CpuProfiler.markPhase("Rendering")
doRendering()
CpuProfiler.endFrame()
// Or use the convenience wrapper:
CpuProfiler.trace("MyOperation") {
  // code to profile
}
// For maximum performance with pre-registered phases:
CpuProfiler.markPhase(CpuProfiler.PHASE_UPDATE)
doUpdate()
CpuProfiler.markPhase(CpuProfiler.PHASE_RENDER)
doRender()

Signature

object CpuProfiler

Properties

nativeEnabled : Boolean
[Get][Set]
Whether the native CPU profiler is available.
Set to true by registerCpuProfiler (in JavaAPIs_CpuProfiler.cpp) only when the runtime is built with AETHER_IMGUI_ENABLE. When false, all public APIs on this object are no-ops and MUST NOT invoke any of the native* methods (they are not registered with the JVM and would throw UnsatisfiedLinkError).
Signature
var nativeEnabled: Boolean
PHASE_ANIMATION : Int
[Get]
Pre-registered phase ID for animation updates.
Signature
const val PHASE_ANIMATION: Int = 4
PHASE_AUDIO : Int
[Get]
Pre-registered phase ID for audio processing.
Signature
const val PHASE_AUDIO: Int = 3
PHASE_INPUT : Int
[Get]
Pre-registered phase ID for input handling.
Signature
const val PHASE_INPUT: Int = 5
PHASE_NETWORK : Int
[Get]
Pre-registered phase ID for network operations.
Signature
const val PHASE_NETWORK: Int = 6
PHASE_PHYSICS : Int
[Get]
Pre-registered phase ID for physics simulation.
Signature
const val PHASE_PHYSICS: Int = 2
PHASE_RENDER : Int
[Get]
Pre-registered phase ID for the render phase.
Signature
const val PHASE_RENDER: Int = 1
PHASE_SYSTEMS : Int
[Get]
Pre-registered phase ID for ECS system execution.
Signature
const val PHASE_SYSTEMS: Int = 7
PHASE_UPDATE : Int
[Get]
Pre-registered phase ID for the update phase.
Signature
const val PHASE_UPDATE: Int = 0

Methods

beginFrame ()
Begin a new profiling frame.
This is a convenience wrapper around CpuProfiler.nativeBeginFrame. No-op when CpuProfiler.nativeEnabled is false.
Signature
fun beginFrame()
endFrame ()
End the current profiling frame.
This is a convenience wrapper around CpuProfiler.nativeEndFrame. No-op when CpuProfiler.nativeEnabled is false.
Signature
fun endFrame()
markPhase ( name )
Mark the end of a phase using a string name.
This is a convenience wrapper around CpuProfiler.nativeMarkPhase. No-op when CpuProfiler.nativeEnabled is false.
Signature
fun markPhase(name: String)
Parameters
name: String  The name of the phase that just completed.
markPhase ( phaseId )
Mark the end of a phase using a pre-registered phase ID (fastest).
This is a convenience wrapper around CpuProfiler.nativeMarkPhaseById. Use the PHASE_* constants for maximum performance. No-op when CpuProfiler.nativeEnabled is false.
Signature
fun markPhase(phaseId: Int)
Parameters
phaseId: Int  The pre-registered phase ID (use PHASE_* constants).
nativeBeginFrame ()
Begin a new profiling frame. Call this at the start of your frame loop.
This resets the phase tracking and starts timing for the new frame.
Uses @CriticalNative for minimal JNI overhead (no JNIEnv/jclass transition).
Signature
external fun nativeBeginFrame()
nativeEndFrame ()
End the current profiling frame. Call this at the end of your frame loop.
This records the total frame time and stores the frame data in the history buffer for visualization in the ImGui debug window.
Uses @CriticalNative for minimal JNI overhead (no JNIEnv/jclass transition).
Signature
external fun nativeEndFrame()
nativeMarkPhase ( name )
Mark the end of a phase and the beginning of a new one using a string name.
The time since the last markPhase (or beginFrame) call is recorded for the named phase.
Uses @FastNative for reduced JNI overhead while still allowing object parameters.
Signature
external fun nativeMarkPhase(name: String)
Parameters
name: String  The name of the phase that just completed.
nativeMarkPhaseById ( phaseId )
Mark the end of a phase using a pre-registered phase ID (fastest).
This is the most performant way to mark phases as it avoids string handling entirely. Use the PHASE_* constants defined in this class.
Uses @CriticalNative for minimal JNI overhead (no JNIEnv/jclass transition).
Signature
external fun nativeMarkPhaseById(phaseId: Int)
Parameters
phaseId: Int  The pre-registered phase ID (use PHASE_* constants).
trace ( sectionName , block )
Profile a block of code as a named section.
This marks the phase at the start and records the duration. Unlike TraceUtils which integrates with Android's systrace/Perfetto, this integrates with the ImGui CPU Profiler debug window.
The native phase mark is skipped when CpuProfiler.nativeEnabled is false; the block is always executed.
CpuProfiler.trace("MyOperation") {
  // code to profile
}

Signature
inline fun <T> trace(sectionName: String, block: () -> T): T
Parameters
sectionName: String  The name of the section being profiled.
block: Function0  The block of code to profile.
Returns
CpuProfiler  The result of the block.
trace ( phaseId , block )
Profile a block of code using a pre-registered phase ID (fastest).
This is the most performant way to profile code sections as it avoids string handling entirely. The native phase mark is skipped when CpuProfiler.nativeEnabled is false; the block is always executed.
CpuProfiler.trace(CpuProfiler.PHASE_UPDATE) {
  // code to profile
}

Signature
inline fun <T> trace(phaseId: Int, block: () -> T): T
Parameters
phaseId: Int  The pre-registered phase ID (use PHASE_* constants).
block: Function0  The block of code to profile.
Returns
CpuProfiler  The result of the block.