Help us shape the future of Go! Take the 2026 Go Developer Survey

procstat

package
v0.69.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package procstat reads and compares two readings of a Linux /proc/stat: how busy the CPUs were between them, and which are the idlest. It is the one home of that arithmetic, shared by cmd/hostload (which reports it) and cmd/abbench (which refuses to start a round on a loaded host).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pick

func Pick(cs []CPUUse, k int) string

Pick returns the k idlest CPUs as a taskset list, "3" or "3,6,4".

Types

type CPUUse

type CPUUse struct {
	ID   int
	Busy float64
}

CPUUse is one CPU's busy fraction over the interval.

func PerCPU

func PerCPU(a, b Snapshot) []CPUUse

PerCPU returns every CPU present in both snapshots, idlest first, ties by number so the choice is stable.

type Snapshot

type Snapshot struct {
	All  Times
	CPUs map[int]Times
}

Snapshot is a whole /proc/stat: the aggregate "cpu" line and each "cpuN".

func Parse

func Parse(data []byte) (Snapshot, error)

Parse reads the cpu lines of a /proc/stat. Fields a kernel does not print (an old one has no steal) are zero.

func ReadFile

func ReadFile(path string) (Snapshot, error)

ReadFile parses the /proc/stat-shaped file at path.

type Times

type Times struct {
	User, Nice, System, Idle, IOWait, IRQ, SoftIRQ, Steal uint64
}

Times is one line of /proc/stat in clock ticks: user, nice, system, idle, iowait, irq, softirq, steal (guest time is already inside user and nice, so it is not added again).

type Usage

type Usage struct {
	Busy, User, Nice, System, IOWait, Steal float64
}

Usage is what happened between two snapshots of one line, as fractions of the elapsed ticks. Busy counts everything but idle and iowait: a CPU waiting on I/O is free to run a benchmark. Steal is reported apart because on a virtual machine it is time the host gave to someone else.

func Between

func Between(a, b Times) Usage

Between is the usage from reading a to reading b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL