summaryrefslogtreecommitdiff
path: root/lib/runtime_tools/src/observer_backend.erl
diff options
context:
space:
mode:
authorSiri Hansen <siri@erlang.org>2013-02-26 11:05:51 +0100
committerSiri Hansen <siri@erlang.org>2013-03-04 11:05:33 +0100
commit999e827ed1d9b5c966af2fc7480e57d2b60b7b09 (patch)
tree1e4b6fbfdeb7eed4074661c75566f13946c31e96 /lib/runtime_tools/src/observer_backend.erl
parent0756a6676d465862056a0fb0969eee827f1a844d (diff)
downloaderlang-999e827ed1d9b5c966af2fc7480e57d2b60b7b09.tar.gz
[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/runtime_tools/src/observer_backend.erl')
-rw-r--r--lib/runtime_tools/src/observer_backend.erl30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/runtime_tools/src/observer_backend.erl b/lib/runtime_tools/src/observer_backend.erl
index e8c9b50c33..d1d291d5cb 100644
--- a/lib/runtime_tools/src/observer_backend.erl
+++ b/lib/runtime_tools/src/observer_backend.erl
@@ -217,15 +217,39 @@ fetch_stats_loop(Parent, Time) ->
%% etop backend
%%
etop_collect(Collector) ->
+ %% If this is the first time and the scheduler_wall_time flag is
+ %% false, SchedulerWallTime will be 'undefined' (and show 0 cpu
+ %% utilization in etop). Next time the flag will be true and then
+ %% there will be a measurement.
+ SchedulerWallTime = erlang:statistics(scheduler_wall_time),
+
+ %% Turn off the flag while collecting data per process etc.
+ case erlang:system_flag(scheduler_wall_time,false) of
+ false ->
+ %% First time and the flag was false - start a monitoring
+ %% process to set the flag back to false when etop is stopped.
+ spawn(fun() -> flag_holder_proc(Collector) end);
+ _ ->
+ ok
+ end,
+
ProcInfo = etop_collect(processes(), []),
+
Collector ! {self(),#etop_info{now = now(),
n_procs = length(ProcInfo),
run_queue = erlang:statistics(run_queue),
- wall_clock = erlang:statistics(wall_clock),
- runtime = erlang:statistics(runtime),
+ runtime = SchedulerWallTime,
memi = etop_memi(),
procinfo = ProcInfo
- }}.
+ }},
+ erlang:system_flag(scheduler_wall_time,true).
+
+flag_holder_proc(Collector) ->
+ Ref = erlang:monitor(process,Collector),
+ receive
+ {'DOWN',Ref,_,_,_} ->
+ erlang:system_flag(scheduler_wall_time,false)
+ end.
etop_memi() ->
try