Skip to content

Commit

Permalink
Add a >0.1s timer to trace
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 16, 2024
1 parent 3458da7 commit 8d612de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ trait TraceSyntax:
(op: => T)(using Context): T =
if ctx.mode.is(Mode.Printing) || !isForced && (printer eq Printers.noPrinter) then op
else
val start = System.nanoTime
// Avoid evaluating question multiple time, since each evaluation
// may cause some extra logging output.
val q = question
Expand All @@ -109,7 +110,13 @@ trait TraceSyntax:
def finalize(msg: String) =
if !finalized then
ctx.base.indent -= 1
doLog(s"$margin$msg")
val stop = System.nanoTime
val diffNs = stop - start
val diffS = (diffNs / 1000 / 1000).toInt / 1000.0
if diffS > 0.1 then
doLog(s"$margin$msg (${"%.2f".format(diffS)} s)")
else
doLog(s"$margin$msg")
finalized = true
try
doLog(s"$margin$leading")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ trait ImportSuggestions:
end importSuggestions

/** Reduce next timeout for import suggestions by the amount of time it took
* for current search, but but never less than to half of the previous budget.
* for current search, but never less than to half of the previous budget.
*/
private def reduceTimeBudget(used: Int)(using Context) =
val run = ctx.run.nn
Expand Down

0 comments on commit 8d612de

Please sign in to comment.