Skip to content

Commit 02fcba1

Browse files
committed
Fix for OTP26-
1 parent ced76f9 commit 02fcba1

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

lib/mix/lib/mix/tasks/profile.tprof.ex

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -221,51 +221,58 @@ defmodule Mix.Tasks.Profile.Tprof do
221221
return_value
222222
end
223223

224-
defp profile_and_analyse(fun, opts) do
225-
if Keyword.get(opts, :warmup, true) do
226-
IO.puts("Warmup...\n")
227-
fun.()
228-
end
229-
230-
:tprof.start()
231-
matching = Keyword.get(opts, :matching, {:_, :_, :_})
232-
set_on_spawn = Keyword.get(opts, :set_on_spawn, true)
233-
type = Keyword.get(opts, :type, :time)
234-
235-
sort_by =
236-
case Keyword.get(opts, :sort) do
237-
nil -> :measurement
238-
:calls -> :calls
239-
^type -> :measurement
240-
other -> Mix.raise("Incompatible sort option `#{other}` with type `#{type}`")
224+
# TODO remove once we require Erlang/OTP 27+
225+
if System.otp_release() >= "27" do
226+
defp profile_and_analyse(fun, opts) do
227+
if Keyword.get(opts, :warmup, true) do
228+
IO.puts("Warmup...\n")
229+
fun.()
241230
end
242231

243-
tprof_type = to_tprof_type(type)
244-
245-
{return_value, {^tprof_type, traces}} =
246-
:tprof.profile(fun, %{
247-
set_on_spawn: set_on_spawn,
248-
pattern: matching,
249-
type: tprof_type,
250-
report: :return
251-
})
252-
253-
inspected = :tprof.inspect({tprof_type, traces}, :process, sort_by)
254-
255-
:tprof.stop()
256-
257-
results =
258-
inspected
259-
|> Enum.map(fn {pid, {^tprof_type, measurement_total, call_results}} ->
260-
parsed_calls =
261-
call_results
262-
|> filter_results(type, opts)
263-
|> add_totals(measurement_total)
264-
265-
{pid, parsed_calls}
266-
end)
267-
268-
{type, return_value, results}
232+
:tprof.start()
233+
matching = Keyword.get(opts, :matching, {:_, :_, :_})
234+
set_on_spawn = Keyword.get(opts, :set_on_spawn, true)
235+
type = Keyword.get(opts, :type, :time)
236+
237+
sort_by =
238+
case Keyword.get(opts, :sort) do
239+
nil -> :measurement
240+
:calls -> :calls
241+
^type -> :measurement
242+
other -> Mix.raise("Incompatible sort option `#{other}` with type `#{type}`")
243+
end
244+
245+
tprof_type = to_tprof_type(type)
246+
247+
{return_value, {^tprof_type, traces}} =
248+
:tprof.profile(fun, %{
249+
set_on_spawn: set_on_spawn,
250+
pattern: matching,
251+
type: tprof_type,
252+
report: :return
253+
})
254+
255+
inspected = :tprof.inspect({tprof_type, traces}, :process, sort_by)
256+
257+
:tprof.stop()
258+
259+
results =
260+
inspected
261+
|> Enum.map(fn {pid, {^tprof_type, measurement_total, call_results}} ->
262+
parsed_calls =
263+
call_results
264+
|> filter_results(type, opts)
265+
|> add_totals(measurement_total)
266+
267+
{pid, parsed_calls}
268+
end)
269+
270+
{type, return_value, results}
271+
end
272+
else
273+
defp profile_and_analyse(_fun, _opts) do
274+
Mix.raise("mix profile.tprof requires Erlang/OTP27 or above")
275+
end
269276
end
270277

271278
defp to_tprof_type(:calls), do: :call_count

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Mix.Tasks.Profile.TprofTest do
66
import ExUnit.CaptureIO
77
alias Mix.Tasks.Profile.Tprof
88

9+
# TODO remove once we require Erlang/OTP 27+
910
@moduletag skip: System.otp_release() < "27"
1011

1112
@expr "Enum.each(1..5, &String.Chars.Integer.to_string/1)"

0 commit comments

Comments
 (0)