Skip to content

Instantly share code, notes, and snippets.

@qzhuyan
Created April 6, 2021 10:07
Show Gist options
  • Save qzhuyan/ce8dfd2b220f5aff665381288a6a2c31 to your computer and use it in GitHub Desktop.
Save qzhuyan/ce8dfd2b220f5aff665381288a6a2c31 to your computer and use it in GitHub Desktop.
recon_frag_cache_leak.escript
#!/usr/bin/env escript
%% find cache leaks from a recon fragmentation dump:
%% input file should look like as following:
%% [{{ets_alloc,1},
%% [{sbcs_usage,1.0},
%% {mbcs_usage,0.3708287885109216},
%% {sbcs_block_size,0},
%% {sbcs_carriers_size,0},
%% {mbcs_block_size,2040364216},
%% {mbcs_carriers_size,5502173184}]},
%% {{binary_alloc,1},
%% [{sbcs_usage,0.9838266915137615},
%% {mbcs_usage,0.2354831817595459},
%% {sbcs_block_size,2196216},
%% {sbcs_carriers_size,2232320},
%% {mbcs_block_size,486011968},
%% {mbcs_carriers_size,2063892480}]},
%% {{binary_alloc,2},
%% [{sbcs_usage,0.9955778864503817},
%% {mbcs_usage,0.24373119298045376},
%% {sbcs_block_size,2671016},
%% {sbcs_carriers_size,2682880},
%% {mbcs_block_size,322538184},
%% {mbcs_carriers_size,1323335680}]}].
main([File]) ->
case file:consult(File) of
{error, _} = E->
io:format("bad input ~p: ~p", [File, E]);
{ok, [Raw]} ->
LeaksPerType = lists:foldl(fun({{Name, _}, Prop}, Acc)->
Sum = proplists:get_value(Name, Acc, 0),
Diff = proplists:get_value(mbcs_carriers_size, Prop, 0) - proplists:get_value(mbcs_block_size, Prop, 0),
lists:keystore(Name, 1, Acc, {Name, Sum+Diff})
end, [], Raw),
Sum = lists:sum([ V || {_Type, V}<- LeaksPerType]),
io:format("Summary:~n ~p~n Total leaks in bytes: ~p ~n", [LeaksPerType, Sum])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment