aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-03-20 07:25:49 +0100
committerBjörn Gustavsson <[email protected]>2012-03-20 07:25:49 +0100
commiteb8c407eabfac8696f0ff235ce9d31af5698cf53 (patch)
treecd2efaa4687f3c440a77a6d99e9c53d6db667a89 /lib
parent68ba8d70deb1549dd37a8325eea686c9908f926b (diff)
parentc928e7e683f01f14d805713f5af9e501306a00aa (diff)
downloadotp-eb8c407eabfac8696f0ff235ce9d31af5698cf53.tar.gz
otp-eb8c407eabfac8696f0ff235ce9d31af5698cf53.tar.bz2
otp-eb8c407eabfac8696f0ff235ce9d31af5698cf53.zip
Merge branch 'bjorn/kernel/erts_debug_size-fix/OTP-9991' into maint
* bjorn/kernel/erts_debug_size-fix/OTP-9991: Improve erts_debug_SUITE Fix calculation of fun size in erts_debug:size/1
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/src/erts_debug.erl20
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