Documentation
WASI
clock_time_get

clock_time_get()

Get the time of the specified clock.

Description

The clock_time_get() function is used to retrieve the time of the specified clock. It returns the value of the clock in nanoseconds.

Syntax

  ;;; Note: This is similar to `clock_gettime` in POSIX.
  ;;; Return the time value of a clock.
  (@interface func (export "clock_time_get")
    ;;; The clock for which to return the time.
    (param $id $clockid)
    ;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
    (param $precision $timestamp)
    ;;; The time value of the clock.
    (result $error (expected $timestamp (error $errno)))
  )

Parameters

  • ctx: A mutable reference to the function environment.
  • clock_id: The ID of the clock to query.
  • precision: The maximum amount of error the reading may have.
  • time: A WebAssembly pointer to a memory location where the value of the clock will be written.

Return Value

The function returns an Errno value indicating the success or failure of the operation.

Logging

This function has been instrumented with trace-level logging. It will log the following information:

  • ?clock_id: The ID of the clock being queried.
  • %precision: The maximum amount of error for the reading.

Note

The clock_time_get() function retrieves the time of the specified clock. The time value is returned in nanoseconds and is written to the specified memory location.