Skip to content

Commit f7f82b2

Browse files
committed
Support debugging the PID in slow compilation
1 parent 64a387d commit f7f82b2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,12 @@ defmodule Kernel.ParallelCompiler do
876876
compiling = System.convert_time_unit(data.compiling, :native, :millisecond)
877877

878878
if not data.warned and compiling >= state.long_compilation_threshold do
879-
state.each_long_compilation.(data.file)
879+
if is_function(state.each_long_compilation, 2) do
880+
state.each_long_compilation.(data.file, data.pid)
881+
else
882+
state.each_long_compilation.(data.file)
883+
end
884+
880885
%{data | warned: true}
881886
else
882887
data

lib/mix/lib/mix/compilers/elixir.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,10 @@ defmodule Mix.Compilers.Elixir do
10201020
each_module: fn file, module, _binary ->
10211021
compiler_call(parent, ref, {:each_module, file, module, System.os_time(:second)})
10221022
end,
1023-
each_long_compilation: fn file ->
1023+
each_long_compilation: fn file, pid ->
10241024
Mix.shell().info(
1025-
"Compiling #{Path.relative_to(file, File.cwd!())} (it's taking more than #{threshold}s)"
1025+
"Compiling #{Path.relative_to(file, File.cwd!())} (it's taking more than #{threshold}s)" <>
1026+
"\n#{debug_stacktrace(pid)}"
10261027
)
10271028
end,
10281029
long_compilation_threshold: threshold,
@@ -1282,6 +1283,15 @@ defmodule Mix.Compilers.Elixir do
12821283
end
12831284
end
12841285

1286+
defp debug_stacktrace(pid) do
1287+
with true <- Mix.debug?(),
1288+
{:current_stacktrace, stacktrace} <- Process.info(pid, :current_stacktrace) do
1289+
Exception.format_stacktrace(stacktrace)
1290+
else
1291+
_ -> ""
1292+
end
1293+
end
1294+
12851295
## Consolidation
12861296

12871297
@doc """

0 commit comments

Comments
 (0)