From 1df6ba99c781fc8eeb30a02aab913d10600527ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Wed, 7 Mar 2012 17:11:16 +0100 Subject: Update scheduler_wall_time documentation * Add example on calculating scheduler utilization --- erts/doc/src/erlang.xml | 52 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'erts/doc') diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index fbe7b36163..ed79109bdd 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -4935,17 +4935,51 @@ true scheduler_wall_time -

Returns - [{Scheduler_Id, Scheduler_Worked_Time, Scheduler_Total_Time}], time lapses are since the - the system flag scheduler_wall_time - was set to true. +

Returns a list of tuples with + {SchedulerId, ActiveTime, TotalTime}], where SchedulerId is an integer id of the scheduler, ActiveTime is + the duration the scheduler has been busy. TotalTime is the total time duration since + scheduler_wall_time activation. The time unit is not defined and may be subject to change. scheduler_wall_time should only be used to calculate relative values for scheduler-utilization. ActiveTime can never exceed TotalTime. +

+ +

The definition of a busy scheduler is when it is not idle or not scheduling (selecting) a process or port, meaning; executing process code, executing linked-in-driver or NIF code, garbage collecting or handling any other memory management. +

+ +

Returns undefined if the system flag - scheduler_wall_time is set to false. + scheduler_wall_time is turned off.

+

The list of scheduler information is unsorted and may come in different order - between calls. The time unit is undefined and may be changed and should only be used - to calculate relative utilization. + between calls.

+

Using scheduler_wall_time to calculate scheduler utilization.

+
+> erlang:system_flag(scheduler_wall_time, true).
+false
+> Ts0 = lists:sort(erlang:statistics(scheduler_wall_time)), ok.
+ok
+
+

Some time later we will take another snapshot and calculate scheduler-utilization per scheduler.

+
+> Ts1 = lists:sort(erlang:statistics(scheduler_wall_time)), ok.
+ok
+> lists:map(fun({{I, W0, T0}, {I, W1, T1}}) -> {I, (W1 - W0)/(T1 - T0)} end, lists:zip(Ts0,Ts1)).
+[{1,0.9743474730177548},
+ {2,0.9744843782751444},
+ {3,0.9995902361669045},
+ {4,0.9738012596572161},
+ {5,0.9717956667018103},
+ {6,0.9739235846420741},
+ {7,0.973237033077876},
+ {8,0.9741297293248656}]
+
+

Using the same snapshot to calculate a total scheduler-utilization.

+
+> {W, T} = lists:foldl(fun({{_, W0, T0}, {_, W1, T1}}, {Wi,Ti}) -> 
+	{Wi + (W1 - W0), Ti + (T1 - T0)} end, {0,0}, lists:zip(Ts0,Ts1)), W/T.
+0.9769136803764825
+
+
wall_clock @@ -4965,6 +4999,10 @@ true {2046,11} > statistics(garbage_collection). {85,23961,0} + +

scheduler_wall_time is by default disabled. Use erlang:system_flag(scheduler_wall_time, true) to enable it.

+
+ -- cgit v1.2.3