System.Clock

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
- 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 #

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.

#### Instances

Instances details

Enum Clock # |
Instance details Defined in System.Clock Methods succ :: Clock -> Clock # pred :: Clock -> Clock # toEnum :: Int -> Clock # fromEnum :: Clock -> Int # enumFrom :: Clock -> [Clock] # enumFromThen :: Clock -> Clock -> [Clock] # enumFromTo :: Clock -> Clock -> [Clock] # enumFromThenTo :: Clock -> Clock -> Clock -> [Clock] #
Generic Clock # |
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-BoSBw0VDB82KWo50HGG2ac" '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)))
Methods from :: Clock -> Rep Clock x # to :: Rep Clock x -> Clock #
Read Clock # |
Instance details Defined in System.Clock Methods readsPrec :: Int -> ReadS Clock # readList :: ReadS [Clock] # readPrec :: ReadPrec Clock # readListPrec :: ReadPrec [Clock] #
Show Clock # |
Instance details Defined in System.Clock Methods showsPrec :: Int -> Clock -> ShowS # show :: Clock -> String # showList :: [Clock] -> ShowS #
Eq Clock # |
Instance details Defined in System.Clock Methods (==) :: Clock -> Clock -> Bool # (/=) :: Clock -> Clock -> Bool #
type Rep Clock # |
Instance details Defined in System.Clock type Rep Clock = D1 ('MetaData "Clock" "System.Clock" "clock-0.8.4-BoSBw0VDB82KWo50HGG2ac" '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)))

data TimeSpec #

TimeSpec structure

Constructors

TimeSpec |
Fields sec :: !Int64 seconds nsec :: !Int64 nanoseconds

#### Instances

Instances details

Bounded TimeSpec # |
Instance details Defined in System.Clock Methods minBound :: TimeSpec # maxBound :: TimeSpec #
Enum TimeSpec # |
Instance details Defined in System.Clock Methods succ :: TimeSpec -> TimeSpec # pred :: TimeSpec -> TimeSpec # toEnum :: Int -> TimeSpec # fromEnum :: TimeSpec -> Int # enumFrom :: TimeSpec -> [TimeSpec] # enumFromThen :: TimeSpec -> TimeSpec -> [TimeSpec] # enumFromTo :: TimeSpec -> TimeSpec -> [TimeSpec] # enumFromThenTo :: TimeSpec -> TimeSpec -> TimeSpec -> [TimeSpec] #
Storable TimeSpec # |
Instance details Defined in System.Clock Methods sizeOf :: TimeSpec -> Int # alignment :: TimeSpec -> Int # peekElemOff :: Ptr TimeSpec -> Int -> IO TimeSpec # pokeElemOff :: Ptr TimeSpec -> Int -> TimeSpec -> IO () # peekByteOff :: Ptr b -> Int -> IO TimeSpec # pokeByteOff :: Ptr b -> Int -> TimeSpec -> IO () # peek :: Ptr TimeSpec -> IO TimeSpec # poke :: Ptr TimeSpec -> TimeSpec -> IO () #
Generic TimeSpec # |
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-BoSBw0VDB82KWo50HGG2ac" '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 # to :: Rep TimeSpec x -> TimeSpec #
Num TimeSpec # |
Instance details Defined in System.Clock Methods (+) :: TimeSpec -> TimeSpec -> TimeSpec # (-) :: TimeSpec -> TimeSpec -> TimeSpec # (*) :: TimeSpec -> TimeSpec -> TimeSpec # negate :: TimeSpec -> TimeSpec # abs :: TimeSpec -> TimeSpec # signum :: TimeSpec -> TimeSpec # fromInteger :: Integer -> TimeSpec #
Read TimeSpec # |
Instance details Defined in System.Clock Methods readsPrec :: Int -> ReadS TimeSpec # readList :: ReadS [TimeSpec] # readPrec :: ReadPrec TimeSpec # readListPrec :: ReadPrec [TimeSpec] #
Integral TimeSpec # |
Instance details Defined in System.Clock Methods quot :: TimeSpec -> TimeSpec -> TimeSpec # rem :: TimeSpec -> TimeSpec -> TimeSpec # div :: TimeSpec -> TimeSpec -> TimeSpec # mod :: TimeSpec -> TimeSpec -> TimeSpec # quotRem :: TimeSpec -> TimeSpec -> (TimeSpec, TimeSpec) # divMod :: TimeSpec -> TimeSpec -> (TimeSpec, TimeSpec) # toInteger :: TimeSpec -> Integer #
Real TimeSpec # |
Instance details Defined in System.Clock Methods toRational :: TimeSpec -> Rational #
Show TimeSpec # |
Instance details Defined in System.Clock Methods showsPrec :: Int -> TimeSpec -> ShowS # show :: TimeSpec -> String # showList :: [TimeSpec] -> ShowS #
Eq TimeSpec # |
Instance details Defined in System.Clock Methods (==) :: TimeSpec -> TimeSpec -> Bool # (/=) :: TimeSpec -> TimeSpec -> Bool #
Ord TimeSpec # |
Instance details Defined in System.Clock Methods compare :: TimeSpec -> TimeSpec -> Ordering # (<) :: TimeSpec -> TimeSpec -> Bool # (<=) :: TimeSpec -> TimeSpec -> Bool # (>) :: TimeSpec -> TimeSpec -> Bool # (>=) :: TimeSpec -> TimeSpec -> Bool # max :: TimeSpec -> TimeSpec -> TimeSpec # min :: TimeSpec -> TimeSpec -> TimeSpec #
type Rep TimeSpec # |
Instance details Defined in System.Clock type Rep TimeSpec = D1 ('MetaData "TimeSpec" "System.Clock" "clock-0.8.4-BoSBw0VDB82KWo50HGG2ac" '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 #

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

getRes :: Clock -> IO TimeSpec #

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 #

TimeSpec from nano seconds.

toNanoSecs :: TimeSpec -> Integer #

TimeSpec to nano seconds.

diffTimeSpec :: TimeSpec -> TimeSpec -> TimeSpec #

Compute the absolute difference.

timeSpecAsNanoSecs :: TimeSpec -> Integer #

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

TimeSpec as nano seconds.

normalize :: TimeSpec -> TimeSpec #

s2ns :: Num a => a #