From 8d612de7b0e9a07711db86e6cbc1a7e04194b847 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 16 Oct 2024 20:35:54 +0100 Subject: [PATCH] Add a >0.1s timer to trace --- compiler/src/dotty/tools/dotc/reporting/trace.scala | 9 ++++++++- .../src/dotty/tools/dotc/typer/ImportSuggestions.scala | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/trace.scala b/compiler/src/dotty/tools/dotc/reporting/trace.scala index 732e779e9bf7..7f05cffb422a 100644 --- a/compiler/src/dotty/tools/dotc/reporting/trace.scala +++ b/compiler/src/dotty/tools/dotc/reporting/trace.scala @@ -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 @@ -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") diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index 8f8c51e2f566..3ae533d58b2e 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -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