Skip to content

Instantly share code, notes, and snippets.

View ferd's full-sized avatar
☢️
This place is not a place of honor… no highly esteemed deed is commemorated here

Fred Hebert ferd

☢️
This place is not a place of honor… no highly esteemed deed is commemorated here
View GitHub Profile
@ferd
ferd / gist:8702796
Last active August 29, 2015 13:55
Trace a given M:F/A with tracer BIFs for N times
f(Clear), Clear = fun() ->
erlang:trace(all, false, [all]),
erlang:trace_pattern({'_','_','_'}, false, [local,meta,call_count,call_time]),
erlang:trace_pattern({'_','_','_'}, false, []) % unsets global
end.
f(TraceCall),
TraceCall = fun(Mod, Fun, Arg, Max) when Mod =/= '_' ->
Clear(),
case whereis(recon_tracer) of
undefined ->
→ traceroute i.imgur.com
traceroute to i.imgur.com (103.31.7.34), 64 hops max, 52 byte packets
1 my.router (192.168.1.1) 1.572 ms 1.225 ms 1.189 ms
2 10.7.0.1 (10.7.0.1) 9.616 ms 14.129 ms 9.639 ms
3 10.170.165.201 (10.170.165.201) 17.612 ms 18.071 ms 20.427 ms
4 10.170.165.201 (10.170.165.201) 17.860 ms 21.767 ms 16.859 ms
5 * 10.10.11.254 (10.10.11.254) 556.853 ms 2232.299 ms
6 ia-piex-gw02-fe5-1-0.vtl.net (216.113.14.174) 20.418 ms 22.980 ms 19.020 ms
7 207.96.210.159 (207.96.210.159) 28.456 ms 21.729 ms 32.195 ms
8 216.113.123.249 (216.113.123.249) 40.840 ms 50.339 ms *
@ferd
ferd / monitors.erl
Last active June 29, 2018 03:16
Monitor long scheduling, long gc, and busy distributed ports
F = fun(F) ->
receive
{monitor, Pid, long_schedule, Info} -> io:format(user, "monitor=long_schedule pid=~p info=~p~n", [Pid, Info]);
{monitor, Pid, busy_dist_port, Port} -> io:format(user, "monitor=busy_dist_port pid=~p port=~p~n" ,[Pid, Port]);
{monitor, Pid, long_gc, Info} -> io:format(user, "monitor=long_gc pid=~p info=~p~n", [Pid, Info])
end,
F(F)
end.
Setup = fun() -> register(temp_sys_monitor, self()), erlang:system_monitor(self(), [{long_schedule, 1000}, busy_dist_port, {long_gc, 1000}]), F(F) end.
recon:rpc(fun() -> spawn(Setup) end).
@ferd
ferd / recon:port_info.erl
Created September 23, 2013 01:41
tiny demo of the port_info function from recon
1> {ok,Port}=gen_tcp:connect("google.com", 80, []),
1> gen_tcp:send(Port,"GET /"),
1> recon:port_info(Port). % also: recon:port_info("#Port<0.826>") or recon:port_info(826)
[{meta,[{id,6672},
{name,"tcp_inet"},
{os_pid,undefined},
{parallelism,false}]},
{signals,[{connected,<0.48.0>},
{links,[<0.48.0>]},
{monitors,[]}]},
@ferd
ferd / gist:6380600
Created August 29, 2013 16:53
show all log info related to lager's mailbox size over an entire cluster sorted by message_queue_len, including node names.
1> recon_lib:time_fold(
N=1000, Delay=10000,
fun(_) -> {lists:usort(fun({_,X}, {_,Y}) -> X > Y end,
element(1, recon:named_rpc(
fun() -> erlang:process_info(whereis(lager_event), message_queue_len) end)
)),
nostate}
end,
nostate,
fun(Vals,_) -> io:format("~p~n",[Vals]) end,
-module(test).
-compile(export_all).
-record(request_status, {code, id, properties, message}).
main() ->
print(#request_status{code=232}),
print(#request_status{code=232, id= <<"ok">>, properties=[{a,b}], message= <<"hi">>}),
print(#request_status{code=232, id= <<"ok">>, properties=[{a,b}], message= "hi"}),
print(#request_status{code=232, id= <<"ok">>, properties="still a list, you fail", message= <<"hi">>}),
51> recon:inet_window(send_oct, 10, 1000).
[{#Port<0.8059>,106891,[{send_oct,4849989856}]},
{#Port<0.8061>,101582,[{send_oct,4852148282}]},
{#Port<0.8062>,99912,[{send_oct,4849833970}]},
{#Port<0.8065>,97062,[{send_oct,4850533722}]},
{#Port<0.8064>,96873,[{send_oct,4851718944}]},
{#Port<0.8063>,96434,[{send_oct,4850928888}]},
{#Port<0.8045>,96308,[{send_oct,4852898248}]},
{#Port<0.8060>,94723,[{send_oct,4850619756}]},
{#Port<0.8057>,87827,[{send_oct,4849279524}]},
Eshell V5.10.1 (abort with ^G)
1> X=1,
1> Y=3.
3
2> "abcd,``
2>
User switch command
--> i
--> c
** exception exit: killed
$ erl
Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.1 (abort with ^G)
1> F = fun(F,_State) -> receive Bin -> F(F,Bin) end.
* 1: syntax error before: '.'
1> F = fun(F,_State) -> receive Bin -> F(F,Bin) end end.
#Fun<erl_eval.12.17052888>
2> Pid = spawn(fun() -> F(F,0) end).
<0.41.0>
# 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?