This file contains 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
#!/bin/bash | |
# This is a unix wrapper around the erlang vm. It provides the following functionality: | |
# | |
# * Spawns in foreground | |
# * Handle SIGHUP and call RELOADFUNC | |
# * Handle SIGTERM SIGQUIT and SIGINT telling to the vm to quit | |
# * Dies if the vm dies (for example kernel killing because out of memory) | |
# | |
# Forks and improvements are welcome. |
This file contains 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
cat /erl_crash.dump | grep -2 '=proc:' | grep 'Spawned as:' | cut -d: -f2-3 | sort | uniq -c | sort -rn | |
12433 cowboy_protocol:init/4 | |
1033 proc_lib:init_p/5 | |
1024 ranch_acceptor:loop/3 | |
16 application_master:start_it/4 | |
14 erlang:apply/2 | |
10 inet_tcp_dist:do_setup/6 | |
4 inet_tcp_dist:do_accept/6 | |
4 dlhttpc_client:request/10 | |
1 net_kernel:ticker/2 |
This file contains 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
# Parse Erlang Crash Dumps and correlate mailbox size to the currently running | |
# function. | |
# | |
# Once in the procs section of the dump, all processes are displayed with | |
# =proc:<0.M.N> followed by a list of their attributes, which include the | |
# message queue length and the program counter (what code is currently | |
# executing). | |
BEGIN { | |
threshold = 10000 # mailbox size | |
procs = 0 # are we in the =procs entries? |
This file contains 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
f(MostLeaky). | |
MostLeaky = fun(N) -> | |
lists:sublist( | |
lists:usort( | |
fun({K1,V1},{K2,V2}) -> {V1,K1} =< {V2,K2} end, | |
[try | |
{_,Pre} = erlang:process_info(Pid, binary), | |
erlang:garbage_collect(Pid), | |
{_,Post} = erlang:process_info(Pid, binary), | |
{Pid, length(Post)-length(Pre)} |
This file contains 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
%% Convert a crashdump binary back into a regular binary | |
%% Crash dump binary: | |
%% =binary:CFE75808 % <- reference to refc binary | |
%% CA:2A31300D0A24350D0A484D5345540D0... % <- actual binary | |
CDumpBin = fun(Str) -> | |
[Len,Num] = string:tokens(Str, ":"), | |
Src= lists:flatten(["<<16#",Num,":(16#",Len,"*8)>>."]), | |
{ok, Tokens, _}=erl_scan:string(Src), | |
{ok, [Form]} = erl_parse:parse_exprs(Tokens), | |
{value, Val, _} = erl_eval:expr(Form, erl_eval:new_bindings()), |
This file contains 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
erlang:system_flag(scheduler_wall_time, true), | |
f(WallTimeDiff), | |
WallTimeDiff = fun(T1,T2) -> [trunc(100*((Active2-Active1)/(Total2-Total1)))/100 || {{I, Active1, Total1}, {I, Active2, Total2}} <- lists:zip(lists:sort(T1),lists:sort(T2))] end, | |
f(F), put(stime, erlang:statistics(scheduler_wall_time)), | |
F = fun(F,N) -> Old=get(stime), New=erlang:statistics(scheduler_wall_time), put(stime,New), io:format("rt:~p\trq:~p\t\tsched:~w~n", [element(2,erlang:statistics(runtime)), erlang:statistics(run_queue), WallTimeDiff(Old,New)]), timer:sleep(N), F(F,N) end. | |
%% F(F, IntervalInMS). |
This file contains 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
f(Init), f(Loop), f(Stats), f(ShowStats), | |
Init = fun(Delay) -> | |
Ref = erlang:start_timer(Delay, self(), '#delay'), | |
{{input,In},{output,Out}} = erlang:statistics(io), | |
PrevGC = erlang:statistics(garbage_collection), | |
{{Delay,Ref}, {In,Out}, PrevGC} | |
end, | |
Loop = fun(Self,F,N,{{D,R},{OldIn,OldOut},{OldGCs,OldWords,_}}) -> | |
receive | |
{timeout,R,'#delay'} -> |
This file contains 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
f(Window). | |
Window = fun(AttrName, Time,NumProcs) -> | |
Attrs = fun(Name) -> | |
[{Pid, {Attr, Curr, Init}} | |
|| Pid <- processes() -- [self()], | |
[{_, Attr}, {_, Curr}, {_, Init}] <- | |
[process_info(Pid, [Name, current_function, initial_call])]] | |
end, | |
F = fun() -> Attrs(AttrName) end, |
NewerOlder