Module Mtime

Contents

Instructions: Use this module in your project

In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:

  1. Add the following to your project's dependencies/CMakeLists.txt:

    Copy
    DkSDKProject_DeclareAvailable(mtime
        CONSTRAINT "= 2.0.0+dune"
        FINDLIBS mtime mtime.clock mtime.clock.os mtime.top)
    DkSDKProject_MakeAvailable(mtime)
  2. Add the Findlib::mtime library to any desired targets in src/*/CMakeLists.txt:

    Copy
    target_link_libraries(YourPackage_YourLibraryName
         # ... existing libraries, if any ...
         Findlib::mtime)
  3. Click your IDE's Build button

Not using DkSDK?

FIRST, do one or all of the following:

  1. Run:

    Copy
    opam install mtime.2.0.0+dune
  2. Edit your dune-project and add:

    Copy
    (package
      (name YourExistingPackage)
      (depends
      ; ... existing dependenices ...
      (mtime (>= 2.0.0+dune))))

    Then run:

    Copy
    dune build *.opam # if this fails, run: dune build
  3. Edit your <package>.opam file and add:

    Copy
    depends: [
      # ... existing dependencies ...
      "mtime" {>= "2.0.0+dune"}
    ]

    Then run:

    Copy
    opam install . --deps-only

FINALLY, add the mtime library to any desired (library)and/or (executable) targets in your **/dune files:

Copy
(library
  (name YourLibrary)
  ; ... existing library options ...
  (libraries
    ; ... existing libraries ...
    mtime))

(executable
  (name YourExecutable)
  ; ... existing executable options ...
  (libraries
    ; ... existing libraries ...
    mtime))

Monotonic time spans

type span

The type for non-negative monotonic time spans. They represent the difference between two monotonic clock readings. If the platform's clock has nanosecond resolution the representation guarantees that the function Mtime_clock.elapsed can measure up to approximatively 584 Julian year spans before silently rolling over (unlikely since this is in a single program run).

module Span:sig...end

Monotonic time spans.

Monotonic timestamps

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

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

valto_uint64_ns :t -> int64

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

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

valmin_stamp :t

min_stamp is the earliest timestamp.

valmax_stamp :t

max_stamp is the latest timestamp.

Predicates

valequal :t -> t -> bool

equal t t' is true iff t and t' are equal.

valcompare :t -> t -> int

compare t t' orders timestamps by increasing time.

valis_earlier :t -> ``than:t -> bool

is_earlier t ~than is true iff t occurred before than.

valis_later :t -> ``than:t -> bool

is_later t ~than is true iff t occurred after than.

Arithmetic

valspan :t -> t -> span

span t t' is the span between t and t' regardless of the order between t and t'.

valadd_span :t -> span -> t option

add_span t s is the timestamp s units later than t or None if the result overflows.

valsub_span :t -> span -> t option

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

Formatting

valpp :Stdlib.Format.formatter -> t -> unit

pp formats t as an unsigned 64-bit integer nanosecond timestamp. Note that the absolute value is meaningless.

valdump :Stdlib.Format.formatter -> t -> unit

dump ppf t formats an unspecified raw representation of t on ppf.