Skip to content

enable ability to only record Stats.trackTime #18337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint

for (phase <- ctx.base.allPhases)
if (phase.isRunnable)
Stats.trackTime(s"$phase ms ") {
Stats.trackTime(s"phase time ms/$phase") {
val start = System.currentTimeMillis
val profileBefore = profiler.beforePhase(phase)
units = phase.runOn(units)
Expand Down
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/util/Stats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import collection.mutable

@sharable object Stats {

// when false, Stats.record and Stats.trackTime are elided.
inline val enabled = false

// set to true if only `trackTime` should be recorded by default
inline val timerOnly = false

var monitored: Boolean = false

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

inline def record(inline fn: String, inline n: Int = 1): Unit =
if (enabled) doRecord(fn, n)
inline def record(inline fn: String, inline n: Int = 1, inline skip: Boolean = timerOnly): Unit =
if (enabled && !skip) doRecord(fn, n)

def doRecord(fn: String, n: Int) =
if (monitored) {
Expand All @@ -38,7 +42,7 @@ import collection.mutable
def doTrackTime[T](fn: String)(op: => T): T = {
if (monitored) {
val start = System.nanoTime
try op finally record(fn, ((System.nanoTime - start) / 1000).toInt)
try op finally record(fn, ((System.nanoTime - start) / 1000).toInt, skip = false)
}
else op
}
Expand Down