Skip to content

power

stable

System and process information utilities: uptime, wall-clock time in ms and seconds, OS and CPU architecture detection, and a stub battery info function.

use plugin power::{uptime_seconds, process_uptime, system_time_ms, …}
11 functions Systems
/ filter jk navigate Esc clear
Functions (11)
  1. uptime_seconds Process uptime in whole seconds
  2. process_uptime Process uptime in whole seconds (alias)
  3. system_time_ms Unix epoch time in milliseconds
  4. is_windows True if running on Windows
  5. is_linux True if running on Linux
  6. is_macos True if running on macOS
  7. platform_name OS name string
  8. arch_name CPU architecture string
  9. system_time_secs Unix epoch time in seconds
  10. process_uptime_ms Process uptime in milliseconds
  11. estimated_battery_info Battery info stub (always unsupported)

Overview

power is a small, dependency-free window into the running process and the host it lives on. It groups two kinds of stateless queries: timing values — process uptime (captured the first time you ask and reused thereafter) and the current Unix wall-clock time — and build-target facts about the operating system and CPU architecture the binary was compiled for. Every function takes no arguments and returns a plain int, bool, string, or table, so there is no handle to manage and no object to construct.

Reach for power when you need a cheap timestamp, a quick benchmark of a code path, or a branch on the current platform without pulling in a heavier system crate. All functions live as static methods on the power namespace; import the ones you need with use plugin power::{...}. For real battery, memory, or CPU load data, use the sysinfo plugin instead — estimated_battery_info here is a deliberate stub.

Common patterns

Benchmark a block of work using the high-resolution uptime clock:

use plugin power::{process_uptime_ms}

let t0 = process_uptime_ms()
// ... do work ...
let elapsed = process_uptime_ms() - t0
print("work took {elapsed} ms")

Branch on the host platform and architecture:

use plugin power::{platform_name, arch_name, is_windows}

print("target: {platform_name()} / {arch_name()}")
if is_windows() {
    print("using Windows-specific paths")
}

Stamp an event with both wall-clock time and process uptime:

use plugin power::{system_time_ms, uptime_seconds}

print("event at {system_time_ms()} ms (up {uptime_seconds()}s)")

Process uptime in whole seconds

Returns the number of whole seconds since the Zolo process started. The start time is captured on the first call and reused for all subsequent calls, so the value grows monotonically over the life of the process.

use plugin power::{uptime_seconds}

let up = uptime_seconds()
print("Process running for {up} seconds")

Use it to print a periodic heartbeat for a long-running task:

use plugin power::{uptime_seconds}

for i in 0..3 {
    print("tick {i} at {uptime_seconds()}s uptime")
}

Process uptime in whole seconds (alias)

Alias for uptime_seconds. Returns the same value, measured from the same captured start instant.

use plugin power::{process_uptime}

let up = process_uptime()
print("Uptime: {up}s")

Unix epoch time in milliseconds

Returns the current Unix timestamp in milliseconds (milliseconds since 1970-01-01T00:00:00Z). Useful for timestamping events and measuring elapsed wall time.

use plugin power::{system_time_ms}

let start = system_time_ms()
// ... do work ...
let elapsed = system_time_ms() - start
print("Elapsed: {elapsed} ms")

Unlike process_uptime_ms, this reflects real calendar time, so it survives across runs and can be compared against timestamps from other machines:

use plugin power::{system_time_ms}

print("logged at {system_time_ms()}")

True if running on Windows

Returns true when the binary was compiled for Windows.

use plugin power::{is_windows, is_linux}

if is_windows() {
    print("Running on Windows")
} else if is_linux() {
    print("Running on Linux")
}

True if running on Linux

Returns true when the binary was compiled for Linux.

use plugin power::{is_linux}

if is_linux() {
    print("Linux detected")
}

True if running on macOS

Returns true when the binary was compiled for macOS.

use plugin power::{is_macos}

if is_macos() {
    print("macOS detected")
}

OS name string

Returns a lowercase string identifying the operating system. Possible values: "windows", "linux", "macos", "freebsd", "unknown".

use plugin power::{platform_name}

let os = platform_name()
print("Platform: {os}")

It pairs well with a match to pick platform-specific behaviour in one place:

use plugin power::{platform_name}

match platform_name() {
    "windows" => print("use backslash paths"),
    "linux" => print("use forward-slash paths"),
    _ => print("assume POSIX"),
}

CPU architecture string

Returns the CPU architecture of the compiled binary. Possible values: "x86_64", "aarch64", "x86", "arm", "unknown".

use plugin power::{arch_name, platform_name}

print("Running on {arch_name()} / {platform_name()}")

Unix epoch time in seconds

Returns the current Unix timestamp in whole seconds. Use system_time_ms when sub-second resolution is needed.

use plugin power::{system_time_secs}

let ts = system_time_secs()
print("Unix timestamp: {ts}")

Process uptime in milliseconds

Returns the number of milliseconds since the Zolo process started. Provides finer resolution than uptime_seconds for benchmarking short operations.

use plugin power::{process_uptime_ms}

let t0 = process_uptime_ms()
// ... do work ...
let duration = process_uptime_ms() - t0
print("Operation took {duration} ms")

Battery info stub (always unsupported)

Returns a table indicating that battery information is not supported by this plugin. The table has supported: false and reason: "use sysinfo plugin". Use the sysinfo plugin for real battery data.

use plugin power::{estimated_battery_info}

let info = estimated_battery_info()
print("Battery supported: {info["supported"]}")
print("Reason: {info["reason"]}")
enespt-br