@@ -343,7 +343,14 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
343
343
344
344
def run () {
345
345
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
+ }
347
354
}
348
355
349
356
def apply (unit : CompilationUnit ): Unit
@@ -669,6 +676,21 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
669
676
protected lazy val phasesSet = new mutable.HashSet [SubComponent ]
670
677
protected lazy val phasesDescMap = new mutable.HashMap [SubComponent , String ] withDefaultValue " "
671
678
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
+
672
694
protected def addToPhasesSet (sub : SubComponent , descr : String ) {
673
695
phasesSet += sub
674
696
phasesDescMap(sub) = descr
@@ -1149,8 +1171,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
1149
1171
if (opt.profileAll)
1150
1172
profiler.stopProfiling()
1151
1173
1152
- if (opt.timings)
1174
+ if (opt.timings) {
1153
1175
inform(phaseTimings.formatted)
1176
+ inform(unitTimingsFormatted)
1177
+ }
1154
1178
1155
1179
// In case no phase was specified for -Xshow-class/object, show it now for sure.
1156
1180
if (opt.noShow)
0 commit comments