File 0560-eprof-Don-t-count-CIFs-twice.patch of Package erlang

From b1ce9afba3dc553980e79974ada9218ce3b9ef56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Fri, 27 Mar 2020 09:13:25 +0100
Subject: [PATCH] eprof: Don't count CIFs twice

---
 lib/tools/src/eprof.erl        |  2 +-
 lib/tools/test/eprof_SUITE.erl | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/tools/src/eprof.erl b/lib/tools/src/eprof.erl
index ee72bad234..77bea2b114 100644
--- a/lib/tools/src/eprof.erl
+++ b/lib/tools/src/eprof.erl
@@ -398,7 +398,7 @@ collect_bpd() ->
     collect_bpd([M || M <- [element(1, Mi) || Mi <- code:all_loaded()], M =/= ?MODULE]).
 
 collect_bpd(Ms) when is_list(Ms) ->
-    collect_bpdf(collect_mfas(Ms) ++ erlang:system_info(snifs)).
+    collect_bpdf(collect_mfas(Ms)).
 
 collect_mfas(Ms) ->
     lists:foldl(fun
diff --git a/lib/tools/test/eprof_SUITE.erl b/lib/tools/test/eprof_SUITE.erl
index e908413315..4578b15cdb 100644
--- a/lib/tools/test/eprof_SUITE.erl
+++ b/lib/tools/test/eprof_SUITE.erl
@@ -151,6 +151,7 @@ basic_option_1(Config) ->
     {ok, _} = eprof:profile(fun() -> eprof_test:do(10) end, [{set_on_spawn, true}]),
 
     Mfas1 = lists:foldl(fun({_,Mfas},Out) -> Mfas ++ Out end, [], eprof:dump()),
+    assert_unique_mfas(Mfas1),
 
     {value, {_, {11, _}}} = lists:keysearch({eprof_test,dec,1},  1, Mfas1),
     {value, {_, { 1, _}}} = lists:keysearch({eprof_test, go,1},  1, Mfas1),
@@ -160,6 +161,8 @@ basic_option_1(Config) ->
     {ok, _} = eprof:profile(fun() -> eprof_test:do(10) end, [set_on_spawn]),
 
     Mfas2 = lists:foldl(fun({_,Mfas},Out) -> Mfas ++ Out end, [], eprof:dump()),
+    assert_unique_mfas(Mfas2),
+
     {value, {_, {11, _}}} = lists:keysearch({eprof_test,dec,1},  1, Mfas2),
     {value, {_, { 1, _}}} = lists:keysearch({eprof_test, go,1},  1, Mfas2),
     {value, {_, { 9, _}}} = lists:keysearch({lists, split_2,5},  1, Mfas2),
@@ -168,6 +171,9 @@ basic_option_1(Config) ->
     % disable trace set_on_spawn
     {ok, _} = eprof:profile(fun() -> eprof_test:do(10) end, []),
     [{_, Mfas3}] = eprof:dump(),
+
+    assert_unique_mfas(Mfas3),
+
     {value, {_, {11, _}}} = lists:keysearch({eprof_test,dec,1}, 1, Mfas3),
     {value, {_, { 1, _}}} = lists:keysearch({eprof_test, go,1}, 1, Mfas3),
     false = lists:keysearch({lists, split_2,5},  1, Mfas3),
@@ -178,6 +184,13 @@ basic_option_1(Config) ->
     stopped = eprof:stop(),
     ok.
 
+assert_unique_mfas(MFAs) ->
+    Duplicates = lists:sort(MFAs) -- lists:usort(MFAs),
+    case Duplicates of
+        [{{erlang,apply,2},_}] -> ok;
+        [] -> ok
+    end.
+
 tiny(suite) -> [];
 tiny(Config) when is_list(Config) -> 
     ensure_eprof_stopped(),
-- 
2.16.4

openSUSE Build Service is sponsored by