clock-0.8.4: High-resolution clock functions: monotonic, realtime, cputime.

Safe Haskell | None
Language | Haskell2010

System.Clock

Description

High-resolution, realtime clock and timer functions for Posix systems. This module is being developed according to IEEE Std 1003.1-2008: http://www.opengroup.org/onlinepubs/9699919799/, http://www.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html#

Synopsis

- data Clock
  - = Monotonic
  - | Realtime
  - | ProcessCPUTime
  - | ThreadCPUTime
  - | MonotonicRaw
  - | Boottime
  - | MonotonicCoarse
  - | RealtimeCoarse
- data TimeSpec = TimeSpec {
  - sec :: !Int64
  - nsec :: !Int64
  }
- getTime :: Clock -> IO TimeSpec
- getRes :: Clock -> IO TimeSpec
- fromNanoSecs :: Integer -> TimeSpec
- toNanoSecs :: TimeSpec -> Integer
- diffTimeSpec :: TimeSpec -> TimeSpec -> TimeSpec
- timeSpecAsNanoSecs :: TimeSpec -> Integer
- normalize :: TimeSpec -> TimeSpec
- s2ns :: Num a => a

# Documentation

data Clock Source #

Clock types. A clock may be system-wide (that is, visible to all processes) or per-process (measuring time that is meaningful only within a process). All implementations shall support `Realtime`.

Constructors

Monotonic

The identifier for the system-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be set via `clock_settime` and which cannot have negative clock jumps. The maximum possible clock jump shall be implementation defined. For this clock, the value returned by `getTime` represents the amount of time (in seconds and nanoseconds) since an unspecified point in the past (for example, system start-up time, or the Epoch). This point does not change after system start-up time. Note that the absolute value of the monotonic clock is meaningless (because its origin is arbitrary), and thus there is no need to set it. Furthermore, realtime applications can rely on the fact that the value of this clock is never set. (Identical to `Boottime` since Linux 4.17, see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d6ed449afdb38f89a7b38ec50e367559e1b8f71f) `CLOCK_MONOTONIC` (macOS - `SYSTEM_CLOCK`)

Realtime | The identifier of the system-wide clock measuring real time. For this clock, the value returned by `getTime` represents the amount of time (in seconds and nanoseconds) since the Epoch. `CLOCK_REALTIME` (macOS - `CALENDAR_CLOCK`, Windows - `GetSystemTimeAsFileTime`)
ProcessCPUTime | The identifier of the CPU-time clock associated with the calling process. For this clock, the value returned by `getTime` represents the amount of execution time of the current process.
ThreadCPUTime | The identifier of the CPU-time clock associated with the calling OS thread. For this clock, the value returned by `getTime` represents the amount of execution time of the current OS thread.
MonotonicRaw | (since Linux 2.6.28, macOS 10.12) Similar to `Monotonic`, but provides access to a raw hardware-based time that is not subject to NTP adjustments or the incremental adjustments performed by adjtime(3). `CLOCK_MONOTONIC_RAW` (Windows - `QueryPerformanceCounter`, `QueryPerformanceFrequency`)
Boottime | (since Linux 2.6.39; Linux-specific) Identical to `Monotonic`, except it also includes any time that the system is suspended. This allows applications to get a suspend-aware monotonic clock without having to deal with the complications of `Realtime`, which may have discontinuities if the time is changed using settimeofday(2). (since Linux 4.17; identical to `Monotonic`) `CLOCK_BOOTTIME`
MonotonicCoarse | (since Linux 2.6.32; Linux-specific) A faster but less precise version of `Monotonic`. Use when you need very fast, but not fine-grained timestamps. `CLOCK_MONOTONIC_COARSE`
RealtimeCoarse | (since Linux 2.6.32; Linux-specific) A faster but less precise version of `Realtime`. Use when you need very fast, but not fine-grained timestamps. `CLOCK_REALTIME_COARSE`

#### Instances

Instances details

