mirror of https://github.com/sbt/sbt.git
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:
parent
b678d2115f
commit
d227b6423f
|
|
@ -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 = {
|
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)
|
activeTasksMap.remove(task)
|
||||||
|
|
||||||
// we need this to infer anonymous task names
|
// 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]
|
private[this] val taskNameCache = TrieMap.empty[Task[_], String]
|
||||||
protected def taskName(t: Task[_]): String =
|
protected def taskName(t: Task[_]): String =
|
||||||
taskNameCache.getOrElseUpdate(t, taskName0(t))
|
taskNameCache.getOrElseUpdate(t, taskName0(t))
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ private[sbt] class TaskProgress private ()
|
||||||
}
|
}
|
||||||
|
|
||||||
override def afterAllCompleted(results: RMap[Task, Result]): Unit = {
|
override def afterAllCompleted(results: RMap[Task, Result]): Unit = {
|
||||||
|
reset()
|
||||||
// send an empty progress report to clear out the previous report
|
// send an empty progress report to clear out the previous report
|
||||||
appendProgress(ProgressEvent("Info", Vector(), Some(lastTaskCount.get), None, None))
|
appendProgress(ProgressEvent("Info", Vector(), Some(lastTaskCount.get), None, None))
|
||||||
}
|
}
|
||||||
|
|
@ -132,8 +133,12 @@ private[sbt] class TaskProgress private ()
|
||||||
StandardMain.exchange.updateProgress(event)
|
StandardMain.exchange.updateProgress(event)
|
||||||
private[this] def active: Vector[Task[_]] = activeTasks.toVector.filterNot(Def.isDummy)
|
private[this] def active: Vector[Task[_]] = activeTasks.toVector.filterNot(Def.isDummy)
|
||||||
private[this] def activeExceedingThreshold: Vector[(Task[_], Long)] = active.flatMap { task =>
|
private[this] def activeExceedingThreshold: Vector[(Task[_], Long)] = active.flatMap { task =>
|
||||||
val elapsed = timings.get(task).currentElapsedMicros
|
timings.get(task) match {
|
||||||
if (elapsed.micros > threshold) Some[(Task[_], Long)](task -> elapsed) else None
|
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 = {
|
private[this] def report(): Unit = {
|
||||||
val currentTasks = activeExceedingThreshold
|
val currentTasks = activeExceedingThreshold
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue