Module Affect_unix.Mtime

Monotonic time.

This time is measured by sampling this clock. It increases monotonically and, in contrast to Ptime, is not subject to operating system calendar time adjustments.

Time spans

module Span : sig ... end

Time spans.

Waiting

Warning. This relies on an Unix.unblocker being setup on the executing domain.

val wait_for : Span.t -> unit

wait_for span blocks the caller until a minimum amount of span time has elapsed on the monotonic clock. The actual supported resolution is unspecified and may depend on scheduling but millisecond waits should be reasonably precise. Use observe_wait_for to measure the overshoot.

val observe_wait_for : Span.t -> Span.t

observe_wait_for is like wait_for but returns the actual amount of monotonic time that elapsed on the monotonic clock between the call and when it returned.

Actions

val wait_for' : Span.t -> 'tag -> 'tag Affect.Action.t

wait_for' span tag is the action for wait_for. The action invocation enables and synchronizes with tag after a minimum amount of span monotonic time has elapsed on the monotonic clock.

Counters

type counter

The type for monotonic wall-clock time counters.

val counter : unit -> counter

counter () is a counter counting from now on.

val count : counter -> Span.t

count c is the amount of time that has elapsed on the monotonic clock since c was created.

val elapsed : unit -> Span.t

elapsed () is the amount of time that has elapsed on the monotonic clock since the beginning of the program.

Timestamps

Note. Only use timestamps if you need inter-process time correlation, otherwise prefer elapsed and counters to measure time.

type t

The type for monotonic timestamps relative to an indeterminate system-wide event (e.g. last startup). Their absolute value has no meaning but can be used for inter-process time correlation.

val now : unit -> t

now () is the current system-relative timestamp on the monotonic clock. Its absolute value is meaningless.

val min_stamp : t

min_stamp is the earliest timestamp.

val max_stamp : t

max_stamp is the latest timestamp.

Predicates

val equal : t -> t -> bool

equal t0 t1 is true if and only if t0 and t1 are equal.

val compare : t -> t -> int

compare totally orders timestamps by increasing time.

val is_earlier : t -> than:t -> bool

is_earlier t ~than is true if and only if t occurred strictly before than.

val is_later : t -> than:t -> bool

is_later t ~than is true if and only if t occurred strictly after than.

Arithmetic

val span : t -> t -> Span.t

span t0 t1 is the span between t0 and t1 regardless of the order between t0 and t1.

val add_span : t -> Span.t -> t option

add_span t s is the timestamp s units later than t or None if the result overflows.

val sub_span : t -> Span.t -> t option

sub_span t s is the timestamp s units earlier than t or None if overflows.

Converting

val to_uint64_ns : t -> int64

to_uint64_ns t is t as an unsigned 64-bit integer nanosecond timestamp. The absolute value is meaningless.

val of_uint64_ns : int64 -> t

to_uint64_ns t is t is an unsigned 64-bit integer nanosecond timestamp as a timestamp.

Warning. Timestamps returned by this function should only be used with other timestamp values that are know to come from the same operating system run.

val pp : Stdlib.Format.formatter -> t -> unit

pp is a formatter for timestamps.

The monotonic clock