Skip to content

Commit c352105

Browse files
committed
Added per-file stats to -Dscala.timings.
% pscalac -Dscala.timings ./src/library/scala/util/*.scala phase id ms share ----------------------- -- ---- ----- typer 4 3632 44.73 specialize 13 1175 14.47 erasure 15 800 9.85 jvm 27 504 6.21 icode 22 427 5.26 ... ms path -------- ---------------------------------------------- 1056.667 ./src/library/scala/util/Sorting.scala 1019.369 ./src/library/scala/util/MurmurHash.scala 702.881 ./src/library/scala/util/Properties.scala 435.053 ./src/library/scala/util/Random.scala 429.702 ./src/library/scala/util/MurmurHash3.scala 246.453 ./src/library/scala/util/DynamicVariable.scala 69.755 ./src/library/scala/util/Marshal.scala
1 parent 04d13e6 commit c352105

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,14 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
343343

344344
def run() {
345345
echoPhaseSummary(this)
346-
currentRun.units foreach applyPhase
346+
currentRun.units foreach { unit =>
347+
if (opt.timings) {
348+
val start = System.nanoTime
349+
try applyPhase(unit)
350+
finally unitTimings(unit) += (System.nanoTime - start)
351+
}
352+
else applyPhase(unit)
353+
}
347354
}
348355

349356
def apply(unit: CompilationUnit): Unit
@@ -669,6 +676,21 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
669676
protected lazy val phasesSet = new mutable.HashSet[SubComponent]
670677
protected lazy val phasesDescMap = new mutable.HashMap[SubComponent, String] withDefaultValue ""
671678
private lazy val phaseTimings = new Phases.TimingModel // tracking phase stats
679+
private lazy val unitTimings = mutable.HashMap[CompilationUnit, Long]() withDefaultValue 0L // tracking time spent per unit
680+
private def unitTimingsFormatted(): String = {
681+
def toMillis(nanos: Long) = "%.3f" format nanos / 1000000d
682+
683+
val formatter = new util.TableDef[(String, String)] {
684+
>> ("ms" -> (_._1)) >+ " "
685+
<< ("path" -> (_._2))
686+
}
687+
"" + (
688+
new formatter.Table(unitTimings.toList sortBy (-_._2) map {
689+
case (unit, nanos) => (toMillis(nanos), unit.source.path)
690+
})
691+
)
692+
}
693+
672694
protected def addToPhasesSet(sub: SubComponent, descr: String) {
673695
phasesSet += sub
674696
phasesDescMap(sub) = descr
@@ -1149,8 +1171,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
11491171
if (opt.profileAll)
11501172
profiler.stopProfiling()
11511173

1152-
if (opt.timings)
1174+
if (opt.timings) {
11531175
inform(phaseTimings.formatted)
1176+
inform(unitTimingsFormatted)
1177+
}
11541178

11551179
// In case no phase was specified for -Xshow-class/object, show it now for sure.
11561180
if (opt.noShow)

0 commit comments

Comments
 (0)