com.threerings.util
Class MethodProfiler

java.lang.Object
  extended by com.threerings.util.MethodProfiler

public class MethodProfiler
extends Object

Records the times that it takes to call methods. Allows one simultaneous method call per thread (no nested calls). Uses java's nano second timer. Results are logged by method name.


Nested Class Summary
static class MethodProfiler.Result
          The results of sampling for a single method.
 
Constructor Summary
MethodProfiler()
           
 
Method Summary
 void enter(String methodName)
          Notes that the calling thread has entered the given method and records the time stamp.
 void exit(String methodName)
          Notes that the calling thread has exited the given method and records the time delta since entry.
 void exitAndClear(String methodName)
          Clears out the profile for the current thread, and invokes the exit of the top-level method.
 Map<String,MethodProfiler.Result> getResults()
          Gets all method results so far.
static void main(String[] args)
          Runs some very basic tests of the method profiler.
 void reset()
          Clears all recorded methods and times.
 void swap(String methodName)
          Transition to a new method or segment.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodProfiler

public MethodProfiler()
Method Detail

main

public static void main(String[] args)
                 throws InterruptedException
Runs some very basic tests of the method profiler.

Throws:
InterruptedException

getResults

public Map<String,MethodProfiler.Result> getResults()
Gets all method results so far.


enter

public void enter(String methodName)
Notes that the calling thread has entered the given method and records the time stamp.


exit

public void exit(String methodName)
Notes that the calling thread has exited the given method and records the time delta since entry. The method parameter is not strictly necessary but allows some error checking. If not null, it must match the most recent value given to enter(java.lang.String) for the calling thread.


swap

public void swap(String methodName)
Transition to a new method or segment. Exits the current one and enters the given one.


exitAndClear

public void exitAndClear(String methodName)
Clears out the profile for the current thread, and invokes the exit of the top-level method. This allows callers to use one try... finally block in their top-level method without skewing the results for nested methods that may have thrown exceptions and/or not called exit(java.lang.String).


reset

public void reset()
Clears all recorded methods and times.



Copyright © 2012. All Rights Reserved.