Module Mtime_clock
Contents
Instructions: Use this module in your project
In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:
Add the following to your project's
dependencies/CMakeLists.txt:DkSDKProject_DeclareAvailable(mtime CONSTRAINT "= 2.0.0+dune" FINDLIBS mtime mtime.clock mtime.clock.os mtime.top) DkSDKProject_MakeAvailable(mtime)Add the
Findlib::mtimelibrary to any desired targets insrc/*/CMakeLists.txt:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::mtime)Click your IDE's
Buildbutton
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install mtime.2.0.0+duneEdit your
dune-projectand add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (mtime (>= 2.0.0+dune))))Then run:
dune build *.opam # if this fails, run: dune buildEdit your
<package>.opamfile and add:depends: [ # ... existing dependencies ... "mtime" {>= "2.0.0+dune"} ]Then run:
opam install . --deps-only
FINALLY, add the mtime.clock.os library to any desired (library)and/or (executable) targets in your **/dune files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
mtime.clock.os))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
mtime.clock.os))Monotonic clock
valelapsed : ``unit->Mtime.span
elapsed () is the monotonic time span elapsed since the beginning of
the program.
Raises Sys_error, see error handling
valnow : ``unit->Mtime.t
now () is the current system-relative monotonic timestamp. Its
absolute value is meaningless.
Raises Sys_error, see error handling
valperiod : ``unit->Mtime.spanoption
period () is the clock's period as a monotonic time span (if
available).
Time counters
typecounter
The type for monotonic wall-clock time counters.
valcounter : ``unit->counter
counter () is a counter counting from now on.
Raises Sys_error, see error handling
valcount :counter->Mtime.span
count c is the monotonic time span elapsed since c was created.
Monotonic clock raw interface
valelapsed_ns : ``unit->int64
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
valnow_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
valperiod_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 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_gettimewith CLOCK_BOOTTIME. This means that sleep time is taken into account. - Platforms with a POSIX clock use
clock_gettimewith 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_hooksmodule, which provides an interface compatible to theperformancemodule in browsers.
