Last active
April 7, 2021 11:49
-
-
Save qzhuyan/0d56be9f8200b4b46245aaf0eceb71b1 to your computer and use it in GitHub Desktop.
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
#!/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