Skip to content

Instantly share code, notes, and snippets.

@jonmeredith
Created September 18, 2012 19:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonmeredith/a460a9dbb11698cf01a6 to your computer and use it in GitHub Desktop.
Save jonmeredith/a460a9dbb11698cf01a6 to your computer and use it in GitHub Desktop.
-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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment