Skip to content

Commit b701e30

Browse files
committed
Add debug help to find out what's compiling
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.
1 parent 81e057a commit b701e30

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Run.Progress
3838
import scala.compiletime.uninitialized
3939
import dotty.tools.dotc.transform.MegaPhase
4040
import dotty.tools.dotc.transform.Pickler.AsyncTastyHolder
41+
import java.util.{Timer, TimerTask}
4142

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

385-
runPhases(allPhases = fusedPhases)(using runCtx)
386+
showProgress(runPhases(allPhases = fusedPhases)(using runCtx))
386387
cancelAsyncTasty()
387388

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

437+
/** If set to true, prints every 10 seconds the files currently being compiled.
438+
* Turn this flag on if you want to find out which test among many takes more time than
439+
* the others or loops infinitely.
440+
*/
441+
private inline val debugPrintProgress = false
442+
443+
/** Period between progress reports, in ms */
444+
private inline val printProgressPeriod = 10000
445+
446+
/** Shows progress if debugPrintProgress is true */
447+
private def showProgress(proc: => Unit)(using Context): Unit =
448+
if !debugPrintProgress then proc
449+
else
450+
val watchdog = new TimerTask:
451+
def run() = println(i"[compiling $units]")
452+
try
453+
new Timer().schedule(watchdog, printProgressPeriod, printProgressPeriod)
454+
proc
455+
finally watchdog.cancel()
456+
436457
private sealed trait PrintedTree
437458
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
438459
private object NoPrintedTree extends PrintedTree

0 commit comments

Comments
 (0)