Skip to content

Commit

Permalink
Add system_stats: a small module that collects beam statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
meeusr committed Aug 26, 2012
1 parent 6b1c2f0 commit aa49670
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system_stats.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-module(system_stats).
-export([get_total/1,get_all/0]).

get_total(Type) ->
List = [ element(2,lists:keyfind(Type,1,erlang:process_info(F))) || F <- erlang:processes()],
lists:foldl(fun(X, Sum) -> X + Sum end, 0, List).

get_all() ->
[{context_switches,element(1,erlang:statistics(context_switches))},
{run_queue,erlang:statistics(run_queue)},
{process_count,erlang:system_info(process_count)},
{exact_reductions,element(1,erlang:statistics(exact_reductions))} |
[{Atom,get_total(Atom)} || Atom <- [heap_size,stack_size,message_queue_len,reductions]]
].

0 comments on commit aa49670

Please sign in to comment.