@@ -219,20 +219,23 @@ defmodule Mix.Tasks.Profile.Eprof do
219
219
220
220
defp format_row ( { { module , function , arity } , { count , time } } , total_time ) do
221
221
mfa = Exception . format_mfa ( module , function , arity )
222
- time_percentage = :erlang . float_to_binary ( 100 * time / total_time , [ { :decimals , 2 } ] )
223
- time_per_call = :erlang . float_to_binary ( time / count , [ { :decimals , 2 } ] )
222
+ time_percentage = :erlang . float_to_binary ( 100 * divide ( time , total_time ) , [ { :decimals , 2 } ] )
223
+ time_per_call = :erlang . float_to_binary ( divide ( time , count ) , [ { :decimals , 2 } ] )
224
224
count = Integer . to_string ( count )
225
225
time = Integer . to_string ( time )
226
226
227
227
[ mfa , count , time_percentage , time , time_per_call ]
228
228
end
229
229
230
230
defp format_total ( total_time , total_count ) do
231
- time_per_call = :erlang . float_to_binary ( total_time / total_count , [ { :decimals , 2 } ] )
231
+ time_per_call = :erlang . float_to_binary ( divide ( total_time , total_count ) , [ { :decimals , 2 } ] )
232
232
233
233
[ "Total" , Integer . to_string ( total_count ) , "100.00" , Integer . to_string ( total_time ) , time_per_call ]
234
234
end
235
235
236
+ defp divide ( _ , 0 ) , do: 0.0
237
+ defp divide ( t , n ) , do: t / n
238
+
236
239
defp column_lengths ( header , rows ) do
237
240
max_lengths = Enum . map ( header , & String . length / 1 )
238
241
0 commit comments