Module Mtime_clock

module Mtime_clock: sig .. end
Monotonic time clock.

Mtime_clock provides access to a system monotonic clock. This time increases monotonically and is not subject to operating system calendar time adjustments.

Only use Mtime_clock.now if you need inter-process time correlation, otherwise prefer Mtime_clock.elapsed and counters.

Consult important information about error handling and platform support.

v1.1.0 — homepage



Monotonic clock


val elapsed : unit -> Mtime.span
elapsed () is the monotonic time span elapsed since the beginning of the program.
Raises Sys_error see error handling
val now : unit -> Mtime.t
now () is the current system-relative monotonic timestamp. Its absolute value is meaningless.
Raises Sys_error see error handling
val period : unit -> Mtime.span option
period () is the clock's period as a monotonic time span (if available).

Time counters


type counter 
The type for monotonic wall-clock time counters.
val counter : unit -> counter
counter () is a counter counting from now on.
Raises Sys_error see error handling
val count : counter -> Mtime.span
count c is the monotonic time span elapsed since c was created.

Monotonic clock raw interface


val elapsed_ns : unit -> int64
now_ns () is the unsigned 64-bit integer nanosecond monotonic time span elapsed since the beginning of the program.
Raises Sys_error see error handling
val now_ns : unit -> int64
now_ns () is an unsigned 64-bit integer nanosecond system-relative monotonic timestamp. The absolute value is meaningless.
Raises Sys_error see error handling
val period_ns : unit -> int64 option
period_ns () is the clock's period as an unsigned 64-bit integer nanosecond monotonic time span (if available).

Error handling

The functions Mtime_clock.elapsed, Mtime_clock.now, Mtime_clock.counter, Mtime_clock.elapsed_ns and Mtime_clock.now_ns raise Sys_error whenever they can't determine the current time or that it doesn't fit in Mtime's range. Ususally this exception should only be catched at the toplevel of your program to log it and abort the program. It indicates a serious error condition in the system.

All the other functions, whose functionality is less essential, simply silently return None if they can't determine the information either because it is unavailable or because an error occured.

Platform support