gate.util.profile
Class Profiler

java.lang.Object
  extended bygate.util.profile.Profiler

public class Profiler
extends Object


Field Summary
private  Hashtable m_categoryLasts
           
private  Hashtable m_categorySums
           
private  long m_currMemory
           
private  long m_diffMemory
           
private  boolean m_doPrintToStdOut
          Indicates whether just to return the string dumps (false) or also print them to the std out (true)
private  boolean m_enabled
           
private  boolean m_garbageCollection
           
private  long m_lastCheckTime
           
private  long m_lastDuration
           
private  long m_maxMemory
           
private  PrintStream m_out
           
private  long m_profilerTime
           
private  Runtime m_rt
           
private  long m_startTime
           
 
Constructor Summary
Profiler()
           
 
Method Summary
private  void checkCategories(String[] categs)
           
 String checkPoint(String execPointDescr)
          To be called at all execution points of interest.
 String checkPoint(String execPointDescr, String[] categories, boolean showDescr, boolean showStats, boolean memoryCheck)
          In addition to the variant of the method with two parameters allows: a set of categories (identified by strings) to which the preceeding fragment of code belongs; flag determining whether the description of the execution point to be displayed; flag determining whether the statistics to be shown
 void enable(boolean isEnabled)
          Switches the profiler ON and OFF.
 void enableGCCalling(boolean collect)
          Tell's the profiler whether to call the garbage collector when detecting memory usage or not.
 long getCategoryTimeLast(String category)
          Returns 0 if the category was not found
 long getCategoryTimeSum(String category)
          Returns 0 if the category was not found
 long getNetRunTime()
          Returns the time spend in the last run without the time spend by the profiler.
 long getProfilerTime()
          Returns the time spend by the profiler during the last run.
 long getRunDuration()
          Returns the time spend in the current run until the last check-point inclusive the time spend by the profiler.
 String initRun(String runDescription)
          Inialises the profiler for a new run
 boolean isEnabled()
          Answers is the profiler switched ON or OFF.
 boolean isGCCallingEnabled()
           
 void printCategAvg(String categ, long items, double volume, String whateverMeasure)
          An auxiliary routine printing time, avg. time, and avg. speed for a category
 String printSpeed(long timeMillis, double whatever, String whateverMeasure)
          An auxiliary routine printing in a string speed
 String printTime(long timeMillis)
          An auxiliary routine printing time in "nnn.nns" format
 void printToSystemOut(boolean doPrint)
          Sets the profiler to print (or not) to the standard output.
 void showCategoryTime(String categ)
          Prints the time for certain category of activities
 void showCategoryTimes()
          Prints the time for all the categories of activities
private  String showResults(String execPointDescr, boolean showDescr, boolean showStats)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_out

private PrintStream m_out

m_enabled

private boolean m_enabled

m_garbageCollection

private boolean m_garbageCollection

m_doPrintToStdOut

private boolean m_doPrintToStdOut
Indicates whether just to return the string dumps (false) or also print them to the std out (true)


m_categorySums

private Hashtable m_categorySums

m_categoryLasts

private Hashtable m_categoryLasts

m_rt

private Runtime m_rt

m_startTime

private long m_startTime

m_lastCheckTime

private long m_lastCheckTime

m_profilerTime

private long m_profilerTime

m_lastDuration

private long m_lastDuration

m_maxMemory

private long m_maxMemory

m_currMemory

private long m_currMemory

m_diffMemory

private long m_diffMemory
Constructor Detail

Profiler

public Profiler()
Method Detail

enable

public void enable(boolean isEnabled)
Switches the profiler ON and OFF. When OFF all the methods do nothing


isEnabled

public boolean isEnabled()
Answers is the profiler switched ON or OFF. When OFF all the methods do nothing


enableGCCalling

public void enableGCCalling(boolean collect)
Tell's the profiler whether to call the garbage collector when detecting memory usage or not. If switched ON the GC is called following a specific strategy as many time as needed so to collect all the memory that can be collected. This makes the profiling slower and also does not correctly account for the really memory usage of the applicaton when run without the profiler. On the other hand, with garbage collection, it is easier to detecet the amount of memory really necessary for the application.


isGCCallingEnabled

public boolean isGCCallingEnabled()
See Also:
enableGCCalling(boolean)

getProfilerTime

public long getProfilerTime()
Returns the time spend by the profiler during the last run. It is the case that net_run_time = run_duration - profiler_time


getNetRunTime

public long getNetRunTime()
Returns the time spend in the last run without the time spend by the profiler. It is the case that net_run_time = run_duration - profiler_time


getRunDuration

public long getRunDuration()
Returns the time spend in the current run until the last check-point inclusive the time spend by the profiler. It is the case that net_run_time = run_duration - profiler_time


initRun

public String initRun(String runDescription)
Inialises the profiler for a new run


checkPoint

public String checkPoint(String execPointDescr)
To be called at all execution points of interest. Detects the time and memory usage in absolute terms as well as compared to the previous execution point


checkPoint

public String checkPoint(String execPointDescr,
                         String[] categories,
                         boolean showDescr,
                         boolean showStats,
                         boolean memoryCheck)
In addition to the variant of the method with two parameters allows: a set of categories (identified by strings) to which the preceeding fragment of code belongs; flag determining whether the description of the execution point to be displayed; flag determining whether the statistics to be shown


checkCategories

private void checkCategories(String[] categs)

showResults

private String showResults(String execPointDescr,
                           boolean showDescr,
                           boolean showStats)

getCategoryTimeSum

public long getCategoryTimeSum(String category)
Returns 0 if the category was not found


getCategoryTimeLast

public long getCategoryTimeLast(String category)
Returns 0 if the category was not found


showCategoryTimes

public void showCategoryTimes()
Prints the time for all the categories of activities


showCategoryTime

public void showCategoryTime(String categ)
Prints the time for certain category of activities


printTime

public String printTime(long timeMillis)
An auxiliary routine printing time in "nnn.nns" format


printSpeed

public String printSpeed(long timeMillis,
                         double whatever,
                         String whateverMeasure)
An auxiliary routine printing in a string speed


printCategAvg

public void printCategAvg(String categ,
                          long items,
                          double volume,
                          String whateverMeasure)
An auxiliary routine printing time, avg. time, and avg. speed for a category


printToSystemOut

public void printToSystemOut(boolean doPrint)
Sets the profiler to print (or not) to the standard output. The default behaviour is - print to std out.

Parameters:
doPrint - whether or not to print to std out.