aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-03-20 07:29:51 +0100
committerBjörn Gustavsson <[email protected]>2012-03-20 07:29:51 +0100
commitdade65ef6622f532cad64a9cecaae747249f7f3d (patch)
treefa3764e908af23fcfabb9938d9d3076764849fc4 /lib/kernel
parent252b055e7f05e2beb91d680635dec9a9b307b1b1 (diff)
parenteb8c407eabfac8696f0ff235ce9d31af5698cf53 (diff)
downloadotp-dade65ef6622f532cad64a9cecaae747249f7f3d.tar.gz
otp-dade65ef6622f532cad64a9cecaae747249f7f3d.tar.bz2
otp-dade65ef6622f532cad64a9cecaae747249f7f3d.zip
Merge branch 'maint'
* maint: Improve erts_debug_SUITE Fix calculation of fun size in erts_debug:size/1
Diffstat (limited to 'lib/kernel')
-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 b3d54ddc1d..6654cd9ee7 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(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};
@@ -197,6 +202,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