diff options
author | Björn Gustavsson <[email protected]> | 2012-03-19 15:09:35 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2012-03-19 16:25:20 +0100 |
commit | 72d73ab73b5b8c92c5473dea87a35ba6e0ca72ca (patch) | |
tree | 13346d2f83bcf6d2908ead8257125b0397572718 /lib/kernel/src | |
parent | 662e3ffeed74d9121315d86af46430dd71e01709 (diff) | |
download | otp-72d73ab73b5b8c92c5473dea87a35ba6e0ca72ca.tar.gz otp-72d73ab73b5b8c92c5473dea87a35ba6e0ca72ca.tar.bz2 otp-72d73ab73b5b8c92c5473dea87a35ba6e0ca72ca.zip |
Fix calculation of fun size in erts_debug:size/1
Funs would be calculated using erts_debug:flat_size/1.
Diffstat (limited to 'lib/kernel/src')
-rw-r--r-- | lib/kernel/src/erts_debug.erl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/kernel/src/erts_debug.erl b/lib/kernel/src/erts_debug.erl index 7d6a5ade94..16a773898d 100644 --- a/lib/kernel/src/erts_debug.erl +++ b/lib/kernel/src/erts_debug.erl @@ -53,6 +53,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(Fun, Seen0, Sum) when is_function(Fun) -> + case remember_term(Fun, Seen0) of + seen -> {Sum,Seen0}; + Seen -> fun_size(Fun, Seen, Sum) + end; size(Term, Seen0, Sum) -> case erts_debug:flat_size(Term) of 0 -> {Sum,Seen0}; @@ -68,6 +73,21 @@ tuple_size(I, Sz, _, Seen, Sum) when I > Sz -> tuple_size(I, Sz, Tuple, Seen0, Sum0) -> {Sum,Seen} = size(element(I, Tuple), Seen0, Sum0), tuple_size(I+1, Sz, Tuple, Seen, Sum). + +fun_size(Fun, Seen, Sum) -> + case erlang:fun_info(Fun, type) of + {type,external} -> + {Sum + erts_debug:flat_size(Fun),Seen}; + {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)) + end. + +fun_size_1([H|T], Seen0, Sum0) -> + {Sum,Seen} = size(H, Seen0, Sum0), + fun_size_1(T, Seen, Sum); +fun_size_1([], Seen, Sum) -> {Sum,Seen}. remember_term(Term, Seen) -> case gb_trees:lookup(Term, Seen) of |