aboutsummaryrefslogtreecommitdiffstats
path: root/lib/observer
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2013-02-26 11:05:51 +0100
committerSiri Hansen <[email protected]>2013-03-04 11:05:33 +0100
commit999e827ed1d9b5c966af2fc7480e57d2b60b7b09 (patch)
tree1e4b6fbfdeb7eed4074661c75566f13946c31e96 /lib/observer
parent0756a6676d465862056a0fb0969eee827f1a844d (diff)
downloadotp-999e827ed1d9b5c966af2fc7480e57d2b60b7b09.tar.gz
otp-999e827ed1d9b5c966af2fc7480e57d2b60b7b09.tar.bz2
otp-999e827ed1d9b5c966af2fc7480e57d2b60b7b09.zip
[observer] Improve measurement of CPU utilization in etop
Now using scheduler_wall_time instead of runtime/wall_clock to get cpu utilization. The old version could give CPU utilization far beyond 100%. Also, a bug which sometimes gave a badarith when calculating the CPU utilization is corrected.
Diffstat (limited to 'lib/observer')
-rw-r--r--lib/observer/src/etop.erl35
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/observer/src/etop.erl b/lib/observer/src/etop.erl
index 428757e5ce..2610060eae 100644
--- a/lib/observer/src/etop.erl
+++ b/lib/observer/src/etop.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2002-2012. All Rights Reserved.
+%% Copyright Ericsson AB 2002-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -325,13 +325,40 @@ loadinfo(SysI) ->
#etop_info{n_procs = Procs,
run_queue = RQ,
now = Now,
- wall_clock = {_, WC},
- runtime = {_, RT}} = SysI,
- Cpu = round(100*RT/WC),
+ wall_clock = WC,
+ runtime = RT} = SysI,
+ Cpu = calculate_cpu_utilization(WC,RT),
Clock = io_lib:format("~2.2.0w:~2.2.0w:~2.2.0w",
tuple_to_list(element(2,calendar:now_to_datetime(Now)))),
{Cpu,Procs,RQ,Clock}.
+calculate_cpu_utilization({_,WC},{_,RT}) ->
+ %% Old version of observer_backend, using statistics(wall_clock)
+ %% and statistics(runtime)
+ case {WC,RT} of
+ {0,0} ->
+ 0;
+ {0,_} ->
+ 100;
+ _ ->
+ round(100*RT/WC)
+ end;
+calculate_cpu_utilization(_,undefined) ->
+ %% First time collecting - no cpu utilization has been measured
+ %% since scheduler_wall_time flag is not yet on
+ 0;
+calculate_cpu_utilization(_,RTInfo) ->
+ %% New version of observer_backend, using statistics(scheduler_wall_time)
+ Sum = lists:foldl(fun({_,A,T},{AAcc,TAcc}) -> {A+AAcc,T+TAcc} end,
+ {0,0},
+ RTInfo),
+ case Sum of
+ {0,0} ->
+ 0;
+ {Active,Total} ->
+ round(100*Active/Total)
+ end.
+
meminfo(MemI, [Tag|Tags]) ->
[round(get_mem(Tag, MemI)/1024)|meminfo(MemI, Tags)];
meminfo(_MemI, []) -> [].