Clear singleton TaskProgress between runs

In db4878c786, TaskProgress became an
object which mostly made things easier to reason about. The one problem
was that it started leaking tasks with every run because the timings map
would accumulate tasks that weren't cleared. To fix this, we can clear
the timings and activeTasksMap in the TaskProgress object in the
afterAllCompleted callback. Some extra null checks needed to be added
since it's possible for the maps to not contain a previously added key
after reset has been called.
This commit is contained in:
Ethan Atkins 2020-07-17 15:49:36 -07:00
parent b678d2115f
commit d227b6423f
2 changed files with 16 additions and 3 deletions

View File

@ -42,7 +42,10 @@ private[sbt] abstract class AbstractTaskExecuteProgress extends ExecuteProgress[
}
override def afterWork[A](task: Task[A], result: Either[Task[A], Result[A]]): Unit = {
timings.get(task).stop()
timings.get(task) match {
case null =>
case t => t.stop()
}
activeTasksMap.remove(task)
// we need this to infer anonymous task names
@ -51,6 +54,11 @@ private[sbt] abstract class AbstractTaskExecuteProgress extends ExecuteProgress[
}
}
protected def reset(): Unit = {
activeTasksMap.clear()
timings.clear()
}
private[this] val taskNameCache = TrieMap.empty[Task[_], String]
protected def taskName(t: Task[_]): String =
taskNameCache.getOrElseUpdate(t, taskName0(t))

View File

@ -101,6 +101,7 @@ private[sbt] class TaskProgress private ()
}
override def afterAllCompleted(results: RMap[Task, Result]): Unit = {
reset()
// send an empty progress report to clear out the previous report
appendProgress(ProgressEvent("Info", Vector(), Some(lastTaskCount.get), None, None))
}
@ -132,8 +133,12 @@ private[sbt] class TaskProgress private ()
StandardMain.exchange.updateProgress(event)
private[this] def active: Vector[Task[_]] = activeTasks.toVector.filterNot(Def.isDummy)
private[this] def activeExceedingThreshold: Vector[(Task[_], Long)] = active.flatMap { task =>
val elapsed = timings.get(task).currentElapsedMicros
if (elapsed.micros > threshold) Some[(Task[_], Long)](task -> elapsed) else None
timings.get(task) match {
case null => None
case t =>
val elapsed = t.currentElapsedMicros
if (elapsed.micros > threshold) Some[(Task[_], Long)](task -> elapsed) else None
}
}
private[this] def report(): Unit = {
val currentTasks = activeExceedingThreshold