APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class PerformanceCounter

extends Object
Class Inheritance
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.math.FloatCounter, .MathUtils

Class to keep track of the time and load (percentage of total time) a specific task takes. Call start() just before starting the task and stop() right after. You can do this multiple times if required. Every render or update call tick() to update the values. The time FloatCounter provides access to the minimum, maximum, average, total and current time (in seconds) the task takes. Likewise for the load value, which is the percentage of the total time.
Author
xoppa

Field Summary

Modifier and TypeField and Description
public float
current

The current value in seconds, you can manually increase this using your own timing mechanism if needed, if you do so, you also need to update valid.

private long
public final FloatCounter
load

The load value of this counter

public final String
name

The name of this counter

private static final float
private long
public final FloatCounter
time

The time value of this counter (seconds)

public boolean
valid

Flag to indicate that the current value is valid, you need to set this to true if using your own timing mechanism

Constructor Summary

AccessConstructor and Description
public
public
PerformanceCounter(final String name, final int windowSize)

Method Summary

Modifier and TypeMethod and Description
public void
reset()

Resets this performance counter to its defaults values.

public void
start()

Start counting, call this method just before performing the task you want to keep track of.

public void
stop()

Stop counting, call this method right after you performed the task you want to keep track of.

public void
tick()

Updates the time and load counters and resets the time.

public void
tick(final float
The time since the last call to this method
delta
)

Updates the time and load counters and resets the time.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public StringBuilder
toString(final StringBuilder sb)

Creates a string in the form of "name [time: value, load: value]"

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

currentback to summary
public float current

The current value in seconds, you can manually increase this using your own timing mechanism if needed, if you do so, you also need to update valid.

lastTickback to summary
private long lastTick
loadback to summary
public final FloatCounter load

The load value of this counter

nameback to summary
public final String name

The name of this counter

nano2secondsback to summary
private static final float nano2seconds
startTimeback to summary
private long startTime
timeback to summary
public final FloatCounter time

The time value of this counter (seconds)

validback to summary
public boolean valid

Flag to indicate that the current value is valid, you need to set this to true if using your own timing mechanism

Constructor Detail

PerformanceCounterback to summary
public PerformanceCounter(final String name)
PerformanceCounterback to summary
public PerformanceCounter(final String name, final int windowSize)

Method Detail

resetback to summary
public void reset()

Resets this performance counter to its defaults values.

startback to summary
public void start()

Start counting, call this method just before performing the task you want to keep track of. Call stop() when done.

stopback to summary
public void stop()

Stop counting, call this method right after you performed the task you want to keep track of. Call start() again when you perform more of that task.

tickback to summary
public void tick()

Updates the time and load counters and resets the time. Call start() to begin a new count. The values are only valid after at least two calls to this method.

tickback to summary
public void tick(final float delta)

Updates the time and load counters and resets the time. Call start() to begin a new count.

Parameters
delta:float

The time since the last call to this method

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
toStringback to summary
public StringBuilder toString(final StringBuilder sb)

Creates a string in the form of "name [time: value, load: value]"