ouroboros-consensus-0.27.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Util.Enclose

Description

Utility functions for enclosing a code segment with tracing events.

Synopsis

Documentation

data Enclosing' a Source #

Mini-abstraction for tracing of specific code segment, emitting events just before and just after.

Usage example:

>>> :{
data TraceEvent
  = TraceFoo String
  | TraceComputed
      -- | Input of the computation.
      Int
      -- | Either 'RisingEdge', or 'FallingEdgeWith' with the result.
      (Enclosing' Int)
:}
>>> :{
work :: Monad m => Tracer m TraceEvent -> Int -> m Int
work tracer input = do
  traceWith compTracer RisingEdge
  output <- pure (input + 5)
  traceWith compTracer $ FallingEdgeWith output
  pure output
  where
    compTracer = TraceComputed input >$< tracer
:}

Constructors

RisingEdge

Preceding a specific code segment.

FallingEdgeWith !a

Succeeding a specific code segment, with extra information.

Instances

Instances details
Show a ⇒ Show (Enclosing' a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Enclose

Methods

showsPrecIntEnclosing' a → ShowS #

showEnclosing' a → String #

showList ∷ [Enclosing' a] → ShowS #

Eq a ⇒ Eq (Enclosing' a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Enclose

Methods

(==)Enclosing' a → Enclosing' a → Bool #

(/=)Enclosing' a → Enclosing' a → Bool #

Ord a ⇒ Ord (Enclosing' a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Enclose

Methods

compareEnclosing' a → Enclosing' a → Ordering #

(<)Enclosing' a → Enclosing' a → Bool #

(<=)Enclosing' a → Enclosing' a → Bool #

(>)Enclosing' a → Enclosing' a → Bool #

(>=)Enclosing' a → Enclosing' a → Bool #

maxEnclosing' a → Enclosing' a → Enclosing' a #

minEnclosing' a → Enclosing' a → Enclosing' a #

Simple usage

type Enclosing = Enclosing' () Source #

Enclosing', but without extra data in the FallingEdge case.

encloseWithApplicative m ⇒ Tracer m Enclosing → m a → m a Source #

Enclose an action using the given Tracer.

>>> :{
data TraceEvent
  = TraceFoo String
  | TraceComputed
      -- | Input of the computation.
      Int
      -- | Either 'RisingEdge' or 'FallingEdge'.
      Enclosing
:}
>>> :{
work :: Monad m => Tracer m TraceEvent -> Int -> m Int
work tracer input =
  encloseWith (TraceComputed input >$< tracer) $
    pure (input + 5)
:}

Timing

type EnclosingTimed = Enclosing' DiffTime Source #

Enclosing', but with the elapsed time in the FallingEdge case.

encloseTimedWithMonadMonotonicTime m ⇒ Tracer m EnclosingTimed → m a → m a Source #

Enclose an action and trace its elapsed time.

>>> :{
data TraceEvent
  = TraceFoo String
  | TraceComputed
      -- | Input of the computation.
      Int
      -- | Either 'RisingEdge' or 'FallingEdge'.
      EnclosingTimed
:}
>>> :{
work :: MonadMonotonicTime m => Tracer m TraceEvent -> Int -> m Int
work tracer input =
  encloseTimedWith (TraceComputed input >$< tracer) $
    pure (input + 5)
:}