Guest User

Untitled

a guest
Jan 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. -module(user_default).
  2.  
  3. -export([proc_count/1, proc_count/0,
  4. proc_mem/2, proc_mem/1, proc_mem/0,
  5. matching/2, matching/1]).
  6.  
  7.  
  8. proc_info(X, Info) ->
  9. case proplists:get_value(X, Info) of
  10. {proc_lib, init_p, _} ->
  11. proc_lib:translate_initial_call(Info);
  12. ICall -> ICall
  13. end.
  14.  
  15. show_count_dict(D) ->
  16. lists:foreach(fun({K,V}) -> io:format("~p: ~p~n", [K, V]) end,
  17. lists:keysort(2,
  18. dict:fold(fun(K, V, L) -> [{K, V}|L] end,
  19. [], D))).
  20.  
  21. count_procs(NameLabel, SizeFun) ->
  22. lists:foldl(fun(Pid, D) ->
  23. case process_info(Pid) of
  24. undefined -> D;
  25. Info ->
  26. dict:update_counter(proc_info(NameLabel, Info),
  27. SizeFun(Info), D)
  28. end
  29. end,
  30. dict:new(),
  31. processes()).
  32.  
  33. proc_count(Which) ->
  34. show_count_dict(count_procs(Which, fun(_) -> 1 end)).
  35.  
  36. proc_count() -> proc_count(initial_call).
  37.  
  38. proc_mem(FunField, MemField) ->
  39. show_count_dict(count_procs(FunField,
  40. fun(Info) ->
  41. erlang:system_info(wordsize) *
  42. proplists:get_value(MemField, Info)
  43. end)).
  44.  
  45. proc_mem(FunField) -> proc_mem(FunField, total_heap_size).
  46.  
  47. proc_mem() -> proc_mem(initial_call).
  48.  
  49. matching(Which, Pattern) ->
  50. [P || P <- processes(), Pattern == proc_info(Which, process_info(P))].
  51.  
  52. matching(Pattern) -> matching(initial_call, Pattern).
Add Comment
Please, Sign In to add comment