Std.System (Cure Standard Library v0.37.2)

View Source

System operations: time, process identity, node info, exit.

Light wrappers around :erlang and :os BIFs. exit/1 halts the whole BEAM node -- use with care.

Examples

use Std.System

cpu_count()                             # e.g. 8
timestamp_ms() > 0                      # => true
node() == :nonode@nohost                # true without -sname

Summary

Types

Group tag consumed by Cure.Stdlib.Preload. Units accepted by BEAM wall-clock time operations. Constructors are translated at the private foreign boundary; callers cannot pass an arbitrary atom that :os.system_time/1 does not understand.

Functions

Number of logical processors available to the VM.

Halt never reports a meaningful atom to its caller. The raw declaration records BEAM's boundary shape; this safe surface communicates that there is no result to inspect if a host substitutes or intercepts the call.

Native monotonic-time reading in implementation-defined units. Use for measuring durations (a - b is meaningful); not wall-clock.

Atom name of the local node.

Running OTP release version, e.g. "27".

Halt the whole BEAM node with the given exit status.

:erlang.system_info/1 answers a different shape for every key, so it gets one private extern per key rather than a single polymorphic declaration: an @extern is a direct remote call with no marshalling, so an unconstrained -> t would let any caller claim any type for the BIF's result.

OS wall-clock time in unit (typically :second, :millisecond, :microsecond, or :nanosecond).

OS wall-clock time in unit, typed.

Current millisecond timestamp since the Unix epoch.

Current microsecond timestamp since the Unix epoch.

Types

enum TimeUnit

 enum TimeUnit
   Second
   Millisecond
   Microsecond
   Nanosecond

Group tag consumed by Cure.Stdlib.Preload. Units accepted by BEAM wall-clock time operations. Constructors are translated at the private foreign boundary; callers cannot pass an arbitrary atom that :os.system_time/1 does not understand.

Functions

cpu_count() -> Int

 fn cpu_count() -> Int

Number of logical processors available to the VM.

exit(code: Int) -> Unit

 fn exit(code: Int) -> Unit

Halt never reports a meaningful atom to its caller. The raw declaration records BEAM's boundary shape; this safe surface communicates that there is no result to inspect if a host substitutes or intercepts the call.

monotonic_time() -> Int

 fn monotonic_time() -> Int

Native monotonic-time reading in implementation-defined units. Use for measuring durations (a - b is meaningful); not wall-clock.

node() -> Atom

 fn node() -> Atom

Atom name of the local node.

otp_version() -> String

 fn otp_version() -> String

Running OTP release version, e.g. "27".

raw_exit(code: Int) -> Atom

 fn raw_exit(code: Int) -> Atom

Halt the whole BEAM node with the given exit status.

raw_logical_processors(key: Atom) -> Int

 fn raw_logical_processors(key: Atom) -> Int

raw_otp_release(key: Atom) -> List(Char)

 fn raw_otp_release(key: Atom) -> List(Char)

:erlang.system_info/1 answers a different shape for every key, so it gets one private extern per key rather than a single polymorphic declaration: an @extern is a direct remote call with no marshalling, so an unconstrained -> t would let any caller claim any type for the BIF's result.

:otp_release answers a code-point list. List(Char) erases to a bare charlist, which is exactly that; nominal String erases to the tagged pair {String, chars}, which the BIF does not build -- so the extern is declared at List(Char) and otp_version wraps.

raw_system_time(unit: Atom) -> Int

 fn raw_system_time(unit: Atom) -> Int

OS wall-clock time in unit (typically :second, :millisecond, :microsecond, or :nanosecond).

system_time(unit: TimeUnit) -> Int

 fn system_time(unit: TimeUnit) -> Int

OS wall-clock time in unit, typed.

The typed counterpart of raw_system_time/1: converts the TimeUnit constructor to its BEAM atom and delegates. Prefer this over the raw extern at call sites.

time_unit_atom(unit: TimeUnit) -> Atom

 fn time_unit_atom(unit: TimeUnit) -> Atom

timestamp_ms() -> Int

 fn timestamp_ms() -> Int

Current millisecond timestamp since the Unix epoch.

timestamp_us() -> Int

 fn timestamp_us() -> Int

Current microsecond timestamp since the Unix epoch.