Skip to content

Commit fcada17

Browse files
committed
Align profiling times for better readability
Before we would write: lib/foo.ex compiled in 10ms (plus 100ms waiting) However, because the file name is variable, it was hard to see which file took the longest. Now we will write: 10ms compiling + 100ms waiting for lib/foo.ex By right aligning all times, we can easily look in the first row and see which file took the longest. We can also provide a summary option in the future, if necessary.
1 parent 6be8bdd commit fcada17

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,13 @@ defmodule Kernel.ParallelCompiler do
623623
data = maybe_warn_long_compilation(data, state)
624624

625625
if state.profile != :none do
626-
compiling = System.convert_time_unit(data.compiling, :native, :millisecond)
627-
waiting = System.convert_time_unit(data.waiting, :native, :millisecond)
628-
extra = if waiting > 0, do: " (plus #{waiting}ms waiting)", else: ""
626+
compiling = to_padded_ms(data.compiling)
627+
waiting = to_padded_ms(data.waiting)
628+
relative = Path.relative_to_cwd(data.file)
629629

630630
IO.puts(
631631
:stderr,
632-
"[profile] #{Path.relative_to_cwd(data.file)} compiled in #{compiling}ms" <> extra
632+
"[profile] #{compiling}ms compiling + #{waiting}ms waiting for #{relative}"
633633
)
634634
end
635635

@@ -640,6 +640,13 @@ defmodule Kernel.ParallelCompiler do
640640
end)
641641
end
642642

643+
defp to_padded_ms(time) do
644+
time
645+
|> System.convert_time_unit(:native, :millisecond)
646+
|> Integer.to_string()
647+
|> String.pad_leading(6, " ")
648+
end
649+
643650
defp discard_down(pid) do
644651
receive do
645652
{:DOWN, _, :process, ^pid, _} -> :ok

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ defmodule Kernel.ParallelCompilerTest do
4343
assert HelloWorld in modules
4444
end)
4545

46-
assert profile =~ ~r"\[profile\] .*tmp/profile_time/bar.ex compiled in \d+ms"
46+
assert profile =~
47+
~r"\[profile\] [\s\d]{6}ms compiling \+ 0ms waiting for .*tmp/profile_time/bar.ex"
48+
4749
assert profile =~ ~r"\[profile\] Finished compilation cycle of 1 modules in \d+ms"
4850
assert profile =~ ~r"\[profile\] Finished group pass check of 1 modules in \d+ms"
4951
after

0 commit comments

Comments
 (0)