Skip to content

Commit bdea259

Browse files
committed
Fix CI and raise if :tprof is not present
1 parent ced76f9 commit bdea259

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ defmodule Mix.Tasks.Profile.Tprof do
227227
fun.()
228228
end
229229

230-
:tprof.start()
230+
tprof_module().start()
231231
matching = Keyword.get(opts, :matching, {:_, :_, :_})
232232
set_on_spawn = Keyword.get(opts, :set_on_spawn, true)
233233
type = Keyword.get(opts, :type, :time)
@@ -243,16 +243,16 @@ defmodule Mix.Tasks.Profile.Tprof do
243243
tprof_type = to_tprof_type(type)
244244

245245
{return_value, {^tprof_type, traces}} =
246-
:tprof.profile(fun, %{
246+
tprof_module().profile(fun, %{
247247
set_on_spawn: set_on_spawn,
248248
pattern: matching,
249249
type: tprof_type,
250250
report: :return
251251
})
252252

253-
inspected = :tprof.inspect({tprof_type, traces}, :process, sort_by)
253+
inspected = tprof_module().inspect({tprof_type, traces}, :process, sort_by)
254254

255-
:tprof.stop()
255+
tprof_module().stop()
256256

257257
results =
258258
inspected
@@ -397,4 +397,13 @@ defmodule Mix.Tasks.Profile.Tprof do
397397
defp print_function_count(count) do
398398
IO.puts("Profile done over #{count} matching functions")
399399
end
400+
401+
# TODO remove once we require Erlang/OTP 27+
402+
defp tprof_module do
403+
if Code.ensure_loaded?(:tprof) do
404+
:tprof
405+
else
406+
Mix.raise("mix profile.tprof requires Erlang/OTP 27 or above")
407+
end
408+
end
400409
end

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)