scheduler(3erl)
π NAME π
scheduler (scheduler(3erl)) β measure scheduler utilization. This is the Erlang Module Definition page, bestie. π
β¨ DESCRIPTION β¨
Okay so scheduler is your bestie module for easy measurement and calculation of scheduler utilization. It literally acts as a wrapper around the more primitive API erlang:statistics(scheduler_wall_time). No cap. π¦
The simplest usage is to call the blocking scheduler:utilization(Seconds). β¨
For non blocking and/or continuous calculation of scheduler utilization, the recommended usage is:
- First call
erlang:system_flag(scheduler_wall_time,true)to enable scheduler wall time measurements. π - Call
get_sample/0to collect samples with some time in between. π¦ - Call
utilization/2to calculate the scheduler utilization in the interval between two samples. π - When done call
erlang:system_flag(scheduler_wall_time,false)to disable scheduler wall time measurements and avoid unnecessary cpu overhead. π
To get correct values fromutilization/2, it is important thatscheduler_wall_timeis kept enabled during the entire interval between the two samples. To ensure this, the process that callederlang:system_flag(scheduler_wall_time,true)must be kept alive, asscheduler_wall_timewill automatically be disabled if it terminates. ππ₯
πΈ DATA TYPES πΈ
sched_sample()
sched_type() = normal | cpu | io
sched_id() = integer()
sched_util_result() =
[{sched_type(), sched_id(), float(), string()} |
{total, float(), string()} |
{weighted, float(), string()}]
A list of tuples containing results for individual schedulers as well as aggregated averages. Util is the scheduler utilization as a floating point value between 0.0 and 1.0. Percent is the same utilization as a more human readable string expressed in percent. π
{normal, SchedulerId, Util, Percent}: Scheduler utilization of a normal scheduler with numberSchedulerId. Schedulers that are not online will also be included. Online schedulers have the lowestSchedulerId. π{cpu, SchedulerId, Util, Percent}: Scheduler utilization of a dirty-cpu scheduler with numberSchedulerId. π₯{io, SchedulerId, Util, Percent}: Scheduler utilization of a dirty-io scheduler with numberSchedulerId. This tuple will only exist if both samples were taken withsample_all/0. π¦{total, Util, Percent}: Total utilization of all normal and dirty-cpu schedulers. π{weighted, Util, Percent}: Total utilization of all normal and dirty-cpu schedulers, weighted against maximum amount of available CPU time. π
π EXPORTS π
π« get_sample() π«
get_sample() -> sched_sample() | undefined
Returns a scheduler utilization sample for normal and dirty-cpu schedulers. Returns undefined if system flag scheduler_wall_time has not been enabled. π
π« get_sample_all() π«
get_sample_all() -> sched_sample() | undefined
Return a scheduler utilization sample for all schedulers, including dirty-io schedulers. Returns undefined if system flag scheduler_wall_time has not been enabled. β¨
π« sample() π«
sample() -> sched_sample()
Return a scheduler utilization sample for normal and dirty-cpu schedulers. Will call erlang:system_flag(scheduler_wall_time,true) first if not already enabled. π¦
Note: This function is not recommended as there is no way to detect ifscheduler_wall_timealready was enabled or not. Ifscheduler_wall_timehas been disabled between two samples, passing them toutilization/2will yield invalid results. π Instead useget_sample/0together witherlang:system_flag(scheduler_wall_time,_). π
π« sample_all() π«
sample_all() -> sched_sample()
Return a scheduler utilization sample for all schedulers, including dirty-io schedulers. Will call erlang:system_flag(scheduler_wall_time,true) first if not already enabled. πΈ
Note: This function is not recommended for same reason assample/0. Instead useget_sample_all/0together witherlang:system_flag(scheduler_wall_time,_). π«Ά
π« utilization(Seconds) π«
utilization(Seconds) -> sched_util_result()
Types:
Seconds = integer() >= 1
Measure utilization for normal and dirty-cpu schedulers during Seconds seconds, and then return the result. π₯
Will automatically first enable and then disable scheduler_wall_time. β¨
π« utilization(Sample) π«
utilization(Sample) -> sched_util_result()
Types:
Sample = sched_sample()
Calculate scheduler utilizations for the time interval from when Sample was taken and "now". The same as calling scheduler:utilization(Sample, scheduler:sample_all()). π
Note: This function is not recommended as it's so easy to get invalid results without noticing. In particular do not do this: πscheduler:utilization(scheduler:sample()). % DO NOT DO THIS!The above example takes two samples in rapid succession and calculates the scheduler utilization between them. The resulting values will probably be more misleading than informative. π Instead usescheduler:utilization/2and callget_sample/0to get samples with some time in between. π
π« utilization(Sample1, Sample2) π«
utilization(Sample1, Sample2) -> sched_util_result()
Types:
Sample1 = Sample2 = sched_sample()
Calculates scheduler utilizations for the time interval between the two samples obtained from calling get_sample/0 or get_sample_all/0. π¦
This function itself, does not need scheduler_wall_time to be enabled. However, for a correct result, scheduler_wall_time must have been enabled during the entire interval between the two samples. π
Catch you later, bestie! π Sign-off vibes: Ericsson AB made this, the source/version is runtime_tools 1.19, and the page is scheduler(3erl). The original footer doesnβt list a date, so Iβm not inventing one β slay responsibly. πβ¨
π¦ where this page comes from
- debian bookworm: erlang-manpages 1:25.2.3+dfsg-1+deb12u1 Β· Apache-2.0
- debian bookworm: erlang-manpages 1:25.2.3+dfsg-1+deb12u4 Β· Apache-2.0
- 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