Package com.jalios.jcms.tools
Class Profiler
- java.lang.Object
-
- com.jalios.jcms.tools.Profiler
-
public class Profiler extends java.lang.Object
Allow one to profile performance in JCMS.
While admin:- 1. create a new profiler session :
Profiler profiler = Profiler.getProfiler("test1", true);
- 2. enable measure recording :
profiler.startProfiling();
- 3. Retrieve the already created profiler
Profiler profiler = Profiler.getProfiler("test1", false);
- 4. Retrieve the RequestProfiler for the current request
Profiler.RequestProfiler rprofiler = profiler.getRequestProfiler(request);
- 5. Start measures for this request
rprofiler.startMeasures();
it will force a full garbage collection, waiting for some time, so be sure not to profile on production systems! - 6. Add individual measures
rprofiler.startMeasures("something"); doSomething(...); rprofiler.endMeasures("something");
- 7. End measures for this request
rprofile.endMeasures();
- 8. End measures recording:
profiler.endProfiling();
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
- 1. create a new profiler session :
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Profiler.RequestProfiler
Store measures for a given request
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addMeasuredId(java.lang.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 java.util.Collection<Profiler>
getAllProfilers()
long
getAverageConsumedMemory()
long
getAverageElapsedTime()
java.util.HashMap<java.lang.String,long[]>
getAverageMeasuresMap()
long
getAverageOutputSize()
java.util.Date
getEndDate()
java.lang.String
getName()
long
getProfiledRequestNumber()
static Profiler
getProfiler(java.lang.String name, boolean create)
Return an existing Profiler with the namename
, or null if it does not existProfiler.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.java.util.TreeMap<java.lang.String,long[]>
getSortedAverageMeasuresMap()
java.util.Date
getStartDate()
boolean
isProfiling()
static void
removeAllProfiler()
Remove all profilers currently availables.static void
removeProfiler(java.lang.String name)
Remove the profiler named "name".void
startProfiling()
Start profiling (clean older result if existing)
-
-
-
Method Detail
-
getProfiler
public static Profiler getProfiler(java.lang.String name, boolean create)
Return an existing Profiler with the namename
, or null if it does not exist- Parameters:
name
- the name of the profiler to retrievecreate
- 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 java.util.Collection<Profiler> getAllProfilers()
- Returns:
- a collection containing all profilers currently available.
-
removeProfiler
public static void removeProfiler(java.lang.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 java.lang.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(java.lang.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 java.util.HashMap<java.lang.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 java.util.Date getStartDate()
- Returns:
- the Date on which the profiling was started.
-
getEndDate
public java.util.Date getEndDate()
- Returns:
- the Date on which the profiling was ended.
-
getSortedAverageMeasuresMap
public java.util.TreeMap<java.lang.String,long[]> getSortedAverageMeasuresMap()
- Returns:
- the TreeMap (id ==> long[3] {averageConsumedMemory, averagedTimeElapsed, averageOutputSize }) sorted from slowest to fastest.
-
-