ouroboros-consensus
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
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

compare ∷ Enclosing' a → Enclosing' a → Ordering #

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

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

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

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

max ∷ Enclosing' a → Enclosing' a → Enclosing' a #

min ∷ Enclosing' a → Enclosing' a → Enclosing' a #

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

Defined in Ouroboros.Consensus.Util.Enclose

Methods

showsPrec ∷ Int → Enclosing' a → ShowS #

show ∷ Enclosing' a → String #

showList ∷ [Enclosing' a] → ShowS #

Simple usage

type Enclosing = Enclosing' () Source #

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

encloseWith ∷ Monad 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.

encloseTimedWith ∷ MonadMonotonicTime 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)
:}