1Counting Instructions
2=====================
3
4Here is an example that shows how to count how many times each
5instruction is executed:
6
7    $ (cd erts/emulator && make icount)
8     MAKE	icount
9    make[1]: Entering directory `/home/uabbgus/otp/erts/emulator'
10      .
11      .
12      .
13    make[1]: Leaving directory `/home/uabbgus/otp/erts/emulator'
14    $ cat t.erl
15    -module(t).
16    -compile([export_all,nowarn_export_all]).
17
18    count() ->
19        erts_debug:ic(fun benchmark/0).
20
21    benchmark() ->
22        %% Run dialyzer.
23        Root = code:root_dir(),
24        Wc1 = filename:join(Root, "lib/{kernel,stdlib}/ebin/*.beam"),
25        Wc2 = filename:join(Root, "erts/preloaded/ebin/*.beam"),
26        Files = filelib:wildcard(Wc1) ++ filelib:wildcard(Wc2),
27        Opts = [{analysis_type,plt_build},{files,Files},{get_warnings,true}],
28        dialyzer:run(Opts).
29    $ $ERL_TOP/bin/cerl -icount
30    Erlang/OTP 22 [RELEASE CANDIDATE 1] [erts-10.2.4] [source-ac0d451] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [instruction-counting]
31
32    Eshell V10.2.4  (abort with ^G)
33    1> c(t).
34    {ok,t}
35    2> t:count().
36               0 badarg_j
37               0 badmatch_x
38               0 bs_add_jsstx
39               0 bs_context_to_binary_x
40                .
41                .
42                .
43       536461394 move_call_last_yfQ
44       552405176 allocate_tt
45       619920327 i_is_eq_exact_immed_frc
46       636419163 is_nonempty_list_allocate_frtt
47       641859278 i_get_tuple_element_xPx
48       678196718 move_return_c
49       786289914 is_tagged_tuple_frAa
50       865826424 i_call_f
51    Total: 20728870321
52    []
53    3>
54