@@ -366,32 +366,33 @@ defmodule Kernel.ParallelCompiler do
366
366
end
367
367
368
368
defp maybe_check_modules ( result , runtime_modules , state ) do
369
- % { profile: profile , checker: checker } = state
370
-
371
369
compiled_modules =
372
370
for { { :module , module } , binary } when is_binary ( binary ) <- result ,
373
371
do: module
374
372
375
- profile_checker ( profile , compiled_modules , runtime_modules , fn ->
376
- Module.ParallelChecker . verify ( checker , runtime_modules )
377
- end )
373
+ profile (
374
+ state ,
375
+ fn ->
376
+ num_modules = length ( compiled_modules ) + length ( runtime_modules )
377
+ "group pass check of #{ num_modules } modules"
378
+ end ,
379
+ fn -> Module.ParallelChecker . verify ( state . checker , runtime_modules ) end
380
+ )
378
381
end
379
382
380
383
defp profile_init ( :time ) , do: { :time , System . monotonic_time ( ) , 0 }
381
384
defp profile_init ( nil ) , do: :none
382
385
383
- defp profile_checker ( { :time , _ , _ } , compiled_modules , runtime_modules , fun ) do
386
+ defp profile ( % { profile: :none } , _what , fun ) , do: fun . ( )
387
+
388
+ defp profile ( % { profile: { :time , _ , _ } } , what , fun ) do
384
389
{ time , result } = :timer . tc ( fun )
385
390
time = div ( time , 1000 )
386
- num_modules = length ( compiled_modules ) + length ( runtime_modules )
387
- IO . puts ( :stderr , "[profile] Finished group pass check of #{ num_modules } modules in #{ time } ms" )
391
+ what = if is_binary ( what ) , do: what , else: what . ( )
392
+ IO . puts ( :stderr , "[profile] Finished #{ what } in #{ time } ms" )
388
393
result
389
394
end
390
395
391
- defp profile_checker ( :none , _compiled_modules , _runtime_modules , fun ) do
392
- fun . ( )
393
- end
394
-
395
396
## Compiler worker spawning
396
397
397
398
# We already have n=schedulers currently running, don't spawn new ones
@@ -475,7 +476,10 @@ defmodule Kernel.ParallelCompiler do
475
476
end )
476
477
477
478
[ ] = files
478
- cycle_return = measure_timing ( state , "each_cycle callback" , fn -> each_cycle_return ( state . each_cycle . ( ) ) end )
479
+
480
+ cycle_return =
481
+ profile ( state , "cycle resolution" , fn -> each_cycle_return ( state . each_cycle . ( ) ) end )
482
+
479
483
state = cycle_timing ( result , state )
480
484
481
485
case cycle_return do
@@ -519,23 +523,23 @@ defmodule Kernel.ParallelCompiler do
519
523
# Finally, note there is no difference between hard and raise, the
520
524
# difference is where the raise is happening, inside the compiler
521
525
# or in the caller.
522
- measure_timing ( state , "spawn_workers/8 in potential deadlock situation" , fn ->
523
- waiting_list = Map . to_list ( waiting )
526
+ deadlocked =
527
+ profile ( state , "deadlock resolution" , fn ->
528
+ waiting_list = Map . to_list ( waiting )
524
529
525
- deadlocked =
526
530
deadlocked ( waiting_list , :soft , false ) ||
527
531
deadlocked ( waiting_list , :soft , true ) ||
528
532
deadlocked ( waiting_list , :hard , false ) ||
529
533
without_definition ( waiting_list , files )
534
+ end )
530
535
531
- if deadlocked do
532
- spawn_workers ( deadlocked , spawned , waiting , files , result , warnings , errors , state )
533
- else
534
- return_error ( warnings , errors , state , fn ->
535
- handle_deadlock ( waiting , files )
536
- end )
537
- end
538
- end )
536
+ if deadlocked do
537
+ spawn_workers ( deadlocked , spawned , waiting , files , result , warnings , errors , state )
538
+ else
539
+ return_error ( warnings , errors , state , fn ->
540
+ handle_deadlock ( waiting , files )
541
+ end )
542
+ end
539
543
end
540
544
541
545
# No more queue, but spawned and map_size(waiting) do not match
@@ -560,15 +564,6 @@ defmodule Kernel.ParallelCompiler do
560
564
end
561
565
end
562
566
563
- defp measure_timing ( % { profile: :none } , _what , fun ) , do: fun . ( )
564
- defp measure_timing ( % { profile: { :time , _ , _ } } , what , fun ) do
565
- { time , result } = :timer . tc ( fun )
566
- time = div ( time , 1000 )
567
-
568
- IO . puts ( :stderr , "[profile] Executed #{ what } in #{ time } ms" )
569
- result
570
- end
571
-
572
567
defp cycle_timing ( _result , % { profile: :none } = state ) do
573
568
state
574
569
end
0 commit comments