Sys.Linux.Cgroup.V2.CpuStat (Hyper v0.1.0)

Copy Markdown View Source

Reads a cgroup v2 cpu.stat interface file — the cumulative CPU time the cgroup's processes have actually executed since the cgroup was created.

usage_usec only advances while a process in the cgroup is on-CPU, so an idle cgroup's counter stands still: it measures compute performed, not compute allocated. A single reading is meaningless on its own; consumption over a window is the delta between two readings (see Hyper.Node.FireVMM.Meter).

Laws under test: a rendered payload round-trips usage_usec/user_usec/ system_usec regardless of line order or unknown lines; a payload without usage_usec is always refused.

Summary

Functions

Parse a cpu.stat payload. Refuses a payload without a well-formed usage_usec — the billing counter must never silently read as zero.

Read and parse <cgroup_dir>/cpu.stat.

Types

t()

@type t() :: %Sys.Linux.Cgroup.V2.CpuStat{
  system: Unit.Time.t(),
  usage: Unit.Time.t(),
  user: Unit.Time.t()
}

Functions

parse(content)

@spec parse(String.t()) :: {:ok, t()} | {:error, :missing_usage}

Parse a cpu.stat payload. Refuses a payload without a well-formed usage_usec — the billing counter must never silently read as zero.

read(cgroup_dir)

@spec read(Path.t()) :: {:ok, t()} | {:error, File.posix() | :missing_usage}

Read and parse <cgroup_dir>/cpu.stat.