package mtime
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=0492fa5f5187b909fe2b0550363c7dcb8cffef963d51072272ef3d876b51e1ddf8de4c4e221cffb0144658fccf6a0dc584a5c8094a4b2208156e43bad5b269d4
doc/mtime_clock/Mtime_clock/index.html
Module Mtime_clock
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.
Monotonic clock
val elapsed : unit -> Mtime.spanelapsed () is the monotonic time span elapsed since the beginning of the program.
Raises Sys_error, see error handling
val now : unit -> Mtime.tnow () is the current system-relative monotonic timestamp. Its absolute value is meaningless.
Raises Sys_error, see error handling
val period : unit -> Mtime.span optionperiod () is the clock's period as a monotonic time span (if available).
Time counters
val counter : unit -> countercounter () is a counter counting from now on.
Raises Sys_error, see error handling
val count : counter -> Mtime.spancount 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
- Platforms with a POSIX clock (includes Linux) use
clock_gettimewith CLOCK_MONOTONIC. - Darwin uses
mach_absolute_time. - 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_hooksmodule, which provides an interface compatible to theperformancemodule in browsers.