package kaun-board

  1. Overview
  2. Docs

Module Sysstat.CpuSource

CPU statistics.

Sourcetype t = {
  1. user : int64;
    (*

    Time spent in user mode.

    *)
  2. nice : int64;
    (*

    Time spent in user mode with low priority (nice).

    *)
  3. system : int64;
    (*

    Time spent in system (kernel) mode.

    *)
  4. idle : int64;
    (*

    Time spent idle.

    *)
  5. iowait : int64;
    (*

    Time spent waiting for I/O to complete (Linux only).

    *)
  6. irq : int64;
    (*

    Time spent servicing interrupts (Linux only).

    *)
  7. softirq : int64;
    (*

    Time spent servicing soft interrupts (Linux only).

    *)
  8. steal : int64;
    (*

    Time stolen by other VMs in virtualized environments (Linux only).

    *)
  9. guest : int64;
    (*

    Time spent running guest VMs (Linux only).

    *)
}

Cumulative CPU time counters in ticks since boot.

All fields represent cumulative time spent in each CPU state. The unit is platform-specific ticks (Linux jiffies or macOS Mach ticks) but is abstracted away by compute.

Platform behavior:

  • macOS: Only user, nice, system, and idle are available; other fields are 0L.
Sourcetype stats = {
  1. user : float;
    (*

    Percentage of time spent in user mode.

    *)
  2. nice : float;
    (*

    Percentage of time spent in user mode with low priority.

    *)
  3. system : float;
    (*

    Percentage of time spent in system mode.

    *)
  4. idle : float;
    (*

    Percentage of time spent idle.

    *)
  5. iowait : float;
    (*

    Percentage of time spent waiting for I/O.

    *)
  6. irq : float;
    (*

    Percentage of time spent servicing interrupts.

    *)
  7. softirq : float;
    (*

    Percentage of time spent servicing soft interrupts.

    *)
  8. steal : float;
    (*

    Percentage of time stolen by hypervisor.

    *)
  9. guest : float;
    (*

    Percentage of time spent running guest VMs.

    *)
}

CPU usage percentages between two samples.

All fields are in the range 0.0 to 100.0, where 100.0 represents full utilization. The sum of all fields equals 100.0.

Sourceval sample : unit -> t

sample () returns aggregate CPU counters across all cores.

  • raises Sys_error

    if CPU statistics are unavailable on the current platform or an error occurs during sampling.

Sourceval sample_per_core : unit -> t array

sample_per_core () returns per-core CPU counters.

The array length equals the number of logical CPU cores.

  • raises Sys_error

    if per-core statistics are unavailable or an error occurs.

Sourceval compute : prev:t -> next:t -> stats

compute ~prev ~next calculates CPU usage percentages between two samples.

Computes the delta for each counter field and converts to percentages of total CPU time elapsed between samples. The sum of all fields in the returned stats equals 100.0.

Returns zero_stats if no time has elapsed between samples (i.e., all counters are identical). This is not an error condition.