Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Util.Enclose
Contents
Description
Utility functions for enclosing a code segment with tracing events.
Synopsis
- data Enclosing' a
- = RisingEdge
- | FallingEdgeWith !a
- type Enclosing = Enclosing' ()
- pattern FallingEdge ∷ Enclosing' ()
- encloseWith ∷ Applicative m ⇒ Tracer m Enclosing → m a → m a
- type EnclosingTimed = Enclosing' DiffTime
- encloseTimedWith ∷ MonadMonotonicTime m ⇒ Tracer m EnclosingTimed → m a → m a
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
Show a ⇒ Show (Enclosing' a) Source # | |
Defined in Ouroboros.Consensus.Util.Enclose Methods showsPrec ∷ Int → Enclosing' a → ShowS # show ∷ Enclosing' a → String # showList ∷ [Enclosing' a] → ShowS # | |
Eq a ⇒ Eq (Enclosing' a) Source # | |
Defined in Ouroboros.Consensus.Util.Enclose | |
Ord a ⇒ Ord (Enclosing' a) Source # | |
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 # |
Simple usage
type Enclosing = Enclosing' () Source #
Enclosing'
, but without extra data in the FallingEdge
case.
pattern FallingEdge ∷ Enclosing' () Source #
encloseWith ∷ Applicative 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) :}