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.
This commit is contained in:
jvican 2017-04-19 10:12:03 +02:00 committed by Eugene Yokota
parent 9175193df3
commit d2a51d5085
1 changed files with 7 additions and 1 deletions

View File

@ -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
}
}