New option sbt.task.timings.omit.paths, to produce even cleaner reports.

This commit is contained in:
David Perez 2015-09-30 08:52:59 +02:00 committed by Eugene Yokota
parent 6ab0bc403a
commit 618487eb58
1 changed files with 7 additions and 2 deletions

View File

@ -21,6 +21,7 @@ private[sbt] final class TaskTimings(shutdown: Boolean) extends ExecuteProgress[
private[this] val timings = new ConcurrentHashMap[Task[_], Long]
private[this] var start = 0L
private[this] val threshold = java.lang.Long.getLong("sbt.task.timings.threshold", 0L)
private[this] val omitPaths = java.lang.Boolean.getBoolean("sbt.task.timings.omit.paths")
private[this] val (unit, divider) = System.getProperty("sbt.task.timings.unit", "ms") match {
case "ns" => ("ns", 0)
case "us" => ("µs", 3)
@ -59,6 +60,8 @@ private[sbt] final class TaskTimings(shutdown: Boolean) extends ExecuteProgress[
report()
}
private val reFilePath = raw"\{[^}]+\}".r
private[this] def report() = {
val total = divide(System.nanoTime - start)
println(s"Total time: $total $unit")
@ -66,8 +69,10 @@ private[sbt] final class TaskTimings(shutdown: Boolean) extends ExecuteProgress[
def sumTimes(in: Seq[(Task[_], Long)]) = in.map(_._2).sum
val timingsByName = timings.asScala.toSeq.groupBy { case (t, time) => mappedName(t) } mapValues (sumTimes)
val times = timingsByName.toSeq.sortBy(_._2).reverse
.map { case (name, time) => (name, divide(time)) }
.filter { _._2 > threshold }
.map {
case (name, time) =>
(if (omitPaths) reFilePath.replaceFirstIn(name, "") else name, divide(time))
}.filter { _._2 > threshold }
if (times.size > 0) {
val maxTaskNameLength = times.map { _._1.length }.max
val maxTime = times.map { _._2 }.max.toString.length