package mirage-mtime
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=e5ffba272dd75c9e40ed8ccbbf87d9614345c3adb7bfe95dd170a3c6e367deae
sha512=9ac59431e7e2c38ea66eda555778c2f19ac86665bfa5729a8b991e359cb5c8650b77e715c2c429d94c3cd26a5977b7e55b36e704cf4cb9393c291178792680eb
doc/mirage-mtime.unix/Mirage_mtime/index.html
Module Mirage_mtime
Source
include module type of struct include Mtime_clock end
Monotonic clock
elapsed ()
is the monotonic time span elapsed since the beginning of the program.
Raises Sys_error
, see error handling
now ()
is the current system-relative monotonic timestamp. Its absolute value is meaningless.
Raises Sys_error
, see error handling
period ()
is the clock's period as a monotonic time span (if available).
Time counters
The type for monotonic wall-clock time counters.
counter ()
is a counter counting from now on.
Raises Sys_error
, see error handling
count c
is the monotonic time span elapsed since c
was created.
Monotonic clock raw interface
elapsed_ns ()
is the unsigned 64-bit integer nanosecond monotonic time span elapsed since the beginning of the program.
Raises Sys_error
, see error handling
now_ns ()
is an unsigned 64-bit integer nanosecond system-relative monotonic timestamp. The absolute value is meaningless.
Raises Sys_error
, see error handling
period_ns ()
is the clock's period as an unsigned 64-bit integer nanosecond monotonic time span (if available).
Error handling
The functions elapsed
, now
, counter
, elapsed_ns
and now_ns
raise Sys_error
whenever they can't determine the current time or that it doesn't fit in Mtime
's range. Usually 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
- Linux uses
clock_gettime
with CLOCK_BOOTTIME. This means that sleep time is taken into account. - Platforms with a POSIX clock use
clock_gettime
with CLOCK_MONOTONIC. - Darwin uses
mach_continous_time
. This means that sleep time is taken into account. - Windows uses Performance counters.
- JavaScript uses
performance.now
(consult availability) which returns a double floating point value in milliseconds with resolution up to the microsecond. - JavaScript running on Node.js uses the built-in
perf_hooks
module, which provides an interface compatible to theperformance
module in browsers.