public class ExecutorStatisticWrapper extends AbstractSubmitterExecutor implements StatisticExecutor
Executor
to get statistics based off executions through this wrapper. If
statistics are desired on the PriorityScheduler
,
PrioritySchedulerStatisticTracker
may be a better
option, taking advantages by extending and replacing logic rather than wrapping and just adding
logic. Similarly
SingleThreadSchedulerStatisticTracker
and
NoThreadSchedulerStatisticTracker
should be used as
an alternative for their respective schedulers.Constructor and Description |
---|
ExecutorStatisticWrapper(java.util.concurrent.Executor executor)
Constructs a new statistics tracker wrapper for a given executor.
|
ExecutorStatisticWrapper(java.util.concurrent.Executor executor,
boolean accurateTime)
Constructs a new statistics tracker wrapper for a given executor.
|
ExecutorStatisticWrapper(java.util.concurrent.Executor executor,
int maxStatisticWindowSize)
Constructs a new statistics tracker wrapper for a given executor.
|
ExecutorStatisticWrapper(java.util.concurrent.Executor executor,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new statistics tracker wrapper for a given executor.
|
Modifier and Type | Method and Description |
---|---|
double |
getAverageExecutionDelay()
This reports the rolling average delay from when a task was expected to run, till when the
executor actually started the task.
|
double |
getAverageExecutionDuration()
Get the average duration that tasks submitted through this executor have spent executing.
|
java.util.Map<java.lang.Double,java.lang.Long> |
getExecutionDelayPercentiles(double... percentiles)
Gets percentile values for execution delays.
|
java.util.List<java.lang.Long> |
getExecutionDelaySamples()
Get raw sample data for task execution delays.
|
java.util.Map<java.lang.Double,java.lang.Long> |
getExecutionDurationPercentiles(double... percentiles)
Gets percentile values for execution duration.
|
java.util.List<java.lang.Long> |
getExecutionDurationSamples()
Get raw sample data for task run durations.
|
java.util.List<Pair<java.lang.Runnable,java.lang.StackTraceElement[]>> |
getLongRunningTasks(long durationLimitMillis)
Call to get a list of runnables and stack traces from tasks which have been actively
executing for a longer duration than the one provided.
|
int |
getLongRunningTasksQty(long durationLimitMillis)
Call to return the number of tasks which have been running longer than the provided duration
in milliseconds.
|
int |
getQueuedTaskCount()
Call to check how many tasks are queued waiting for execution.
|
long |
getTotalExecutionCount()
Call to get the total quantity of tasks this executor has handled.
|
void |
resetCollectedStats()
Clears all collected rolling statistics.
|
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
submit, submit, submit
public ExecutorStatisticWrapper(java.util.concurrent.Executor executor)
This defaults to inaccurate time. Meaning that durations and delays may under report (but
NEVER OVER what they actually were). This has the least performance impact. If you want more
accurate time consider using ExecutorStatisticWrapper(Executor, boolean)
.
executor
- Executor to defer executions topublic ExecutorStatisticWrapper(java.util.concurrent.Executor executor, boolean accurateTime)
executor
- Executor to defer executions toaccurateTime
- true
to ensure that delays and durations are not under reportedpublic ExecutorStatisticWrapper(java.util.concurrent.Executor executor, int maxStatisticWindowSize)
This defaults to inaccurate time. Meaning that durations and delays may under report (but
NEVER OVER what they actually were). This has the least performance impact. If you want more
accurate time consider using ExecutorStatisticWrapper(Executor, int, boolean)
.
executor
- Executor to defer executions tomaxStatisticWindowSize
- maximum number of samples to keep internallypublic ExecutorStatisticWrapper(java.util.concurrent.Executor executor, int maxStatisticWindowSize, boolean accurateTime)
executor
- Executor to defer executions tomaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic java.util.List<java.lang.Long> getExecutionDelaySamples()
StatisticExecutor
StatisticsUtils
for additional statistics.getExecutionDelaySamples
in interface StatisticExecutor
public double getAverageExecutionDelay()
StatisticExecutor
-1
if no samples have been
collected yet.getAverageExecutionDelay
in interface StatisticExecutor
public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDelayPercentiles(double... percentiles)
StatisticExecutor
The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.
getExecutionDelayPercentiles
in interface StatisticExecutor
percentiles
- Percentiles requested, any decimal values between 0 and 100 (inclusive)public java.util.List<java.lang.Long> getExecutionDurationSamples()
StatisticExecutor
StatisticsUtils
for additional statistics.getExecutionDurationSamples
in interface StatisticExecutor
public double getAverageExecutionDuration()
StatisticExecutor
getAverageExecutionDuration
in interface StatisticExecutor
public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDurationPercentiles(double... percentiles)
StatisticExecutor
The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.
getExecutionDurationPercentiles
in interface StatisticExecutor
percentiles
- Percentiles requested, any decimal values between 0 and 100 (inclusive)public java.util.List<Pair<java.lang.Runnable,java.lang.StackTraceElement[]>> getLongRunningTasks(long durationLimitMillis)
StatisticExecutor
If only the quantity of long running tasks is needed, please use
StatisticExecutor.getLongRunningTasksQty(long)
. Since it does not need to generate stack traces it is
a cheaper alternative.
The left side of the Pair
is the runnable task submitted. If the task was submitted
as a Callable
the Runnable will be of type:
ListenableFutureTask
. Casting and invoking
ListenableFutureTask.getContainedCallable()
will allow
you to get to your original Callable
.
The right side of the Pair
is a single sample of what that long running tasks stack
was. Because these tasks are running concurrently by the time this function returns the
provided tasks may have completed.
getLongRunningTasks
in interface StatisticExecutor
durationLimitMillis
- Limit for tasks execution, if task execution time is below this they will be ignoredpublic int getLongRunningTasksQty(long durationLimitMillis)
StatisticExecutor
getLongRunningTasksQty
in interface StatisticExecutor
durationLimitMillis
- threshold of time in milliseconds a task must have been executingpublic int getQueuedTaskCount()
getQueuedTaskCount
in interface StatisticExecutor
public long getTotalExecutionCount()
StatisticExecutor
getTotalExecutionCount
in interface StatisticExecutor
public void resetCollectedStats()
StatisticExecutor
This does NOT reset the total execution counts.
resetCollectedStats
in interface StatisticExecutor