com.threerings.media.util
Class PerformanceMonitor

java.lang.Object
  extended by com.threerings.media.util.PerformanceMonitor

public class PerformanceMonitor
extends Object

Provides a simple mechanism for monitoring the number of times an action takes place within a certain time period.

The action being tracked should be registered with a suitable name via register(com.threerings.media.util.PerformanceObserver, java.lang.String, long), and tick(com.threerings.media.util.PerformanceObserver, java.lang.String) should be called each time the action is performed.

Whenever tick(com.threerings.media.util.PerformanceObserver, java.lang.String) is called and the checkpoint time interval has elapsed since the last checkpoint (if any), the observer will be notified to that effect by a call to PerformanceObserver.checkpoint(java.lang.String, int).

Note that this is not intended to be used as an industrial-strength profiling or performance monitoring tool. The checkpoint time interval granularity is in milliseconds, not microseconds, and the observer's checkpoint() method will never be called until/unless a subsequent call to tick(com.threerings.media.util.PerformanceObserver, java.lang.String) is made after the requested number of milliseconds have passed since the last checkpoint.


Field Summary
protected static Map<PerformanceObserver,Map<String,com.threerings.media.util.PerformanceAction>> _observers
          The observers monitoring some set of actions.
protected static MediaTimer _timer
          Used to obtain high resolution time stamps.
 
Constructor Summary
PerformanceMonitor()
           
 
Method Summary
protected static long getTimeStamp()
          Used by the performance actions.
static void register(PerformanceObserver obs, String name, long delta)
          Register a new action with an observer, the action name, and the milliseconds to wait between checkpointing the action's performance.
static void setMediaTimer(MediaTimer timer)
          Used to configure the performance monitor with a particular MediaTimer implementation.
static void tick(PerformanceObserver obs, String name)
          Tick the named action associated with the given observer.
static void unregister(PerformanceObserver obs, String name)
          Un-register the named action associated with the given observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_observers

protected static Map<PerformanceObserver,Map<String,com.threerings.media.util.PerformanceAction>> _observers
The observers monitoring some set of actions.


_timer

protected static MediaTimer _timer
Used to obtain high resolution time stamps.

Constructor Detail

PerformanceMonitor

public PerformanceMonitor()
Method Detail

register

public static void register(PerformanceObserver obs,
                            String name,
                            long delta)
Register a new action with an observer, the action name, and the milliseconds to wait between checkpointing the action's performance.

Parameters:
obs - the action observer.
name - the action name.
delta - the milliseconds between checkpoints.

unregister

public static void unregister(PerformanceObserver obs,
                              String name)
Un-register the named action associated with the given observer.

Parameters:
obs - the action observer.
name - the action name.

tick

public static void tick(PerformanceObserver obs,
                        String name)
Tick the named action associated with the given observer.

Parameters:
obs - the action observer.
name - the action name.

setMediaTimer

public static void setMediaTimer(MediaTimer timer)
Used to configure the performance monitor with a particular MediaTimer implementation. By default it uses a pure-Java implementation which isn't extremely accurate across platforms.


getTimeStamp

protected static long getTimeStamp()
Used by the performance actions.