@@ -152,7 +152,7 @@ defmodule Mix.Tasks.Profile.Eprof do
152152 def profile ( fun , opts ) do
153153 fun
154154 |> profile_and_analyse ( opts )
155- |> print_output
155+ |> print_output ( )
156156 end
157157
158158 defp profile_and_analyse ( fun , opts ) do
@@ -165,11 +165,15 @@ defmodule Mix.Tasks.Profile.Eprof do
165165 :eprof . profile ( [ ] , fun , matching_pattern ( opts ) )
166166
167167 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 )
173177
174178 :eprof . stop ( )
175179
@@ -191,9 +195,6 @@ defmodule Mix.Tasks.Profile.Eprof do
191195 end
192196 end
193197
194- defp extract_results ( [ ] ) , do: [ ]
195- defp extract_results ( [ { _pid , call_results } ] ) , do: call_results
196-
197198 defp filter_results ( call_results , opts ) do
198199 calls_opt = Keyword . get ( opts , :calls , 0 )
199200 time_opt = Keyword . get ( opts , :time , 0 )
@@ -227,14 +228,23 @@ defmodule Mix.Tasks.Profile.Eprof do
227228
228229 @ header [ "#" , "CALLS" , "%" , "TIME" , "µS/CALL" ]
229230
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
231238
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
233240 formatted_rows = Enum . map ( call_results , & format_row ( & 1 , total_time ) )
234241 formatted_total = format_total ( total_time , call_count )
235242
236243 column_lengths = column_lengths ( @ header , formatted_rows )
237244
245+ IO . puts ( "" )
246+
247+ print_pid_row ( pid )
238248 print_row ( @ header , column_lengths )
239249 print_row ( formatted_total , column_lengths )
240250 Enum . each ( formatted_rows , & print_row ( & 1 , column_lengths ) )
@@ -244,6 +254,10 @@ defmodule Mix.Tasks.Profile.Eprof do
244254 print_function_count ( function_count )
245255 end
246256
257+ defp print_pid_row ( pid ) do
258+ IO . puts ( "Profile results of #{ inspect ( pid ) } " )
259+ end
260+
247261 defp format_row ( { { module , function , arity } , { count , time } } , total_time ) do
248262 mfa = Exception . format_mfa ( module , function , arity )
249263 time_percentage = :erlang . float_to_binary ( 100 * divide ( time , total_time ) , [ { :decimals , 2 } ] )
0 commit comments