diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-05-12 16:45:41 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-05-12 16:45:41 +0200 |
commit | 614439de03d85efba23de0ea31f04cf8efb86495 (patch) | |
tree | 28eb62f9930220fbe1ebed3f1c6e5367d047a3cb /lib/kernel | |
parent | 316cdd16e221870397ee9571609de09314749927 (diff) | |
parent | 614bca0f5832f06bcc181c58b78e3371d79ec40d (diff) | |
download | otp-614439de03d85efba23de0ea31f04cf8efb86495.tar.gz otp-614439de03d85efba23de0ea31f04cf8efb86495.tar.bz2 otp-614439de03d85efba23de0ea31f04cf8efb86495.zip |
Merge branch 'maint'
Diffstat (limited to 'lib/kernel')
-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); |