From c352105fa082f88163869c0ba86f3e32aff57fc7 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 9 Dec 2011 12:36:04 -0800 Subject: 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 --- src/compiler/scala/tools/nsc/Global.scala | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index b4f14dd21b..f14474eda8 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -343,7 +343,14 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb def run() { echoPhaseSummary(this) - currentRun.units foreach applyPhase + currentRun.units foreach { unit => + if (opt.timings) { + val start = System.nanoTime + try applyPhase(unit) + finally unitTimings(unit) += (System.nanoTime - start) + } + else applyPhase(unit) + } } def apply(unit: CompilationUnit): Unit @@ -669,6 +676,21 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb protected lazy val phasesSet = new mutable.HashSet[SubComponent] protected lazy val phasesDescMap = new mutable.HashMap[SubComponent, String] withDefaultValue "" private lazy val phaseTimings = new Phases.TimingModel // tracking phase stats + private lazy val unitTimings = mutable.HashMap[CompilationUnit, Long]() withDefaultValue 0L // tracking time spent per unit + private def unitTimingsFormatted(): String = { + def toMillis(nanos: Long) = "%.3f" format nanos / 1000000d + + val formatter = new util.TableDef[(String, String)] { + >> ("ms" -> (_._1)) >+ " " + << ("path" -> (_._2)) + } + "" + ( + new formatter.Table(unitTimings.toList sortBy (-_._2) map { + case (unit, nanos) => (toMillis(nanos), unit.source.path) + }) + ) + } + protected def addToPhasesSet(sub: SubComponent, descr: String) { phasesSet += sub phasesDescMap(sub) = descr @@ -1149,8 +1171,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb if (opt.profileAll) profiler.stopProfiling() - if (opt.timings) + if (opt.timings) { inform(phaseTimings.formatted) + inform(unitTimingsFormatted) + } // In case no phase was specified for -Xshow-class/object, show it now for sure. if (opt.noShow) -- cgit v1.2.3