Skip to content

Commit

Permalink
Add debug help to find out what's compiling
Browse files Browse the repository at this point in the history
We sometimes see that tests take long time or loop infinitely. Then the first
problem is to find out which test caused this behavior. This can now be shown
by turning on a new flag `debugPrintProgress` in `Run.scala`. If that flag is
set to `true`, the compiler will print out each 10 seconds the list of
currently compiled source files.
  • Loading branch information
odersky committed Feb 5, 2025
1 parent 81e057a commit b701e30
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Run.Progress
import scala.compiletime.uninitialized
import dotty.tools.dotc.transform.MegaPhase
import dotty.tools.dotc.transform.Pickler.AsyncTastyHolder
import java.util.{Timer, TimerTask}

/** A compiler run. Exports various methods to compile source files */
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
Expand Down Expand Up @@ -382,7 +383,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
initializeAsyncTasty()
else () => {}

runPhases(allPhases = fusedPhases)(using runCtx)
showProgress(runPhases(allPhases = fusedPhases)(using runCtx))
cancelAsyncTasty()

ctx.reporter.finalizeReporting()
Expand Down Expand Up @@ -433,6 +434,26 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
process()(using unitCtx)
}

/** If set to true, prints every 10 seconds the files currently being compiled.
* Turn this flag on if you want to find out which test among many takes more time than
* the others or loops infinitely.
*/
private inline val debugPrintProgress = false

/** Period between progress reports, in ms */
private inline val printProgressPeriod = 10000

/** Shows progress if debugPrintProgress is true */
private def showProgress(proc: => Unit)(using Context): Unit =
if !debugPrintProgress then proc
else
val watchdog = new TimerTask:
def run() = println(i"[compiling $units]")
try
new Timer().schedule(watchdog, printProgressPeriod, printProgressPeriod)
proc
finally watchdog.cancel()

private sealed trait PrintedTree
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
private object NoPrintedTree extends PrintedTree
Expand Down

0 comments on commit b701e30

Please sign in to comment.