public class ProfilerTimerFilter extends IoFilterAdapter
IoFilterAdapter class to execute. The basic
premise of the logic in this class is to get the current time
at the beginning of the method, call method on nextFilter, and
then get the current time again. An example of how to use
the filter is:
ProfilerTimerFilter profiler = new ProfilerTimerFilter(
TimeUnit.MILLISECOND, IoEventType.MESSAGE_RECEIVED);
chain.addFirst("Profiler", profiler);
The profiled IoEventType are :
| Modifier and Type | Class and Description |
|---|---|
private class |
ProfilerTimerFilter.TimerWorker
Class that will track the time each method takes and be able to provide information
for each method.
|
IoFilter.NextFilter| Modifier and Type | Field and Description |
|---|---|
private ProfilerTimerFilter.TimerWorker |
messageReceivedTimerWorker
A TimerWorker for the MessageReceived events
|
private ProfilerTimerFilter.TimerWorker |
messageSentTimerWorker
A TimerWorker for the MessageSent events
|
private boolean |
profileMessageReceived
A flag to tell the filter that the MessageReceived must be profiled
|
private boolean |
profileMessageSent
A flag to tell the filter that the MessageSent must be profiled
|
private boolean |
profileSessionClosed
A flag to tell the filter that the SessionClosed must be profiled
|
private boolean |
profileSessionCreated
A flag to tell the filter that the SessionCreated must be profiled
|
private boolean |
profileSessionIdle
A flag to tell the filter that the SessionIdle must be profiled
|
private boolean |
profileSessionOpened
A flag to tell the filter that the SessionOpened must be profiled
|
private ProfilerTimerFilter.TimerWorker |
sessionClosedTimerWorker
A TimerWorker for the SessionClosed events
|
private ProfilerTimerFilter.TimerWorker |
sessionCreatedTimerWorker
A TimerWorker for the SessionCreated events
|
private ProfilerTimerFilter.TimerWorker |
sessionIdleTimerWorker
A TimerWorker for the SessionIdle events
|
private ProfilerTimerFilter.TimerWorker |
sessionOpenedTimerWorker
A TimerWorker for the SessionOpened events
|
private java.util.concurrent.TimeUnit |
timeUnit
TRhe selected time unit
|
| Constructor and Description |
|---|
ProfilerTimerFilter()
Creates a new instance of ProfilerFilter.
|
ProfilerTimerFilter(java.util.concurrent.TimeUnit timeUnit)
Creates a new instance of ProfilerFilter.
|
ProfilerTimerFilter(java.util.concurrent.TimeUnit timeUnit,
IoEventType... eventTypes)
Creates a new instance of ProfilerFilter.
|
| Modifier and Type | Method and Description |
|---|---|
double |
getAverageTime(IoEventType type)
Get the average time for the specified method represented by the
IoEventType |
java.util.Set<IoEventType> |
getEventsToProfile()
Return the set of
IoEventType which are profiled. |
long |
getMaximumTime(IoEventType type)
The maximum time the method represented by
IoEventType has executed |
long |
getMinimumTime(IoEventType type)
The minimum time the method represented by
IoEventType has executed |
long |
getTotalCalls(IoEventType type)
Gets the total number of times the method has been called that is represented by the
IoEventType |
long |
getTotalTime(IoEventType type)
The total time this method has been executing
|
void |
messageReceived(IoFilter.NextFilter nextFilter,
IoSession session,
java.lang.Object message)
Profile a MessageReceived event.
|
void |
messageSent(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Profile a MessageSent event.
|
void |
profile(IoEventType type)
Set the
IoEventType to be profiled |
void |
sessionClosed(IoFilter.NextFilter nextFilter,
IoSession session)
Profile a SessionClosed event.
|
void |
sessionCreated(IoFilter.NextFilter nextFilter,
IoSession session)
Profile a SessionCreated event.
|
void |
sessionIdle(IoFilter.NextFilter nextFilter,
IoSession session,
IdleStatus status)
Profile a SessionIdle event.
|
void |
sessionOpened(IoFilter.NextFilter nextFilter,
IoSession session)
Profile a SessionOpened event.
|
void |
setEventsToProfile(IoEventType... eventTypes)
Set the profilers for a list of
IoEventType |
private void |
setProfilers(IoEventType... eventTypes)
Create the profilers for a list of
IoEventType. |
void |
setTimeUnit(java.util.concurrent.TimeUnit timeUnit)
Sets the
TimeUnit being used. |
void |
stopProfile(IoEventType type)
Stop profiling an
IoEventType |
private long |
timeNow() |
destroy, exceptionCaught, filterClose, filterWrite, init, inputClosed, onPostAdd, onPostRemove, onPreAdd, onPreRemove, toStringprivate volatile java.util.concurrent.TimeUnit timeUnit
private ProfilerTimerFilter.TimerWorker messageReceivedTimerWorker
private boolean profileMessageReceived
private ProfilerTimerFilter.TimerWorker messageSentTimerWorker
private boolean profileMessageSent
private ProfilerTimerFilter.TimerWorker sessionCreatedTimerWorker
private boolean profileSessionCreated
private ProfilerTimerFilter.TimerWorker sessionOpenedTimerWorker
private boolean profileSessionOpened
private ProfilerTimerFilter.TimerWorker sessionIdleTimerWorker
private boolean profileSessionIdle
private ProfilerTimerFilter.TimerWorker sessionClosedTimerWorker
private boolean profileSessionClosed
public ProfilerTimerFilter()
public ProfilerTimerFilter(java.util.concurrent.TimeUnit timeUnit)
timeUnit - the time increment to setpublic ProfilerTimerFilter(java.util.concurrent.TimeUnit timeUnit,
IoEventType... eventTypes)
new ProfilerTimerFilter(
TimeUnit.MILLISECONDS,
IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT);
Note : you can add as many IoEventType as you want. The method accepts
a variable number of arguments.timeUnit - Used to determine the level of precision you need in your timing.eventTypes - A list of IoEventType representation of the methods to profileprivate void setProfilers(IoEventType... eventTypes)
IoEventType.eventTypes - the list of IoEventType to profilepublic void setTimeUnit(java.util.concurrent.TimeUnit timeUnit)
TimeUnit being used.timeUnit - the new TimeUnit to be used.public void profile(IoEventType type)
IoEventType to be profiledtype - The IoEventType to profilepublic void stopProfile(IoEventType type)
IoEventTypetype - The IoEventType to stop profilingpublic java.util.Set<IoEventType> getEventsToProfile()
IoEventType which are profiled.IoEventTypepublic void setEventsToProfile(IoEventType... eventTypes)
IoEventTypeeventTypes - the list of IoEventType to profilepublic void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message) throws java.lang.Exception
messageReceived in interface IoFiltermessageReceived in class IoFilterAdapternextFilter - The filter to call nextsession - The associated sessionmessage - the received messagejava.lang.Exceptionpublic void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws java.lang.Exception
messageSent in interface IoFiltermessageSent in class IoFilterAdapternextFilter - The filter to call nextsession - The associated sessionwriteRequest - the sent messagejava.lang.Exceptionpublic void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
sessionCreated in interface IoFiltersessionCreated in class IoFilterAdapternextFilter - The filter to call nextsession - The associated sessionjava.lang.Exceptionpublic void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
sessionOpened in interface IoFiltersessionOpened in class IoFilterAdapternextFilter - The filter to call nextsession - The associated sessionjava.lang.Exceptionpublic void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) throws java.lang.Exception
sessionIdle in interface IoFiltersessionIdle in class IoFilterAdapternextFilter - The filter to call nextsession - The associated sessionstatus - The session's statusjava.lang.Exceptionpublic void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
sessionClosed in interface IoFiltersessionClosed in class IoFilterAdapternextFilter - The filter to call nextsession - The associated sessionjava.lang.Exceptionpublic double getAverageTime(IoEventType type)
IoEventTypetype - The IoEventType that the user wants to get the average method call timeIoEventTypepublic long getTotalCalls(IoEventType type)
IoEventTypetype - The IoEventType that the user wants to get the total number of method callsIoEventTypepublic long getTotalTime(IoEventType type)
type - The IoEventType that the user wants to get the total time this method has
been executingIoEventTypepublic long getMinimumTime(IoEventType type)
IoEventType has executedtype - The IoEventType that the user wants to get the minimum time this method has
executedIoEventTypepublic long getMaximumTime(IoEventType type)
IoEventType has executedtype - The IoEventType that the user wants to get the maximum time this method has
executedIoEventTypeprivate long timeNow()