com.jalios.jcms.tools
Class Profiler

java.lang.Object
  extended by com.jalios.jcms.tools.Profiler

public class Profiler
extends Object

Allow one to profile performance in JCMS.

While admin:


Then for each request:
      rprofiler.startMeasures("something");
      doSomething(...);
      rprofiler.endMeasures("something");
    

While admin:
In the end, retrieve the measure and work with them.

Note: this API is NOT thread safe, as doing memory measures simultaneously on different thread is not possible.

Since:
jcms-5.5.0
Author:
Olivier Jaquemet

Nested Class Summary
 class Profiler.RequestProfiler
          Store measures for a given request
 
Method Summary
protected  void addMeasuredId(String id)
          Method called by request profiler to add measured id;
protected  void computeAverage()
           
 void endProfiling()
          End profiling and compute average of RequestProfiler measures.
static Collection<Profiler> getAllProfilers()
           
 long getAverageConsumedMemory()
           
 long getAverageElapsedTime()
           
 HashMap<String,long[]> getAverageMeasuresMap()
           
 long getAverageOutputSize()
           
 Date getEndDate()
           
 String getName()
           
 long getProfiledRequestNumber()
           
static Profiler getProfiler(String name, boolean create)
          Return an existing Profiler with the name name, or null if it does not exist
 Profiler.RequestProfiler getRequestProfiler(javax.servlet.http.HttpServletRequest request)
          Return the request profiler associated with the given request and create a new one if none is available.
 TreeMap<String,long[]> getSortedAverageMeasuresMap()
           
 Date getStartDate()
           
 boolean isProfiling()
           
static void removeAllProfiler()
          Remove all profilers currently availables.
static void removeProfiler(String name)
          Remove the profiler named "name".
 void startProfiling()
          Start profiling (clean older result if existing)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getProfiler

public static Profiler getProfiler(String name,
                                   boolean create)
Return an existing Profiler with the name name, or null if it does not exist

Parameters:
name - the name of the profiler to retrieve
create - if true, will create the profiler if it does not exist (be sure to create only when admin)
Returns:
the Profiler or null if does not exist

getAllProfilers

public static Collection<Profiler> getAllProfilers()
Returns:
a collection containing all profilers currently available.

removeProfiler

public static void removeProfiler(String name)
Remove the profiler named "name".

Parameters:
name - the name of the profiler to remove

removeAllProfiler

public static void removeAllProfiler()
Remove all profilers currently availables.


getName

public String getName()

startProfiling

public void startProfiling()
Start profiling (clean older result if existing)


endProfiling

public void endProfiling()
End profiling and compute average of RequestProfiler measures.


isProfiling

public boolean isProfiling()

addMeasuredId

protected void addMeasuredId(String id)
Method called by request profiler to add measured id;


computeAverage

protected void computeAverage()

getRequestProfiler

public Profiler.RequestProfiler getRequestProfiler(javax.servlet.http.HttpServletRequest request)
Return the request profiler associated with the given request and create a new one if none is available.

Parameters:
request - the request of which to find RequestProfiler
Returns:
a RequestProfiler

getAverageConsumedMemory

public long getAverageConsumedMemory()
Returns:
the total average memory used between call to startMeasures() and endMeasures() of each request

getAverageElapsedTime

public long getAverageElapsedTime()
Returns:
the total average time elapsed between call to startMeasures() and endMeasures() of each request

getAverageOutputSize

public long getAverageOutputSize()
Returns:
the total average output size between call to startMeasures() and endMeasures() of each request

getAverageMeasuresMap

public HashMap<String,long[]> getAverageMeasuresMap()
Returns:
the HashMap (id ==> long[3] {averageConsumedMemory, averagedTimeElapsed, averageOutputSize})

getProfiledRequestNumber

public long getProfiledRequestNumber()
Returns:
the total number of request that have been used to do this profiling.

getStartDate

public Date getStartDate()
Returns:
the Date on which the profiling was started.

getEndDate

public Date getEndDate()
Returns:
the Date on which the profiling was ended.

getSortedAverageMeasuresMap

public TreeMap<String,long[]> getSortedAverageMeasuresMap()
Returns:
the TreeMap (id ==> long[3] {averageConsumedMemory, averagedTimeElapsed, averageOutputSize }) sorted from slowest to fastest.


Copyright © 2001-2010 Jalios SA. All Rights Reserved.