From d2a51d5085392e6b0b7b88118f00247c8a788ebf Mon Sep 17 00:00:00 2001 From: jvican Date: Wed, 19 Apr 2017 10:12:03 +0200 Subject: [PATCH] Indent timing logs Sbt has a feature to show timed logs for every operation at startup. However, its output is cluttered and users cannot read how much time single methods consume nor if they call other methods. This commit improves the status quo by adding indentation. --- main/src/main/scala/sbt/internal/Load.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main/src/main/scala/sbt/internal/Load.scala b/main/src/main/scala/sbt/internal/Load.scala index 6a5f3f664..fcf5edd90 100755 --- a/main/src/main/scala/sbt/internal/Load.scala +++ b/main/src/main/scala/sbt/internal/Load.scala @@ -1015,12 +1015,18 @@ private[sbt] object Load { } } + /** Variable to control the indentation of the timing logs. */ + private var timedIndentation: Int = 0 + /** Debugging method to time how long it takes to run various compilation tasks. */ private[sbt] def timed[T](label: String, log: Logger)(t: => T): T = { + timedIndentation += 1 val start = System.nanoTime val result = t val elapsed = System.nanoTime - start - log.debug(label + " took " + (elapsed / 1e6) + " ms") + timedIndentation -= 1 + val prefix = " " * 2 * timedIndentation + log.debug(s"$prefix$label took ${elapsed / 1e6}ms") result } }