aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/erts_debug.erl
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2015-04-17 11:51:36 +0200
committerBjörn-Egil Dahlberg <[email protected]>2015-04-23 14:37:17 +0200
commit7d06388110e52357f6ec3742b2fcc11d4ac3aadc (patch)
tree4646354ee09f77060e84e20f81e4ffbbbb8fcc9d /lib/kernel/src/erts_debug.erl
parent6ba93050fa369626b22cc608c7f874148bb0e5c1 (diff)
downloadotp-7d06388110e52357f6ec3742b2fcc11d4ac3aadc.tar.gz
otp-7d06388110e52357f6ec3742b2fcc11d4ac3aadc.tar.bz2
otp-7d06388110e52357f6ec3742b2fcc11d4ac3aadc.zip
kernel: Add instruction_count helper to erts_debug
Diffstat (limited to 'lib/kernel/src/erts_debug.erl')
-rw-r--r--lib/kernel/src/erts_debug.erl15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/kernel/src/erts_debug.erl b/lib/kernel/src/erts_debug.erl
index 17bee06b5e..8f81fcf825 100644
--- a/lib/kernel/src/erts_debug.erl
+++ b/lib/kernel/src/erts_debug.erl
@@ -20,7 +20,7 @@
%% Low-level debugging support. EXPERIMENTAL!
--export([size/1,df/1,df/2,df/3]).
+-export([size/1,df/1,df/2,df/3,ic/1]).
%% This module contains the following *experimental* BIFs:
%% disassemble/1
@@ -114,6 +114,19 @@ get_internal_state(_) ->
instructions() ->
erlang:nif_error(undef).
+-spec ic(F) -> Result when
+ F :: function(),
+ Result :: term().
+
+ic(F) when is_function(F) ->
+ Is0 = erlang:system_info(instruction_counts),
+ R = F(),
+ Is1 = erlang:system_info(instruction_counts),
+ Is = lists:keysort(2,[{I,C1 - C0}||{{I,C1},{I,C0}} <- lists:zip(Is1,Is0)]),
+ _ = [io:format("~12w ~w~n", [C,I])||{I,C}<-Is],
+ io:format("Total: ~w~n",[lists:sum([C||{_I,C}<-Is])]),
+ R.
+
-spec lock_counters(info) -> term();
(clear) -> ok;
({copy_save, boolean()}) -> boolean();