Standard library · System and tools

runtime

Facts about the running program: the system, the memory, the uptime and the build options.

import runtime
On this page
  1. Functions

The runtime package is useful for reporting a program's state, on a /health route on a server for instance. The uptime is counted from the moment MarkStart was called.

Free and used memory are available on Linux and Windows only; on other systems those functions return minus one.

Functions

OS

func OS(): str
The name of the operating system.
runtime-Summary.salam
import runtime

func main:
    runtime.MarkStart()
    println runtime.OS().len() > 0, runtime.Arch().len() > 0, runtime.CpuCount() >= 1
    free := runtime.AvailableMemory()
    used := runtime.UsedMemory()
    println runtime.TotalMemory() > 0, free > 0 or free == -1, used >= 0 or used == -1
    println runtime.UptimeMs() >= 0, runtime.UptimeSeconds() >= 0.0
    println runtime.IsAsanBuild(), runtime.IsMemDebugBuild()
    println runtime.IsSafeBuild() or not runtime.IsSafeBuild()
    println runtime.BuildFlags().len() >= 0, runtime.Summary().len() > 0
end
Outputtrue true true true true true true true false false true true true

Arch

func Arch(): str
The name of the processor architecture.

The example for this item is shown with the ones above: runtime-Summary.salam

CpuCount

func CpuCount(): int
The number of processor cores.

The example for this item is shown with the ones above: runtime-Summary.salam

TotalMemory

func TotalMemory(): i64
The system's total memory.

The example for this item is shown with the ones above: runtime-Summary.salam

AvailableMemory

func AvailableMemory(): i64
The system's free memory, or minus one where it is not available.

The example for this item is shown with the ones above: runtime-Summary.salam

UsedMemory

func UsedMemory(): i64
The system's used memory, total minus free, or minus one.

The example for this item is shown with the ones above: runtime-Summary.salam

MarkStart

func MarkStart()
Records the start instant for the uptime; call it at the top of main.

The example for this item is shown with the ones above: runtime-Summary.salam

UptimeMs

func UptimeMs(): i64
The uptime in milliseconds.

The example for this item is shown with the ones above: runtime-Summary.salam

UptimeSeconds

func UptimeSeconds(): f64
The uptime in seconds.

The example for this item is shown with the ones above: runtime-Summary.salam

IsAsanBuild

func IsAsanBuild(): bool
True when the program was built with the ASan memory checker.

The example for this item is shown with the ones above: runtime-Summary.salam

IsMemDebugBuild

func IsMemDebugBuild(): bool
True when the program was built with allocation counting.

The example for this item is shown with the ones above: runtime-Summary.salam

IsSafeBuild

func IsSafeBuild(): bool
True when the program was built with array bounds checking.

The example for this item is shown with the ones above: runtime-Summary.salam

BuildFlags

func BuildFlags(): str
The program's build options as text.

The example for this item is shown with the ones above: runtime-Summary.salam

Summary

func Summary(): str
A few lines summarising all of the above.

The example for this item is shown with the ones above: runtime-Summary.salam