public class ProfilingTaskRunner extends Object implements TaskRunner
format()| Constructor and Description |
|---|
ProfilingTaskRunner() |
| Modifier and Type | Method and Description |
|---|---|
Object |
before(TaskRun taskRun)
Called before
TaskRunner.executeTaskMethod(TaskRun, Thread, Object), but in the parent thread. |
Object |
executeTaskMethod(TaskRun taskRun,
Thread parentThread,
Object fromBefore)
Task invocation -- an implementation should invoke
TaskRun.run()
to complete the invocation (unless there is some reason to prevent it, but then the implementation
must take responsibility to ensure the all CompletableFuture return values are completed). |
String |
format()
Returns a tabular execution profile with events as rows and threads as columns.
|
void |
onComplete(TaskRun taskRun,
Object fromBefore,
boolean doneOnExit)
Called once any CompletableFuture return result completes, which may be before the call to
TaskRun.run() or after if a method returns an incomplete CompletableFuture.
|
public Object before(TaskRun taskRun)
TaskRunnerTaskRunner.executeTaskMethod(TaskRun, Thread, Object), but in the parent thread.
If there is no immediate spawning then it will be the same thread. The returned object will
simply be passed to executeTaskMethod and is otherwise not read or modified by the framework.before in interface TaskRunnertaskRun - that will also be passed to executeTaskMethodpublic Object executeTaskMethod(TaskRun taskRun, Thread parentThread, Object fromBefore)
TaskRunnerTaskRun.run()
to complete the invocation (unless there is some reason to prevent it, but then the implementation
must take responsibility to ensure the all CompletableFuture return values are completed). A typical
subclass implementation would be to simply surround the call, e.g.:
public Object executeTaskMethod(TaskRun taskRun, Thread parentThread, Object fromBefore) {
LOG.info("STARTED " + taskRun.getTaskPlusMethodName());
try {
taskRun.run()
} finally {
LOG.info("ENDED " + taskRun.getTaskPlusMethodName());
}
}
executeTaskMethod in interface TaskRunnertaskRun - to executeparentThread - of spawned task, which may be same as Thread.currentThread()fromBefore - value returned from TaskRunner.before(TaskRun)public void onComplete(TaskRun taskRun, Object fromBefore, boolean doneOnExit)
TaskRunnerThe provided doneOnExit parameter indicates whether a CompletableFuture return value had isDone()==true when the method completed. This should not be taken as very close but not exactly precise, since there are very small time intervals involved in the steps behind making that determination.
onComplete in interface TaskRunnertaskRun - that was executedfromBefore - value returned from TaskRunner.before(TaskRun)doneOnExit - false iff a CompletableFuture was returned and it was not done when the method exitedpublic String format()
A row is created any time (millisecond granularity) during which at least one task-related event occurred. A task start and end is indicated is by '---' entries, and if active between these two points then just a a '- entry. For example,
0
0| gold.pond ---
10| ---
and
0
0| gold.pond ---
5| -
10| ---
These each indicate that gold.pond ended 10 ms after start; the value at 5 indicates that it was active
and would only be drawn if there were additional columns (not shown above) because other things of interest
(not shown above) occurred at that time.
When a task immediately follows another within the same timestamp value, the end of the first is omitted and the new task entry has '=' markers instead of '-'. In the following, for example, gold.pond ends at timestamp 10 and gold.fish begins at that same timestamp, so the entry is '=-=' (the middle char serves other purposes, see next paragraph):
0
0| gold.pond ---
10| gold.fish =-=
20| ---
Tasks that return non-completed CompletableFutures have by definition a thread outside of BascomTask control. Each of these is represented in its own column and such columns are letter-numbered beginning with 'A'. The markers are '-+-' and '+', replacing the corresponding markers used in BascomTask-controlled threads. A task _always_ has a beginning '---' or '=-=' marker in a BascomTask-controlled thread, and it it _may also_ have a '-+-' entry on the same line in a letter-valued column.
Copyright © 2021. All rights reserved.