@@ -152,7 +152,7 @@ defmodule Mix.Tasks.Profile.Eprof do
152
152
def profile ( fun , opts ) do
153
153
fun
154
154
|> profile_and_analyse ( opts )
155
- |> print_output
155
+ |> print_output ( )
156
156
end
157
157
158
158
defp profile_and_analyse ( fun , opts ) do
@@ -165,11 +165,15 @@ defmodule Mix.Tasks.Profile.Eprof do
165
165
:eprof . profile ( [ ] , fun , matching_pattern ( opts ) )
166
166
167
167
results =
168
- :eprof . dump ( )
169
- |> extract_results
170
- |> filter_results ( opts )
171
- |> sort_results ( opts )
172
- |> add_totals
168
+ Enum . map ( :eprof . dump ( ) , fn { pid , call_results } ->
169
+ parsed_calls =
170
+ call_results
171
+ |> filter_results ( opts )
172
+ |> sort_results ( opts )
173
+ |> add_totals ( )
174
+
175
+ { pid , parsed_calls }
176
+ end )
173
177
174
178
:eprof . stop ( )
175
179
@@ -191,9 +195,6 @@ defmodule Mix.Tasks.Profile.Eprof do
191
195
end
192
196
end
193
197
194
- defp extract_results ( [ ] ) , do: [ ]
195
- defp extract_results ( [ { _pid , call_results } ] ) , do: call_results
196
-
197
198
defp filter_results ( call_results , opts ) do
198
199
calls_opt = Keyword . get ( opts , :calls , 0 )
199
200
time_opt = Keyword . get ( opts , :time , 0 )
@@ -227,14 +228,23 @@ defmodule Mix.Tasks.Profile.Eprof do
227
228
228
229
@ header [ "#" , "CALLS" , "%" , "TIME" , "µS/CALL" ]
229
230
230
- defp print_output ( { 0 , _ , _ , _ } ) , do: print_function_count ( 0 )
231
+ defp print_output ( [ ] ) do
232
+ print_function_count ( 0 )
233
+ end
234
+
235
+ defp print_output ( results ) do
236
+ Enum . each ( results , & print_result / 1 )
237
+ end
231
238
232
- defp print_output ( { function_count , call_results , call_count , total_time } ) do
239
+ defp print_result ( { pid , { function_count , call_results , call_count , total_time } } ) do
233
240
formatted_rows = Enum . map ( call_results , & format_row ( & 1 , total_time ) )
234
241
formatted_total = format_total ( total_time , call_count )
235
242
236
243
column_lengths = column_lengths ( @ header , formatted_rows )
237
244
245
+ IO . puts ( "" )
246
+
247
+ print_pid_row ( pid )
238
248
print_row ( @ header , column_lengths )
239
249
print_row ( formatted_total , column_lengths )
240
250
Enum . each ( formatted_rows , & print_row ( & 1 , column_lengths ) )
@@ -244,6 +254,10 @@ defmodule Mix.Tasks.Profile.Eprof do
244
254
print_function_count ( function_count )
245
255
end
246
256
257
+ defp print_pid_row ( pid ) do
258
+ IO . puts ( "Profile results of #{ inspect ( pid ) } " )
259
+ end
260
+
247
261
defp format_row ( { { module , function , arity } , { count , time } } , total_time ) do
248
262
mfa = Exception . format_mfa ( module , function , arity )
249
263
time_percentage = :erlang . float_to_binary ( 100 * divide ( time , total_time ) , [ { :decimals , 2 } ] )
0 commit comments