Skip to content

Instantly share code, notes, and snippets.

@qzhuyan
Last active April 7, 2021 11:49
Show Gist options
  • Save qzhuyan/0d56be9f8200b4b46245aaf0eceb71b1 to your computer and use it in GitHub Desktop.
Save qzhuyan/0d56be9f8200b4b46245aaf0eceb71b1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env escript
%% find unabandoned carriers and their size, aka cache leaks.
%% note, file should be consultable erlang term file which means it has a '.' at the end of input file.
main([File]) ->
case file:consult(File) of
{error, _} = E->
io:format("bad input ~p: ~p", [File, E]);
{ok, [Raw]} ->
Caches = [{Name, Number, Size}
|| {Name, Prop}<-Raw, {mbcs_pool, Pool}<- Prop, {carriers_size, Size} <- Pool, {carriers, Number} <- Pool],
Numbers = lists:sum([V || {_Name, V, _}<- Caches]),
Sizes = lists:sum([V || {_Name, _, V}<- Caches]),
io:format("Caches in pool: ~p ~n Total nubmers: ~p~n Leaked size: ~p B~n", [Caches, Numbers, Sizes]),
Carriers = [{Name, Number, CSize}
|| {Name, Prop}<-Raw, {mbcs, MBCS}<- Prop, {carriers_size, CSize, _, _} <- MBCS, {carriers, Number, _, _} <- MBCS],
CNumbers = lists:sum([V || {_Name, V, _}<- Carriers]),
CSizes = lists:sum([V || {_Name, _, V}<- Carriers]),
io:format("Carriers : ~p ~n Total nubmers: ~p~n Total size: ~p B~n", [Carriers, CNumbers, CSizes])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment