| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Meter.Stopwatch
Contents
Description
Stopwatch/interval metering as a first-class circuit wire.
Instead of wrapping each stage individually, drop named markers into a
left-to-right pipeline. The timing log travels on a cartesian (,) wire
alongside the payload.
A single watch is active at any point. start sets the active watch;
lap records an interval since the previous start or lap under a
given label and starts a fresh interval on the same active watch;
stop records the final interval and keeps the log.
Synopsis
- data Watches x y
- allLaps :: Watches x y -> Map String [y]
- watchLaps :: Watches x y -> String -> [y]
- start :: Meter (K IO) x y -> String -> Trace (,) (K IO) a (a, Watches x y)
- lap :: Meter (K IO) x y -> String -> Trace (,) (K IO) (a, Watches x y) (a, Watches x y)
- stop :: Meter (K IO) x y -> String -> Trace (,) (K IO) (a, Watches x y) (a, Watches x y)
- carry :: K IO a b -> Trace (,) (K IO) (a, Watches x y) (b, Watches x y)
- carryT :: forall (t :: Type -> Type -> Type) a b x y. Traced t (K IO) => Trace t (K IO) a b -> Trace (,) (K IO) (a, Watches x y) (b, Watches x y)
- meterIt :: Meter (K IO) x y -> String -> K IO a b -> Trace (,) (K IO) a (b, Watches x y)
- timeIt :: String -> K IO a b -> Trace (,) (K IO) a (b, Watches Nanos Nanos)
- meterItN :: Int -> Meter (K IO) x y -> String -> K IO a b -> Trace (,) (K IO) a (b, Watches x y)
- timeItN :: Int -> String -> K IO a b -> Trace (,) (K IO) a (b, Watches Nanos Nanos)
Timing log
Stopwatch state: the active watch name, the meter state for the current in-flight interval, and the log of completed intervals.
allLaps :: Watches x y -> Map String [y] Source #
Extract all measurements for all labels, oldest first.
watchLaps :: Watches x y -> String -> [y] Source #
Extract all measurements for a named label, oldest first.
Markers
start :: Meter (K IO) x y -> String -> Trace (,) (K IO) a (a, Watches x y) Source #
Start a named watch. Sets the active watch and initializes the meter state for the first interval.
lap :: Meter (K IO) x y -> String -> Trace (,) (K IO) (a, Watches x y) (a, Watches x y) Source #
Record a lap: stop the current interval, store the measurement under
label, and start a fresh interval on the same active watch.
stop :: Meter (K IO) x y -> String -> Trace (,) (K IO) (a, Watches x y) (a, Watches x y) Source #
Stop the active watch: record the final interval under name and keep
the log.
Stage sugar
carry :: K IO a b -> Trace (,) (K IO) (a, Watches x y) (b, Watches x y) Source #
Lift a base arrow so it carries the timing wire unchanged.
carryT :: forall (t :: Type -> Type -> Type) a b x y. Traced t (K IO) => Trace t (K IO) a b -> Trace (,) (K IO) (a, Watches x y) (b, Watches x y) Source #
Lift an already-built Trace stage so it carries the timing wire
unchanged. The stage is run at its own tensor and then threaded through the
cartesian timing wire.
meterIt :: Meter (K IO) x y -> String -> K IO a b -> Trace (,) (K IO) a (b, Watches x y) Source #
Meter a single stage: start, run the stage, stop.
timeIt :: String -> K IO a b -> Trace (,) (K IO) a (b, Watches Nanos Nanos) Source #
meterIt with the default time meter.
meterItN :: Int -> Meter (K IO) x y -> String -> K IO a b -> Trace (,) (K IO) a (b, Watches x y) Source #
Meter a stage over n repetitions and record the total measurement.
The stage is run n times between start and stop; the recorded lap is
the total time/space for all runs. Divide by n for a per-iteration average.
The last result is kept and forced to WHNF; intermediate results are also forced
so the work cannot be floated out of the loop.