cpu_sup(3)

๐Ÿ“ฆ
version 29.0.6 ยท 2 versions
, in nixos 26.05, nixpkgs unstable, ubuntu stonking

โœจ cpu_sup ๐Ÿ’…โœจ

okay bestie, this is cpu_sup(3) from the Erlang Module Definition section, and it's brought to you by the os_mon girlies. let's get into it ๐Ÿซถ

๐ŸŒธ NAME ๐ŸŒธ

cpu_sup โ€” a CPU Load and CPU Utilization Supervisor Process ๐Ÿ‘‘


๐Ÿ’– DESCRIPTION ๐Ÿ’–

so cpu_sup is literally a process that supervises the CPU load and CPU utilization. it's part of the OS_Mon application โ€” go peek at os_mon(6) if you want the lore. it's available for Unix, but the CPU utilization values (util/0,1) are only available on Solaris, Linux, FreeBSD and OpenBSD. not everywhere, okay? know the vibe of your platform ๐Ÿ’…

The load values are proportional to how long a runnable Unix process has to sit in the run queue before it gets scheduled. so basically: higher value = more system load. The returned value divided by 256 gives you the figure that rup and top display. what shows up as 2.00 in rup is the load up to the second mark in xload. slay.

for example, rup displays a load of 128 as 0.50, and 512 as 2.00. math is mathing โœจ

Now, if you wanna view load values as a percentage of machine capacity, this whole measuring thing presents a problem, because the load values are not restricted to a fixed interval ๐Ÿ˜ญ. In that case, this simple little transformation can turn your load value into a percentage:

PercentLoad = 100 * (1 - D/(D + Load))

D decides which load value gets associated with which percentage. pick D = 50 and that means 128 is 60% load, 256 is 80%, 512 is 90%, and so on. obsessed.

Another way to measure system load is to divide the number of busy CPU cycles by the total number of CPU cycles. that one gives you values in the 0-100 range immediately. however โ€” and this is the tea ๐Ÿต โ€” this method hides the fact that a machine can be more or less saturated. so CPU utilization is honestly a better name than "system load" for this measure, no cap.

A server that receives just enough requests to never become idle will score a CPU utilization of 100%. if it receives 50% more requests, it will still score 100% ๐Ÿ’€. but when you calculate system load with that percentage formula from earlier, the load increases from 80% to 87%. see the difference? that's the whole point.

The avg1/0, avg5/0, and avg15/0 functions are your girls for retrieving system load values, and util/0 and util/1 are the ones for CPU utilization values. iykyk ๐Ÿงš

โš ๏ธ heads up: when running on Linux, cpu_sup assumes the /proc file system is present and accessible by cpu_sup. if it's not, cpu_sup will terminate. so like... make sure /proc exists, bestie ๐Ÿ™ˆ

๐Ÿ‘€ See Also

os_mon(3)


๐Ÿฆ‹ DATA TYPES ๐Ÿฆ‹

util_cpus() :: all | integer() | [integer()].

util_desc() :: {util_cpus(), util_value(), util_value(), []}.

util_state() :: user | nice_user | kernel | wait | idle.

util_value() :: [{util_state(), number()}] | number().

โœจ FUNCTIONS โœจ

avg1() -> SystemLoad :: integer() | {error, any()}.

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.

avg15() -> SystemLoad :: integer() | {error, any()}.

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.

avg5() -> SystemLoad :: integer() | {error, any()}.

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.

nprocs() -> UnixProcesses :: integer() | {error, any()}.

Returns the number of UNIX processes running on this machine. it's a crude way of measuring the system load, but ngl it may be of interest in some cases ๐Ÿคท

Returns 0 if cpu_sup is not available.

util() -> CpuUtil :: number() | {error, any()}.

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 to util/0 or util/1 by a process will on most systems be the CPU utilization since system boot โ€” but this is not guaranteed, so you should regard that value as garbage ๐Ÿ’€. this also applies to the first call after a restart of cpu_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) in average on all CPUs.

Returns 0 if cpu_sup is not available.

util([detailed | per_cpu]) -> util_desc() | [util_desc()] | {error, any()}.

Returns CPU utilization since the last call to util/0 or util/1 by the calling process โ€” but with more detail than util/0. she's giving main character energy ๐Ÿ‘‘

โš ๏ธ NOTE: same deal as before, bestie โ€” the returned value of the first call to util/0 or util/1 by a process will on most systems be the CPU utilization since system boot, but this is not guaranteed, so that value should be regarded as garbage. this also applies to the first call after a restart of cpu_sup ๐Ÿ™ˆ

Currently recognized options:

  • detailed โ€” the returned UtilDesc(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 one UtilDesc per CPU will be returned ๐ŸŒˆ

Description of UtilDesc = {Cpus, Busy, NonBusy, Misc}:

  • Cpus โ€” if the detailed and/or per_cpu option is given, this is the CPU number, or a list of the CPU numbers. if not, this is the atom all, which implies that the UtilDesc contains information about all CPUs.
  • Busy โ€” if the detailed option 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 atom State is the name of the state, and the float Share represents the percentage share of the CPU cycles spent in this state since the last call to util/0 or util/1. if not, this is the sum of the percentage shares of the CPU cycles spent in all states identified as busy. and if per_cpu is not given, the value(s) presented are the average of all CPUs.
  • NonBusy โ€” similar to Busy, 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 even change between different versions of cpu_sup on the same operating system. however, the sum of the percentage shares of the CPU cycles spent in all busy and all non-busy processor states will always add up to 100%. that part is guaranteed, periodt ๐Ÿ’…

Returns {all,0,0,[]} if cpu_sup is not available.


๐Ÿซถ and that's the whole page, bestie!! this beauty came to you from Ericsson AB, running os_mon 2.12, filed under cpu_sup(3). go forth and monitor those CPU cycles, you absolute icon ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from