{- |
Module      : GHC.Eventlog.Live.Span
Description : Representation for spans.
Stability   : experimental
Portability : portable
-}
module GHC.Eventlog.Live.Data.Span (
  IsSpan,
  duration,
) where

import GHC.RTS.Events (Timestamp)
import GHC.Records (HasField)

{- |
A span is any type with a start and end time.
-}
type IsSpan s = (HasField "startTimeUnixNano" s Timestamp, HasField "endTimeUnixNano" s Timestamp)

{- |
Determine the duration of a span.
-}
duration :: (IsSpan s) => s -> Timestamp
duration :: forall s. IsSpan s => s -> Timestamp
duration s
s = if s
s.startTimeUnixNano Timestamp -> Timestamp -> Bool
forall a. Ord a => a -> a -> Bool
< s
s.endTimeUnixNano then s
s.endTimeUnixNano Timestamp -> Timestamp -> Timestamp
forall a. Num a => a -> a -> a
- s
s.startTimeUnixNano else Timestamp
0
{-# INLINEABLE duration #-}