packages feed

eventlog-live-0.3.0.0: src/GHC/Eventlog/Live/Data/Span.hs

{- |
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 s = if s.startTimeUnixNano < s.endTimeUnixNano then s.endTimeUnixNano - s.startTimeUnixNano else 0
{-# INLINEABLE duration #-}