com.jme.util.stat
Class StatCollector

java.lang.Object
  extended by com.jme.util.stat.StatCollector

public class StatCollector
extends java.lang.Object

This class acts as a centralized data store for statistics. As data is added to the collector, a sum total is kept as well as the total number of data samples given for the particular stat.

Author:
Joshua Slack

Field Summary
protected static java.util.HashMap<StatType,StatValue> current
          Our map of current stat values.
protected static java.util.List<MultiStatSample> historical
           
protected static boolean ignoreStats
           
protected static double lastSampleTime
           
protected static double lastTimeCheckMS
           
protected static java.util.ArrayList<java.lang.ref.WeakReference<StatListener>> listeners
           
protected static int maxSamples
          How many distinct past aggregate samples are kept before the oldest one is dropped on add.
protected static double sampleRateMS
          How long to gather stats as a single unit before pushing them onto the historical stack.
protected static double startOffset
           
protected static java.util.HashSet<StatType> timedStats
           
protected static NanoTimer timer
           
protected static java.util.Stack<StatType> timeStatStack
           
 
Constructor Summary
protected StatCollector()
           
 
Method Summary
static void addStat(StatType type, double statValue)
           
static void addStatListener(StatListener listener)
          Add a listener to the pool of listeners that are notified when a new stats aggregate is created (at the end of each time sample).
static void addTimedStat(StatType type)
          Add a type to the set of stat types that are paid attention to when doing timed stat checking.
static void endStat(StatType type)
           
static void fireActionEvent()
          Notifies all registered listeners that a new stats aggregate was created.
static java.util.List<MultiStatSample> getHistorical()
           
static int getMaxSamples()
           
static double getSampleRate()
           
static double getStartOffset()
           
static boolean hasHistoricalStat(StatType type)
           
static void init(long sampleRateMS, int maxHistorical)
          Construct a new StatCollector.
static boolean isIgnoreStats()
           
static void pause()
          TODO: consider a way to pause just a set of stats?
static void removeAllListeners()
          Cleans the listener pool of all listeners.
static void removeAllTimedStats()
          Cleans the set of stat types we paid attention to when doing timed stat checking.
static boolean removeStatListener(StatListener listener)
          Removes a listener from the pool of listeners that are notified when a new stats aggregate is created (at the end of each time sample).
static boolean removeTimedStat(StatType type)
          Removes a type from the set of stat types that are paid attention to when doing timed stat checking.
static void resetTimedStack()
          Call this if you've caught an error, etc and you need to reset timed stats collecting.
static void resume()
           
static void setIgnoreStats(boolean ignoreStats)
           
static void setMaxSamples(int samples)
           
static void setSampleRate(long sampleRateMS)
           
static void startStat(StatType type)
           
static void update()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxSamples

protected static int maxSamples
How many distinct past aggregate samples are kept before the oldest one is dropped on add. You can multiply this by the time sample rate to determine the total history length in time.


current

protected static java.util.HashMap<StatType,StatValue> current
Our map of current stat values. Current means values that have been collected within the current time sample. For example, if sampleRate = 1.0, then current will hold values collected since the last 1 second ping.


historical

protected static java.util.List<MultiStatSample> historical

sampleRateMS

protected static double sampleRateMS
How long to gather stats as a single unit before pushing them onto the historical stack.


lastSampleTime

protected static double lastSampleTime

lastTimeCheckMS

protected static double lastTimeCheckMS

listeners

protected static java.util.ArrayList<java.lang.ref.WeakReference<StatListener>> listeners

startOffset

protected static double startOffset

ignoreStats

protected static boolean ignoreStats

timeStatStack

protected static java.util.Stack<StatType> timeStatStack

timedStats

protected static java.util.HashSet<StatType> timedStats

timer

protected static NanoTimer timer
Constructor Detail

StatCollector

protected StatCollector()
Method Detail

init

public static void init(long sampleRateMS,
                        int maxHistorical)
Construct a new StatCollector.

Parameters:
sampleRateMS - The amount of time between aggregated samples in milliseconds.

addStat

public static void addStat(StatType type,
                           double statValue)

startStat

public static void startStat(StatType type)

endStat

public static void endStat(StatType type)

update

public static void update()

addStatListener

public static void addStatListener(StatListener listener)
Add a listener to the pool of listeners that are notified when a new stats aggregate is created (at the end of each time sample).

Parameters:
listener - the listener to add

removeStatListener

public static boolean removeStatListener(StatListener listener)
Removes a listener from the pool of listeners that are notified when a new stats aggregate is created (at the end of each time sample).

Parameters:
listener - the listener to remove

removeAllListeners

public static void removeAllListeners()
Cleans the listener pool of all listeners.


addTimedStat

public static void addTimedStat(StatType type)
Add a type to the set of stat types that are paid attention to when doing timed stat checking.

Parameters:
type - the listener to add

removeTimedStat

public static boolean removeTimedStat(StatType type)
Removes a type from the set of stat types that are paid attention to when doing timed stat checking.

Parameters:
type - the listener to remove

removeAllTimedStats

public static void removeAllTimedStats()
Cleans the set of stat types we paid attention to when doing timed stat checking.


fireActionEvent

public static void fireActionEvent()
Notifies all registered listeners that a new stats aggregate was created.


getStartOffset

public static double getStartOffset()

getSampleRate

public static double getSampleRate()

setSampleRate

public static void setSampleRate(long sampleRateMS)

setMaxSamples

public static void setMaxSamples(int samples)

getMaxSamples

public static int getMaxSamples()

getHistorical

public static java.util.List<MultiStatSample> getHistorical()

isIgnoreStats

public static boolean isIgnoreStats()

setIgnoreStats

public static void setIgnoreStats(boolean ignoreStats)

hasHistoricalStat

public static boolean hasHistoricalStat(StatType type)

resetTimedStack

public static void resetTimedStack()
Call this if you've caught an error, etc and you need to reset timed stats collecting. NOTE: You must ensure you are not inside a START/END timed block, (or you recreate any necessary start calls) otherwise when endStat is called a stack exception will occur.


pause

public static void pause()
TODO: consider a way to pause just a set of stats?


resume

public static void resume()