Class AnimationBenchmark.TrackedAnimation
- java.lang.Object
-
- ej.mwt.animation.AnimationBenchmark.TrackedAnimation
-
- All Implemented Interfaces:
Animation
- Enclosing class:
- AnimationBenchmark
public static class AnimationBenchmark.TrackedAnimation extends java.lang.Object implements Animation
AnAnimationdecorator that records timing data for benchmarking.Each call to
tick(long)appends the platform time to an internal list of timestamps. After the animation completes (i.e., aftertick(long)returnsfalse), this data is available viagetTimestamps(),getFrameTimes(),getAverageFps(),getDuration(),getMaxFrameTime(), andgetDroppedFramesCount(long).Instance is automatically returned by
AnimationBenchmark.wait(String, long)when it stops. The result methods listed above are only guaranteed to reflect a fully consistent state after a correspondingAnimationBenchmark.wait(String, long)call has returned for labeled animations.
-
-
Constructor Summary
Constructors Constructor Description TrackedAnimation(Animation delegate, java.lang.String label)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetAverageFps()Returns the average frame rate of this animation over its entire duration.intgetDroppedFramesCount(long threshold)Returns the number of frames whose inter-frame duration was greater than or equal to the given threshold.longgetDuration()Returns the total duration of this animation in milliseconds.long[]getFrameTimes()Returns the list of inter-frame durations for this animation, in milliseconds.java.lang.StringgetLabel()Returns the label associated with this animation.longgetMaxFrameTime()Returns the maximum inter-frame duration recorded for this animation, in milliseconds.long[]getTimestamps()Returns a copy of the tick timestamps recorded for this animation.booleantick(long platformTimeMillis)Called by the animator to step this animation.
-
-
-
Constructor Detail
-
TrackedAnimation
public TrackedAnimation(Animation delegate, java.lang.String label)
-
-
Method Detail
-
getLabel
public java.lang.String getLabel()
Returns the label associated with this animation.- Returns:
- the label
-
getAverageFps
public float getAverageFps()
Returns the average frame rate of this animation over its entire duration.- Returns:
- the average frames per second
-
getTimestamps
public long[] getTimestamps()
Returns a copy of the tick timestamps recorded for this animation.Each value is a platform time in milliseconds as returned by
Util.platformTimeMillis(). The first entry is the time of the first tick; the last entry is the time of the final tick. The list is empty if the animation has not started yet.- Returns:
- a snapshot of the tick timestamps, in chronological order
-
getFrameTimes
public long[] getFrameTimes()
Returns the list of inter-frame durations for this animation, in milliseconds.The i-th element is the elapsed time between the i-th and (i+1)-th tick. This list therefore has one fewer entry than
getTimestamps(). Returns an empty list if fewer than two ticks were recorded.- Returns:
- the array of inter-frame durations, in milliseconds
-
getMaxFrameTime
public long getMaxFrameTime()
Returns the maximum inter-frame duration recorded for this animation, in milliseconds.A high value indicates that the renderer stalled on that frame. Returns
0if fewer than two ticks were recorded.- Returns:
- the maximum inter-frame duration in milliseconds, or
0if not enough ticks were recorded
-
getDroppedFramesCount
public int getDroppedFramesCount(long threshold)
Returns the number of frames whose inter-frame duration was greater than or equal to the given threshold.A frame is considered dropped when its duration meets or exceeds
threshold: the renderer took so long that a visible stall occurred. A common threshold is twice the expected frame budget — for example, 80ms for a 25 fps target (2 × 40ms).- Parameters:
threshold- the minimum inter-frame duration in milliseconds to consider a frame as dropped; must be positive- Returns:
- the number of frames whose duration is >=
threshold
-
getDuration
public long getDuration()
Returns the total duration of this animation in milliseconds.Computed as the elapsed time between the first and last tick. Returns
0if fewer than two ticks were recorded (e.g., the animation completed in a single tick).- Returns:
- the animation duration in milliseconds, or
0if not enough ticks were recorded
-
tick
public boolean tick(long platformTimeMillis)
Called by the animator to step this animation.Records the start time on the first call and delegates to the wrapped animation. When the wrapped animation stops, records the stop time, links this instance to the associated lock, and notifies any thread blocked in
AnimationBenchmark.wait(String, long).
-
-