Module Oclock

module Oclock: sig .. end
Oclock: precise POSIX clock for OCaml

This module gives access to the clock_gettime (2) family of functions to OCaml programs.

If this module allows programs to get time at real- or CPU-time clocks in nanoseconds, the actual precision of the clocks might be much coarser. Also, the resolution of a clock, Oclock.getres should indicate the period of the timer used for this clock, but the actual precision of the clock greatly depends on the CPU (watch out for frequency scaling!) and its time source. You can estimate the precision available on your platform with the shipped example examples/realtime.
Author(s): Mickaƫl Delahaye


type clockid = int 
Clock identifier type

Clock access


val getres : clockid -> int64
Gets the clock's resolution in nanoseconds.
val gettime : clockid -> int64
Gets the clock's time in nanoseconds.
val settime : clockid -> int64 -> unit
Sets the clock's time in nanoseconds.

The three above functions raise Invalid_argument if the clock identifier is not supported, and a Failure if the call fails for any other reason (including permission problems).

Clock identifiers



Standard clock identifiers


val realtime : clockid
Realtime (always valid)
val realtime_coarse : clockid
Faster but less precise realtime clock, through Linux-specific extension CLOCK_REALTIME_COARSE (since 2.6.32) or FreeBSD equivalent CLOCK_REALTIME_FAST. If not available, set to Oclock.realtime.
val monotonic : clockid
Monotonic clock (not subject to system time change)
val monotonic_coarse : clockid
Faster but less precise monotonic clock, through Linux-specific extension CLOCK_MONOTONIC_COARSE (since 2.6.32) or FreeBSD equivalent CLOCK_MONOTONIC_FAST. If not available, set to Oclock.monotonic.
val monotonic_raw : clockid
Linux-specific monotonic clock (since 2.6.28), not subject to NTP adjustements. If not available, set to Oclock.monotonic.
val boottime : clockid
Linux-specific monotonic clock that includes any time the system is suspended (since 2.6.39). If not available, set to Oclock.monotonic.
val process_cputime : clockid option
Current process CPU-time clock (Linux since 2.6.12 and OpenBSD)
val thread_cputime : clockid option
Current thread CPU-time clock (Linux since 2.6.12 and OpenBSD)

Remote clock identifiers


val getcpuclockid : int -> clockid
Gets the CPU-time clock identifier of a process (given its PID).

Raises an Invalid_argument exception if the provided integer is not a valid PID, and a Failure if the calls fails for any other reason (including permission problems).

val pthread_getcpuclockid : int -> clockid
Gets the CPU-time clock identifier of a thread given its pthread identifier, as returned by Thread.id (but only if you use real POSIX threads -thread and not VM threads -vmthread).

Raises an Invalid_argument exception if the provided integer is not a valid thread identifier, and a Failure if the calls fails for any other reason (including permission problems).