@@ -221,51 +221,58 @@ defmodule Mix.Tasks.Profile.Tprof do
221
221
return_value
222
222
end
223
223
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 . ( )
241
230
end
242
231
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
269
276
end
270
277
271
278
defp to_tprof_type ( :calls ) , do: :call_count
0 commit comments