circuits-meter
Safe HaskellNone
LanguageGHC2024

Circuit.Meter

Description

Performance measurement reimagined as a Circuit.

A Meter arr a b is a pair of arrows: start produces the initial state, stop observes it and produces a measurement. The canonical use is meterAction, which sandwiches a payload arrow between the two meter arrows.

Synopsis

Meter

data Meter (arr :: Type -> Type -> Type) a b Source #

A Meter arr a b is a stopwatch: a pair of arrows.

  • start() → arr a — capture initial state (e.g. read the clock).
  • stopa → arr b — observe the state and produce a measurement (e.g. read the clock again and subtract). May be called multiple times; each call measures elapsed time since the single start.

Constructors

Meter 

Fields

mkMeter :: m a -> (a -> m b) -> Meter (K m) a b Source #

Construct a Meter from raw monadic actions.

Cartesian helpers for Kleisli arrows

firstK :: forall (m :: Type -> Type) a b c. Functor m => K m a b -> K m (a, c) (b, c) Source #

First component for K m.

secondK :: forall (m :: Type -> Type) a b c. Functor m => K m a b -> K m (c, a) (c, b) Source #

Second component for K m.

dimapK :: forall (m :: Type -> Type) a' a b b'. Functor m => (a' -> a) -> (b -> b') -> K m a b -> K m a' b' Source #

Profunctor-style pre/post composition for K m.

Meter composition

both :: forall (m :: Type -> Type) a1 b1 a2 b2. Monad m => Meter (K m) a1 b1 -> Meter (K m) a2 b2 -> Meter (K m) (a1, a2) (b1, b2) Source #

Run two meters simultaneously.

The state wires are independent; the (,) tensor handles the wiring automatically.

Plugin metering

meterAction :: forall (m :: Type -> Type) a b c d (t :: Type -> Type -> Type). Monad m => Meter (K m) a b -> K m c d -> Trace t (K m) c (b, d) Source #

Meter a Kleisli arrow action, keeping the measurement.

Tensor-agnostic: the bracket is built directly in the base arrow and lifted with base, so the meter state is introduced and consumed locally. The result is a Circuit polymorphic in the tensor t.

For arrow-level extraction, use eval with your chosen tensor.

Hold

hold :: a -> a Source #

Hold back a value so GHC cannot float a function application past the meter boundary. Re-exported for custom meter authors.