Skip to content

Commit 4cc4d34

Browse files
bishaboshaKordyjan
authored andcommitted
enable ability to only record Stats.trackTime
also aggregate total phase time [Cherry-picked 4ff8d1f]
1 parent 6257957 commit 4cc4d34

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
240240

241241
for (phase <- ctx.base.allPhases)
242242
if (phase.isRunnable)
243-
Stats.trackTime(s"$phase ms ") {
243+
Stats.trackTime(s"phase time ms/$phase") {
244244
val start = System.currentTimeMillis
245245
val profileBefore = profiler.beforePhase(phase)
246246
units = phase.runOn(units)

compiler/src/dotty/tools/dotc/util/Stats.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import collection.mutable
99

1010
@sharable object Stats {
1111

12+
// when false, Stats.record and Stats.trackTime are elided.
1213
inline val enabled = false
1314

15+
// set to true if only `trackTime` should be recorded by default
16+
inline val timerOnly = false
17+
1418
var monitored: Boolean = false
1519

1620
@volatile private var stack: List[String] = Nil
@@ -19,8 +23,8 @@ import collection.mutable
1923
override def default(key: String): Int = 0
2024
}
2125

22-
inline def record(inline fn: String, inline n: Int = 1): Unit =
23-
if (enabled) doRecord(fn, n)
26+
inline def record(inline fn: String, inline n: Int = 1, inline skip: Boolean = timerOnly): Unit =
27+
if (enabled && !skip) doRecord(fn, n)
2428

2529
def doRecord(fn: String, n: Int) =
2630
if (monitored) {
@@ -38,7 +42,7 @@ import collection.mutable
3842
def doTrackTime[T](fn: String)(op: => T): T = {
3943
if (monitored) {
4044
val start = System.nanoTime
41-
try op finally record(fn, ((System.nanoTime - start) / 1000).toInt)
45+
try op finally record(fn, ((System.nanoTime - start) / 1000).toInt, skip = false)
4246
}
4347
else op
4448
}

0 commit comments

Comments
 (0)