2
%% <year>2006-2007</year>
3
%% <holder>Ericsson AB, All Rights Reserved</holder>
4
%% Copyright Ericsson AB 2006-2009. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
17
%% The Initial Developer of the Original Code is Ericsson AB.
20
21
%%----------------------------------------------------------------------
21
22
%% Purpose: Misc utility functions for the mstone modules
128
130
%%----------------------------------------------------------------------
132
%% D i s p l a y A l l o c a t o r I n f o
134
%%----------------------------------------------------------------------
136
display_alloc_info() ->
137
io:format("Allocator memory information:~n", []),
138
AllocInfo = alloc_info(),
139
display_alloc_info(AllocInfo).
141
display_alloc_info([]) ->
143
display_alloc_info([{Alloc, Mem}|AllocInfo]) ->
144
io:format(" ~15w: ~10w~n", [Alloc, Mem]),
145
display_alloc_info(AllocInfo).
148
case erlang:system_info(allocator) of
149
{_Allocator, _Version, Features, _Settings} ->
150
alloc_info(Features);
155
alloc_info(Allocators) ->
156
Allocs = [temp_alloc, sl_alloc, std_alloc, ll_alloc, eheap_alloc,
157
ets_alloc, binary_alloc, driver_alloc],
158
alloc_info(Allocators, Allocs, []).
160
alloc_info([], _, Acc) ->
162
alloc_info([Allocator | Allocators], Allocs, Acc) ->
163
case lists:member(Allocator, Allocs) of
165
Instances0 = erlang:system_info({allocator, Allocator}),
168
is_list(Instances0) ->
169
[Instance || Instance <- Instances0,
170
element(1, Instance) =:= instance];
174
AllocatorMem = alloc_mem_info(Instances),
175
alloc_info(Allocators, Allocs, [{Allocator, AllocatorMem} | Acc]);
178
alloc_info(Allocators, Allocs, Acc)
182
alloc_mem_info(Instances) ->
183
alloc_mem_info(Instances, []).
185
alloc_mem_info([], Acc) ->
186
lists:sum([Mem || {instance, _, Mem} <- Acc]);
187
alloc_mem_info([{instance, N, Info}|Instances], Acc) ->
188
InstanceMemInfo = alloc_instance_mem_info(Info),
189
alloc_mem_info(Instances, [{instance, N, InstanceMemInfo} | Acc]).
191
alloc_instance_mem_info(InstanceInfo) ->
192
MBCS = alloc_instance_mem_info(mbcs, InstanceInfo),
193
SBCS = alloc_instance_mem_info(sbcs, InstanceInfo),
196
alloc_instance_mem_info(Key, InstanceInfo) ->
197
case lists:keysearch(Key, 1, InstanceInfo) of
198
{value, {Key, Info}} ->
199
case lists:keysearch(blocks_size, 1, Info) of
200
{value, {blocks_size, Mem, _, _}} ->
210
%%----------------------------------------------------------------------
130
212
%% D i s p l a y A p p I n f o
132
214
%%----------------------------------------------------------------------
145
227
AI = megaco_ber_bin_drv_media_gateway_control_v1:info(),
147
229
case lists:keysearch(vsn, 1, AI) of
148
{value, {vsn, V}} when atom(V) ->
230
{value, {vsn, V}} when is_atom(V) ->
150
{value, {vsn, V}} when list(V) ->
232
{value, {vsn, V}} when is_list(V) ->
167
249
expand_dirs([], _, EDirs) ->
168
250
lists:reverse(lists:flatten(EDirs));
169
expand_dirs([Dir|Dirs], DrvInclude, EDirs) when atom(Dir) ->
251
expand_dirs([Dir|Dirs], DrvInclude, EDirs) when is_atom(Dir) ->
170
252
EDir = expand_dir(atom_to_list(Dir), DrvInclude),
171
253
expand_dirs(Dirs, DrvInclude, [EDir|EDirs]);
172
expand_dirs([Dir|Dirs], DrvInclude, EDirs) when list(Dir) ->
254
expand_dirs([Dir|Dirs], DrvInclude, EDirs) when is_list(Dir) ->
173
255
EDir = expand_dir(Dir, DrvInclude),
174
256
expand_dirs(Dirs, DrvInclude, [EDir|EDirs]).
258
expand_dir(Dir, flex) ->
261
[{Dir, megaco_pretty_text_encoder, [flex_scanner]},
262
{Dir, megaco_pretty_text_encoder, [flex_scanner]},
263
{Dir, megaco_pretty_text_encoder, [flex_scanner]},
264
{Dir, megaco_pretty_text_encoder, [flex_scanner]},
265
{Dir, megaco_pretty_text_encoder, [flex_scanner]},
266
{Dir, megaco_pretty_text_encoder, [flex_scanner]},
267
{Dir, megaco_pretty_text_encoder, [flex_scanner]},
268
{Dir, megaco_pretty_text_encoder, [flex_scanner]}];
270
[{Dir, megaco_compact_text_encoder, [flex_scanner]},
271
{Dir, megaco_compact_text_encoder, [flex_scanner]},
272
{Dir, megaco_compact_text_encoder, [flex_scanner]},
273
{Dir, megaco_compact_text_encoder, [flex_scanner]},
274
{Dir, megaco_compact_text_encoder, [flex_scanner]},
275
{Dir, megaco_compact_text_encoder, [flex_scanner]},
276
{Dir, megaco_compact_text_encoder, [flex_scanner]},
277
{Dir, megaco_compact_text_encoder, [flex_scanner]}];
285
error({invalid_codec, Else})
176
287
expand_dir(Dir, only_drv) ->
286
397
error({file_empty, FileName});
288
399
{ok, #file_info{type = Type}} ->
289
error({invalid_type, Type, FileName});
400
error({invalid_type, FileName, Type});
292
error({unexpected_file_info, Info, FileName});
403
error({unexpected_file_info, FileName, Info});
295
error({failed_reading_file_info, Error})
406
error({failed_reading_file_info, File, Error})
341
452
flex_scanner_handler(Pid) ->
342
453
case (catch megaco_flex_scanner:start()) of
343
{ok, Port} when port(Port) ->
454
{ok, Port} when is_port(Port) ->
344
455
Pid ! {flex_scanner_started, self(), {flex, Port}},
345
456
flex_scanner_handler(Pid, Port);
346
457
{error, {load_driver, {open_error, Reason}}} ->