Skip to content

Commit 3232a33

Browse files
authored
alternative solution
Improvements: * Does not require `Erlang/OTP` version check * Independent of `JIT` optimisations and architecture * Properly validates sorted results * Asserts mfa string as column value
1 parent 1af6a1f commit 3232a33

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/mix/test/mix/tasks/profile.tprof_test.exs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ defmodule Mix.Tasks.Profile.TprofTest do
8686
result = capture_io(fn ->
8787
Tprof.run(["--type", "memory", "--sort", "per_call", "-e", @expr])
8888
end)
89-
90-
# TODO: Remove when we require Erlang 28 exclusively
91-
otp_release =
92-
:otp_release
93-
|> :erlang.system_info()
94-
|> List.to_integer()
95-
96-
if otp_release < 28 do
97-
assert result =~ ~r/\n:erlang\.integer_to_binary\/1.*\nEnum\.each\/2/s
98-
else
99-
assert result =~ ~r/\n:erlang\.integer_to_binary\/1[^\n]+3\.\d{2}\n/
100-
assert result =~ ~r/\nEnum\.each\/2[^\n]+3\.\d{2}\n/
101-
end
89+
90+
[_warmup, _profile_results, _columns, _total, first, second, _profile_done, ""] =
91+
String.split(result, ~r/\n+/)
92+
93+
list =
94+
Enum.map([first, second], fn row ->
95+
[mfa, _calls, _percent, _words, per_call] = String.split(row, ~r/\s+/)
96+
{mfa, String.to_float(per_call)}
97+
end)
98+
99+
assert list == Enum.sort_by(list, &elem(&1, 1))
100+
assert List.keymember?(list, "Enum.each/2", 0)
101+
assert List.keymember?(list, ":erlang.integer_to_binary/1", 0)
102102
end)
103103
end
104104

0 commit comments

Comments
 (0)