(从这里转贴)
我正在尝试测量/记录任务的运行时间。
我已经研究过通过在之前添加一个任务和之后添加一个任务来“包装”一个任务,但这不会每次都有效,因为 sbt 只能保证部分顺序。
更好的包装应该是这样的:
wrappedTask := {
startMeasuringTime()
somehowInvoke(myTaskKey in SomeContext)
endMeasuringTime()
}
这个“somehowInvoke”应该是什么?
Measuring the time taken by a task needs support from the task executor. As you imply, you cannot do this only by using task primitives. I've pushed some sample code that I wrote a while back that shows the idea.
A complication that the sample code doesn't handle is that what the user conceptually thinks of as one task (compile, for example) may actually be implemented as several tasks and those timings would need to be combined. Also, a task like internalDependencyClasspath
"calls" other tasks (flatMap) and so its execution time includes the execution time of the "called" tasks.
EDIT: This was implemented for 0.13.0 as an experimental feature in 602c1759a1885 and 1cc2f57e158389759. The ExecuteProgress interface provides sufficient information that the previously described issues are not a problem.