Enum Clock Source # |
Instance details Defined in System.Clock Methods succ :: Clock -> Clock Source # pred :: Clock -> Clock Source # toEnum :: Int -> Clock Source # fromEnum :: Clock -> Int Source # enumFrom :: Clock -> [Clock] Source # enumFromThen :: Clock -> Clock -> [Clock] Source # enumFromTo :: Clock -> Clock -> [Clock] Source # enumFromThenTo :: Clock -> Clock -> Clock -> [Clock] Source #
Generic Clock Source # |

Instance details

Defined in System.Clock

Associated Types

type Rep Clock |

Instance details

Defined in System.Clock

type Rep Clock = D1 ('MetaData "Clock" "System.Clock" "clock-0.8.4-H2gxghH0gZSWFOI5QDUKZ" 'False) (((C1 ('MetaCons "Monotonic" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Realtime" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "ProcessCPUTime" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ThreadCPUTime" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MonotonicRaw" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Boottime" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MonotonicCoarse" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RealtimeCoarse" 'PrefixI 'False) (U1 :: Type -> Type))))

Methods

from :: Clock -> Rep Clock x Source #

to :: Rep Clock x -> Clock Source #

Read Clock Source # |
Instance details Defined in System.Clock Methods readsPrec :: Int -> ReadS Clock Source # readList :: ReadS [Clock] Source # readPrec :: ReadPrec Clock Source # readListPrec :: ReadPrec [Clock] Source #
Show Clock Source # |
Instance details Defined in System.Clock Methods showsPrec :: Int -> Clock -> ShowS Source # show :: Clock -> String Source # showList :: [Clock] -> ShowS Source #
Eq Clock Source # |
Instance details Defined in System.Clock Methods (==) :: Clock -> Clock -> Bool Source # (/=) :: Clock -> Clock -> Bool Source #
type Rep Clock Source # |

Instance details

Defined in System.Clock

type Rep Clock = D1 ('MetaData "Clock" "System.Clock" "clock-0.8.4-H2gxghH0gZSWFOI5QDUKZ" 'False) (((C1 ('MetaCons "Monotonic" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Realtime" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "ProcessCPUTime" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ThreadCPUTime" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "MonotonicRaw" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Boottime" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "MonotonicCoarse" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "RealtimeCoarse" 'PrefixI 'False) (U1 :: Type -> Type))))

data TimeSpec Source #

TimeSpec structure

Constructors

TimeSpec |

Fields

- sec :: !Int64

  seconds

- nsec :: !Int64

  nanoseconds

#### Instances

Instances details

Bounded TimeSpec Source # |
Instance details Defined in System.Clock Methods minBound :: TimeSpec Source # maxBound :: TimeSpec Source #
Enum TimeSpec Source # |

Instance details

Defined in System.Clock

Methods

succ :: TimeSpec -> TimeSpec Source #

pred :: TimeSpec -> TimeSpec Source #

toEnum :: Int -> TimeSpec Source #

fromEnum :: TimeSpec -> Int Source #

enumFrom :: TimeSpec -> [TimeSpec] Source #

enumFromThen :: TimeSpec -> TimeSpec -> [TimeSpec] Source #

enumFromTo :: TimeSpec -> TimeSpec -> [TimeSpec] Source #

enumFromThenTo :: TimeSpec -> TimeSpec -> TimeSpec -> [TimeSpec] Source #

Storable TimeSpec Source # |

Instance details

Defined in System.Clock

Methods

sizeOf :: TimeSpec -> Int Source #

alignment :: TimeSpec -> Int Source #

peekElemOff :: Ptr TimeSpec -> Int -> IO TimeSpec Source #

pokeElemOff :: Ptr TimeSpec -> Int -> TimeSpec -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO TimeSpec Source #

pokeByteOff :: Ptr b -> Int -> TimeSpec -> IO () Source #

peek :: Ptr TimeSpec -> IO TimeSpec Source #

poke :: Ptr TimeSpec -> TimeSpec -> IO () Source #

Generic TimeSpec Source # |

Instance details

Defined in System.Clock

Associated Types

type Rep TimeSpec |
Instance details Defined in System.Clock type Rep TimeSpec = D1 ('MetaData "TimeSpec" "System.Clock" "clock-0.8.4-H2gxghH0gZSWFOI5QDUKZ" 'False) (C1 ('MetaCons "TimeSpec" 'PrefixI 'True) (S1 ('MetaSel ('Just "sec") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int64) :*: S1 ('MetaSel ('Just "nsec") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int64)))

Methods

from :: TimeSpec -> Rep TimeSpec x Source #

to :: Rep TimeSpec x -> TimeSpec Source #

Num TimeSpec Source # |
Instance details Defined in System.Clock Methods (+) :: TimeSpec -> TimeSpec -> TimeSpec Source # (-) :: TimeSpec -> TimeSpec -> TimeSpec Source # (*) :: TimeSpec -> TimeSpec -> TimeSpec Source # negate :: TimeSpec -> TimeSpec Source # abs :: TimeSpec -> TimeSpec Source # signum :: TimeSpec -> TimeSpec Source # fromInteger :: Integer -> TimeSpec Source #
Read TimeSpec Source # |
Instance details Defined in System.Clock Methods readsPrec :: Int -> ReadS TimeSpec Source # readList :: ReadS [TimeSpec] Source # readPrec :: ReadPrec TimeSpec Source # readListPrec :: ReadPrec [TimeSpec] Source #
Integral TimeSpec Source # |

Instance details

Defined in System.Clock

Methods

quot :: TimeSpec -> TimeSpec -> TimeSpec Source #

rem :: TimeSpec -> TimeSpec -> TimeSpec Source #

div :: TimeSpec -> TimeSpec -> TimeSpec Source #

mod :: TimeSpec -> TimeSpec -> TimeSpec Source #

quotRem :: TimeSpec -> TimeSpec -> (TimeSpec, TimeSpec) Source #

divMod :: TimeSpec -> TimeSpec -> (TimeSpec, TimeSpec) Source #

toInteger :: TimeSpec -> Integer Source #

Real TimeSpec Source # |
Instance details Defined in System.Clock Methods toRational :: TimeSpec -> Rational Source #
Show TimeSpec Source # |
Instance details Defined in System.Clock Methods showsPrec :: Int -> TimeSpec -> ShowS Source # show :: TimeSpec -> String Source # showList :: [TimeSpec] -> ShowS Source #
Eq TimeSpec Source # |
Instance details Defined in System.Clock Methods (==) :: TimeSpec -> TimeSpec -> Bool Source # (/=) :: TimeSpec -> TimeSpec -> Bool Source #
Ord TimeSpec Source # |
Instance details Defined in System.Clock Methods compare :: TimeSpec -> TimeSpec -> Ordering Source # (<) :: TimeSpec -> TimeSpec -> Bool Source # (<=) :: TimeSpec -> TimeSpec -> Bool Source # (>) :: TimeSpec -> TimeSpec -> Bool Source # (>=) :: TimeSpec -> TimeSpec -> Bool Source # max :: TimeSpec -> TimeSpec -> TimeSpec Source # min :: TimeSpec -> TimeSpec -> TimeSpec Source #
type Rep TimeSpec Source # |
Instance details Defined in System.Clock type Rep TimeSpec = D1 ('MetaData "TimeSpec" "System.Clock" "clock-0.8.4-H2gxghH0gZSWFOI5QDUKZ" 'False) (C1 ('MetaCons "TimeSpec" 'PrefixI 'True) (S1 ('MetaSel ('Just "sec") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int64) :*: S1 ('MetaSel ('Just "nsec") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int64)))

getTime :: Clock -> IO TimeSpec Source #

The `getTime` function shall return the current value for the specified clock.

getRes :: Clock -> IO TimeSpec Source #

The `getRes` function shall return the resolution of any clock. Clock resolutions are implementation-defined and cannot be set by a process.

fromNanoSecs :: Integer -> TimeSpec Source #

TimeSpec from nano seconds.

toNanoSecs :: TimeSpec -> Integer Source #

TimeSpec to nano seconds.

diffTimeSpec :: TimeSpec -> TimeSpec -> TimeSpec Source #

Compute the absolute difference.

timeSpecAsNanoSecs :: TimeSpec -> Integer Source #

Deprecated: Use toNanoSecs instead! Replaced timeSpecAsNanoSecs with the same signature TimeSpec -> Integer

TimeSpec as nano seconds.

normalize :: TimeSpec -> TimeSpec Source #

s2ns :: Num a => a Source #