secret
Created

  • Download Gist
schedstat.erl
Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
-module(schedstat).
-export([run/0,run/1]).
 
run() ->
run(1000).
 
run(Samples) ->
spawn(fun() ->
erlang:trace(all, true, [running,scheduler_id]),
Tid = ets:new(?MODULE, [private]),
[ets:insert(Tid, {S, 0}) || S <- lists:seq(1, erlang:system_info(schedulers))],
loop(Tid, Samples)
end).
 
 
loop(Tid, 0) ->
io:format("=== in scheduler count===\n~p\n", [lists:sort(ets:tab2list(Tid))]);
loop(Tid, Times) ->
receive
{trace,_Pid,in,Sched,_MFArity} ->
ets:update_counter(Tid, Sched, {2, 1}),
loop(Tid, Times - 1);
_ ->
loop(Tid, Times - 1)
after
5000 ->
loop(Tid, 0)
end.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.