package affect

  1. Overview
  2. Docs

Module Affect_unix.MtimeSource

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

Sourcemodule Span : sig ... end

Time spans.

Waiting

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

Sourceval 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.

Sourceval 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

Sourceval 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

Sourcetype counter

The type for monotonic wall-clock time counters.

Sourceval counter : unit -> counter

counter () is a counter counting from now on.

Sourceval count : counter -> Span.t

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

Sourceval 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.

Sourcetype 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.

Sourceval now : unit -> t

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

Sourceval min_stamp : t

min_stamp is the earliest timestamp.

Sourceval max_stamp : t

max_stamp is the latest timestamp.

Predicates

Sourceval equal : t -> t -> bool

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

Sourceval compare : t -> t -> int

compare totally orders timestamps by increasing time.

Sourceval is_earlier : t -> than:t -> bool

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

Sourceval is_later : t -> than:t -> bool

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

Arithmetic

Sourceval span : t -> t -> Span.t

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

Sourceval 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.

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

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

Converting

Sourceval to_uint64_ns : t -> int64

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

Sourceval 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.

Sourceval pp : Format.formatter -> t -> unit

pp is a formatter for timestamps.

The monotonic clock