Skip to content

Commit 3bebe15

Browse files
committed
Log times to type check modules when profiling
1 parent 2beac77 commit 3bebe15

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ defmodule Kernel.ParallelCompiler do
197197
deprecation warnings, and type checking should run. Defaults to `true`.
198198
We recommend disabling it only for debugging purposes.
199199
200-
* `:profile` - if set to `:time` measure the compilation time of each compilation cycle
201-
and group pass checker
200+
* `:profile` - if set to `:time`, measure the compilation time of each compilation cycle,
201+
each module type check, and group pass checker
202202
203203
* `:purge_compiler_modules` - if set to `true`, automatically purge compilation modules
204204
after compilation (see `Code.purge_compiler_modules/0`)

lib/elixir/lib/module/parallel_checker.ex

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ defmodule Module.ParallelChecker do
2020
{:max_concurrency, pos_integer()}
2121
| {:long_verification_threshold, pos_integer()}
2222
| {:each_long_verification, (module() -> term()) | (module(), pid() -> term())}
23+
| {:profile, :time}
2324
| {atom(), term()}
2425
]
2526

@@ -117,13 +118,13 @@ defmodule Module.ParallelChecker do
117118
send(checker, {ref, :cached})
118119

119120
receive do
120-
{^ref, :check} ->
121+
{^ref, :check, profile} ->
121122
# Set the compiler info so we can collect warnings
122123
:erlang.put(:elixir_compiler_info, {pid, self()})
123124

124125
{warnings, errors} =
125126
if module_tuple do
126-
check_module(module_tuple, {checker, table}, log?)
127+
check_module(module_tuple, {checker, table}, log?, profile)
127128
else
128129
{[], []}
129130
end
@@ -262,7 +263,7 @@ defmodule Module.ParallelChecker do
262263

263264
## Module checking
264265

265-
defp check_module(module_tuple, cache, log?) do
266+
defp check_module(module_tuple, cache, log?, profile) do
266267
{module, file, line, definitions, no_warn_undefined, behaviours, impls, attrs, after_verify} =
267268
module_tuple
268269

@@ -276,9 +277,13 @@ defmodule Module.ParallelChecker do
276277
definitions
277278
)
278279

280+
type_warnings =
281+
profile(module, profile, fn ->
282+
Module.Types.warnings(module, file, attrs, definitions, no_warn_undefined, cache)
283+
end)
284+
279285
{warnings, errors} =
280-
module
281-
|> Module.Types.warnings(file, attrs, definitions, no_warn_undefined, cache)
286+
type_warnings
282287
|> Kernel.++(behaviour_warnings)
283288
|> group_diagnostics()
284289
|> emit_diagnostics(file, log?)
@@ -577,6 +582,7 @@ defmodule Module.ParallelChecker do
577582
schedulers: schedulers,
578583
threshold: threshold,
579584
callback: callback,
585+
profile: Keyword.get(options, :profile),
580586
protocols: [],
581587
table: table
582588
}
@@ -653,9 +659,24 @@ defmodule Module.ParallelChecker do
653659
end
654660

655661
defp run_checkers(%{modules: [{module, pid, ref} | modules]} = state) do
656-
send(pid, {ref, :check})
662+
send(pid, {ref, :check, state.profile})
657663
timer = :erlang.send_after(state.threshold, self(), {__MODULE__, :timeout, module, pid})
658664
spawned = Map.put(state.spawned, module, timer)
659665
run_checkers(%{state | modules: modules, spawned: spawned})
660666
end
667+
668+
defp profile(module, :time, fun) do
669+
{time, result} = :timer.tc(fun)
670+
671+
IO.puts(
672+
:stderr,
673+
"[profile] Type checked #{inspect(module)} in #{div(time, 1000)}ms"
674+
)
675+
676+
result
677+
end
678+
679+
defp profile(_module, _profile, fun) do
680+
fun.()
681+
end
661682
end

lib/elixir/test/elixir/kernel/parallel_compiler_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ defmodule Kernel.ParallelCompilerTest do
5757
~r"\[profile\] [\s\d]{6}ms compiling \+ 0ms waiting while compiling .*tmp/profile_time/bar.ex"
5858

5959
assert profile =~ ~r"\[profile\] Finished compilation cycle of 1 modules in \d+ms"
60+
assert profile =~ ~r"\[profile\] Type checked HelloWorld in \d+ms"
6061
assert profile =~ ~r"\[profile\] Finished group pass check of 1 modules in \d+ms"
6162
after
6263
purge([HelloWorld])

0 commit comments

Comments
 (0)