cpu_sup(3erl)
π cpu_sup(3erl) β A CPU Load and CPU Utilization Supervisor Process π
Erlang Module Definition, bestie β and yeah, the manual name is cpu_sup(3erl), folded right up here at the top so we don't have to squint at a header line. We're about to get into CPU load, CPU utilization, and all the little exports. π
β¨ NAME β¨
cpu_supβ A CPU Load and CPU Utilization Supervisor Process
πΈ DESCRIPTION πΈ
Okay so cpu_sup is a process that supervises the CPU load and CPU utilization. It's part of the OS_Mon application β see os_mon(7) for that whole situation. It's available for Unix, although the CPU utilization values (util/0,1) are only available for Solaris, Linux and FreeBSD. π
The load values are proportional to how long time a runnable Unix process has to spend in the run queue before it is scheduled. So higher values mean more system load β lowkey obvious, but still. The returned value divided by 256 produces the figure displayed by rup and top. What is displayed as 2.00 in rup, is displayed as load up to the second mark in xload.
For example, rup displays a load of 128 as 0.50, and 512 as 2.00.
If the user wants to view load values as percentage of machine capacity, then this way of measuring presents a problem, because the load values are not restricted to a fixed interval. In this case, the following simple mathematical transformation can produce the load value as a percentage:
PercentLoad = 100 * (1 - D/(D + Load))
D determines which load value should be associated with which percentage. Choosing D = 50 means that 128 is 60% load, 256 is 80%, 512 is 90%, and so on.
Another way of measuring system load is to divide the number of busy CPU cycles by the total number of CPU cycles. This produces values in the 0-100 range immediately. However, this method hides the fact that a machine can be more or less saturated. CPU utilization is therefore a better name than system load for this measure.
A server which receives just enough requests to never become idle will score a CPU utilization of 100%. If the server receives 50% more requests, it will still score 100%. When the system load is calculated with the percentage formula shown previously, the load will increase from 80% to 87%.
The avg1/0, avg5/0, and avg15/0 functions can be used for retrieving system load values, and the util/0 and util/1 functions can be used for retrieving CPU utilization values.
When run on Linux, cpu_sup assumes that the /proc file system is present and accessible by cpu_sup. If it is not, cpu_sup will terminate. π
π οΈ EXPORTS π οΈ
π nprocs() -> UnixProcesses | {error, Reason}
Types:
UnixProcesses = int()
Reason = term()
Returns the number of UNIX processes running on this machine. This is a crude way of measuring the system load, but it may be of interest in some cases.
Returns 0 if cpu_sup is not available.
π avg1() -> SystemLoad | {error, Reason}
Types:
SystemLoad = int()
Reason = term()
Returns the average system load in the last minute, as described above. 0 represents no load, 256 represents the load reported as 1.00 by rup.
Returns 0 if cpu_sup is not available.
π avg5() -> SystemLoad | {error, Reason}
Types:
SystemLoad = int()
Reason = term()
Returns the average system load in the last five minutes, as described above. 0 represents no load, 256 represents the load reported as 1.00 by rup.
Returns 0 if cpu_sup is not available.
π avg15() -> SystemLoad | {error, Reason}
Types:
SystemLoad = int()
Reason = term()
Returns the average system load in the last 15 minutes, as described above. 0 represents no load, 256 represents the load reported as 1.00 by rup.
Returns 0 if cpu_sup is not available.
π util() -> CpuUtil | {error, Reason}
Types:
CpuUtil = float()
Reason = term()
Returns CPU utilization since the last call to util/0 or util/1 by the calling process.
Note: The returned value of the first call toutil/0orutil/1by a process will on most systems be the CPU utilization since system boot, but this is not guaranteed and the value should therefore be regarded as garbage. This also applies to the first call after a restart ofcpu_sup.
The CPU utilization is defined as the sum of the percentage shares of the CPU cycles spent in all busy processor states (see util/1 below) in average on all CPUs.
Returns 0 if cpu_sup is not available.
π util(Opts) -> UtilSpec | {error, Reason}
Types:
Opts = [detailed | per_cpu]
UtilSpec = UtilDesc | [UtilDesc]
UtilDesc = {Cpus, Busy, NonBusy, Misc}
Cpus = all | int() | [int()]()
Busy = NonBusy = {State, Share} | Share
State = user | nice_user | kernel
| wait | idle | atom()
Share = float()
Misc = []
Reason = term()
Returns CPU utilization since the last call to util/0 or util/1 by the calling process, in more detail than util/0.
Note: The returned value of the first call toutil/0orutil/1by a process will on most systems be the CPU utilization since system boot, but this is not guaranteed and the value should therefore be regarded as garbage. This also applies to the first call after a restart ofcpu_sup.
Currently recognized options:
detailedβ The returnedUtilDesc(s)will be even more detailed.per_cpuβ Each CPU will be specified separately (assuming this information can be retrieved from the operating system), that is, a list with oneUtilDescper CPU will be returned.
Description of UtilDesc = {Cpus, Busy, NonBusy, Misc}:
Cpusβ If thedetailedand/orper_cpuoption is given, this is the CPU number, or a list of the CPU numbers. If not, this is the atomallwhich implies that theUtilDesccontains information about all CPUs.Busyβ If thedetailedoption is given, this is a list of{State, Share}tuples, where each tuple contains information about a processor state that has been identified as a busy processor state (see below). The atomStateis the name of the state, and the floatSharerepresents the percentage share of the CPU cycles spent in this state since the last call toutil/0orutil/1. If not, this is the sum of the percentage shares of the CPU cycles spent in all states identified as busy. If theper_cpuis not given, the value(s) presented are the average of all CPUs.NonBusyβ Similar toBusy, but for processor states that have been identified as non-busy (see below).Miscβ Currently unused; reserved for future use.
Currently these processor states are identified as busy:
userβ Executing code in user mode.nice_userβ Executing code in low priority (nice) user mode. This state is currently only identified on Linux.kernelβ Executing code in kernel mode.
Currently these processor states are identified as non-busy:
waitβ Waiting. This state is currently only identified on Solaris.idleβ Idle.
Note: Identified processor states may be different on different operating systems and may change between different versions ofcpu_supon the same operating system. The sum of the percentage shares of the CPU cycles spent in all busy and all non-busy processor states will always add up to100%, though.
Returns {all,0,0,[]} if cpu_sup is not available.
π SEE ALSO π
os_mon(3erl)
Cute sign-off, bestie: the footer corner is Ericsson AB, os_mon 2.8.2, and cpu_sup(3erl) β that's the source/version/date situation as it appears, no extra date line in this one. π«Άπ
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms