val pm: ParallelMap = ParallelMap.parallel
val timed = new TimedParallelMap("root", pm)
val child = timed.child("phase-1")
val out = child(Seq(1,2,3), _ * 2) // work to be timed under "phase-1"
val report: TimingReport = timed.report
println(report.pretty) // or however you surface it
All timing state and the child list are protected by an internal java.util.concurrent.locks.ReentrantLock. You may call apply, run, child, nanos, and report concurrently from multiple threads.
Timing introduces one System.nanoTime() pair per apply/run call and a few lock acquisitions. For extremely fine-grained tasks, prefer timing fewer, larger phases.
Value parameters
inner
The underlying strategy to which work is delegated.
name
Logical name for this timing node (used in report).
Wall-clock elapsed time (in nanoseconds) covered by this node and all of its descendants.
Wall-clock elapsed time (in nanoseconds) covered by this node and all of its descendants.
Defined as max(endTimes) - min(startTimes) across the subtree. If no work has been recorded yet (no apply or run was called on this node or its children), returns 0.
Builds a hierarchical TimingReport for this node and its children.
Builds a hierarchical TimingReport for this node and its children.
The report captures each node's name and elapsed wall-clock time (via nanos) and then runs a simplification pass (see TimingReport.simplify) to collapse trivial structure.
Returns a view of this strategy that cooperatively cancels work using the given token.
Returns a view of this strategy that cooperatively cancels work using the given token.
Semantics:
If the token is canceled before work begins, no work is performed and an OperationCanceledException is thrown immediately.
While mapping, cancellation is observed at wrapper checkpoints (see below). When detected, an OperationCanceledException is thrown and remaining work is skipped.
Checkpoints added by this wrapper:
One check before the mapping starts.
One check before processing each input element.
Important:
The wrapper does not interrupt user code while running a single element function f. If f can run for a long time, pass the token into f and poll it inside f to achieve finer-grained cancellation.
Example:
val token = new CancellationToken
token.cancelAfter(30.seconds) // common "set and forget" timeout
val pm = ParallelMap.parallel.cancelable(token)
val out = pm(items, { a =>
// Optional finer-grained check inside user code
if (token.isCanceled) throw OperationCanceledException(token)
compute(a)
})
Composition:
Children created via child inherit cancellation by wrapping the parent's child.
Can be combined with timed; timing still reflects the work up to cancellation.
Value parameters
token
Cancellation trigger to observe.
Attributes
Returns
A new ParallelMap that observes the token at the described checkpoints.