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

loadavg

package
v0.72.0 Latest Latest
Warning

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

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

Documentation

Overview

Package loadavg reads the host's 1-minute load average and waits for it to drop, so that a benchmark is not measured on a busy machine.

Linux reads /proc/loadavg (proc(5)). Darwin reads sysctl vm.loadavg, a struct loadavg { fixpt_t ldavg[3]; long fscale; } (xnu sys/resource.h). Every other platform gets a clear error, never a zero.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("load average above the limit")

ErrBusy is wrapped by the error Wait returns when the load stayed above the limit for the whole timeout.

Functions

func Avg1

func Avg1() (float64, error)

Avg1 returns the 1-minute load average.

func Wait

func Wait(ctx context.Context, max float64, timeout, poll time.Duration, onWait func(float64)) (float64, error)

Wait returns the current 1-minute load once it is at most max. With a zero timeout it checks once. Otherwise it polls every poll until timeout has elapsed, then gives up with an error wrapping ErrBusy. onWait, when not nil, is called with each reading that is too high before sleeping.

func WaitFunc

func WaitFunc(ctx context.Context, read func() (float64, error), max float64, timeout, poll time.Duration, onWait func(float64)) (float64, error)

WaitFunc is Wait over a replaceable source of readings.

Types

This section is empty.

Jump to

Keyboard shortcuts

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