Created
July 21, 2011 07:17
-
-
Save dustin/1096713 to your computer and use it in GitHub Desktop.
Helpful stuff for figuring out what's going on in there...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(user_default). | |
-export([proc_count/1, proc_count/0, | |
proc_mem/2, proc_mem/1, proc_mem/0, | |
matching/2, matching/1]). | |
proc_info(X, Info) -> | |
case proplists:get_value(X, Info) of | |
{proc_lib, init_p, _} -> | |
proc_lib:translate_initial_call(Info); | |
ICall -> ICall | |
end. | |
show_count_dict(D) -> | |
lists:foreach(fun({K,V}) -> io:format("~p: ~p~n", [K, V]) end, | |
lists:keysort(2, | |
dict:fold(fun(K, V, L) -> [{K, V}|L] end, | |
[], D))). | |
count_procs(NameLabel, SizeFun) -> | |
lists:foldl(fun(Pid, D) -> | |
case process_info(Pid) of | |
undefined -> D; | |
Info -> | |
dict:update_counter(proc_info(NameLabel, Info), | |
SizeFun(Info), D) | |
end | |
end, | |
dict:new(), | |
processes()). | |
proc_count(Which) -> | |
show_count_dict(count_procs(Which, fun(_) -> 1 end)). | |
proc_count() -> proc_count(initial_call). | |
proc_mem(FunField, MemField) -> | |
show_count_dict(count_procs(FunField, | |
fun(Info) -> | |
erlang:system_info(wordsize) * | |
proplists:get_value(MemField, Info) | |
end)). | |
proc_mem(FunField) -> proc_mem(FunField, total_heap_size). | |
proc_mem() -> proc_mem(initial_call). | |
matching(Which, Pattern) -> | |
[P || P <- processes(), Pattern == proc_info(Which, process_info(P))]. | |
matching(Pattern) -> matching(initial_call, Pattern). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment