%%% %%% Copyright Ericsson AB 2012. All Rights Reserved. %%% %%% The contents of this file are subject to the Erlang Public License, %%% Version 1.1, (the "License"); you may not use this file except in %%% compliance with the License. You should have received a copy of the %%% Erlang Public License along with this software. If not, it can be %%% retrieved online at http://www.erlang.org/. %%% %%% Software distributed under the License is distributed on an "AS IS" %%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %%% the License for the specific language governing rights and limitations %%% under the License. %%% %%%------------------------------------------------------------------- %%% @author Rickard Green %%% @copyright (C) 2012, Ericsson AB %%% @doc %%% %%% @end %%% Created : 24 Sep 2012 by Rickard Green %%%------------------------------------------------------------------- -module(memory). -export([carriers_size/0]). carriers_size() -> AUAs = try erlang:system_info(alloc_util_allocators) catch error:badarg -> [temp_alloc, eheap_alloc, binary_alloc, ets_alloc, sl_alloc, ll_alloc, std_alloc] end, case asz(aua_info(AUAs)) of notsup -> erlang:error(notsup); Res -> Res end. aua_info(AUAs) -> try erlang:system_info({allocator_sizes, AUAs}) catch error:badarg -> try [{AUA, erlang:system_info({allocator_sizes, AUA})} || AUA <- AUAs] catch error:badarg -> try [{AUA, erlang:system_info({allocator, AUA})} || AUA <- AUAs] catch error:badarg -> notsup end end end. asz(notsup) -> notsup; asz([]) -> 0; asz([{sbmbc_alloc, false} | As]) -> asz(As); asz([{_, false} | _]) -> notsup; asz([{_, AIs} | As]) -> aicsz(AIs) + asz(As). aicsz([]) -> 0; aicsz([{instance, _, Cs}| AIs]) -> ctsz(Cs) + aicsz(AIs); aicsz(Cs) -> ctsz(Cs). ctsz([]) -> 0; ctsz([{Xbcs, CI} | CTs]) when Xbcs == mbcs; Xbcs == sbcs -> cisz(CI) + ctsz(CTs); ctsz([_ | CTs]) -> ctsz(CTs). cisz([]) -> 0; cisz([{carriers_size, Sz, _, _} | Cs]) -> Sz + cisz(Cs); cisz([_ | Cs]) -> cisz(Cs).