diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-05-12 16:44:24 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-05-12 16:44:24 +0200 |
commit | 614bca0f5832f06bcc181c58b78e3371d79ec40d (patch) | |
tree | beb8d9d41d986641cbfdd116b358d6bd15aa9fe4 /lib | |
parent | c563f5866b42a3479050241284fffc1245aebe7d (diff) | |
parent | e1d5e4841a657ad26254597dc8f2bb09a38c6646 (diff) | |
download | otp-614bca0f5832f06bcc181c58b78e3371d79ec40d.tar.gz otp-614bca0f5832f06bcc181c58b78e3371d79ec40d.tar.bz2 otp-614bca0f5832f06bcc181c58b78e3371d79ec40d.zip |
Merge branch 'egil/fix-erts_debug-size/OTP-11923' into maint
* egil/fix-erts_debug-size/OTP-11923:
erts: Update preloaded erts_internal.beam
erts: Add spec for erts_internal:map_to_tuple_keys/1
erts: Add testcase for erts_debug:size/1 Map terms
kernel: Fix erts_debug:size/1 to handle Map sizes
erts: Add erts_internal:map_to_tuple_keys/1
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kernel/src/erts_debug.erl | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/kernel/src/erts_debug.erl b/lib/kernel/src/erts_debug.erl index f7a815882b..ef605d0bfe 100644 --- a/lib/kernel/src/erts_debug.erl +++ b/lib/kernel/src/erts_debug.erl @@ -182,6 +182,11 @@ size(Tuple, Seen0, Sum0) when is_tuple(Tuple) -> Sum = Sum0 + 1 + tuple_size(Tuple), tuple_size(1, tuple_size(Tuple), Tuple, Seen, Sum) end; +size(Map, Seen0, Sum) when is_map(Map) -> + case remember_term(Map, Seen0) of + seen -> {Sum,Seen0}; + Seen -> map_size(Map, Seen, Sum) + end; size(Fun, Seen0, Sum) when is_function(Fun) -> case remember_term(Fun, Seen0) of seen -> {Sum,Seen0}; @@ -203,6 +208,12 @@ tuple_size(I, Sz, Tuple, Seen0, Sum0) -> {Sum,Seen} = size(element(I, Tuple), Seen0, Sum0), tuple_size(I+1, Sz, Tuple, Seen, Sum). +map_size(Map,Seen0,Sum0) -> + Kt = erts_internal:map_to_tuple_keys(Map), + Vs = maps:values(Map), + {Sum1,Seen1} = size(Kt,Seen0,Sum0), + fold_size(Vs,Seen1,Sum1+length(Vs)+3). + fun_size(Fun, Seen, Sum) -> case erlang:fun_info(Fun, type) of {type,external} -> @@ -210,14 +221,14 @@ fun_size(Fun, Seen, Sum) -> {type,local} -> Sz = erts_debug:flat_size(fun() -> ok end), {env,Env} = erlang:fun_info(Fun, env), - fun_size_1(Env, Seen, Sum+Sz+length(Env)) + fold_size(Env, Seen, Sum+Sz+length(Env)) end. -fun_size_1([H|T], Seen0, Sum0) -> +fold_size([H|T], Seen0, Sum0) -> {Sum,Seen} = size(H, Seen0, Sum0), - fun_size_1(T, Seen, Sum); -fun_size_1([], Seen, Sum) -> {Sum,Seen}. - + fold_size(T, Seen, Sum); +fold_size([], Seen, Sum) -> {Sum,Seen}. + remember_term(Term, Seen) -> case gb_trees:lookup(Term, Seen) of none -> gb_trees:insert(Term, [Term], Seen); |