Package com.jalios.jcms.tools
Class Profiler
java.lang.Object
com.jalios.jcms.tools.Profiler
Allow one to profile performance in JCMS.
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.
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassStore measures for a given request -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddMeasuredId(String id) Method called by request profiler to add measured id;protected voidvoidEnd profiling and compute average of RequestProfiler measures.static Collection<Profiler> longlonglonggetName()longstatic ProfilergetProfiler(String name, boolean create) Return an existing Profiler with the namename, or null if it does not existgetRequestProfiler(javax.servlet.http.HttpServletRequest request) Return the request profiler associated with the given request and create a new one if none is available.booleanstatic voidRemove all profilers currently availables.static voidremoveProfiler(String name) Remove the profiler named "name".voidStart profiling (clean older result if existing)
-
Method Details
-
getProfiler
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
- Returns:
- a collection containing all profilers currently available.
-
removeProfiler
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
-
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
Method called by request profiler to add measured id; -
computeAverage
protected void computeAverage() -
getRequestProfiler
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
- 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
- Returns:
- the Date on which the profiling was started.
-
getEndDate
- Returns:
- the Date on which the profiling was ended.
-
getSortedAverageMeasuresMap
- Returns:
- the TreeMap (id ==> long[3] {averageConsumedMemory, averagedTimeElapsed, averageOutputSize }) sorted from slowest to fastest.
-