Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

scala - SBT before/after hooks for a task

(reposted from here)

I'm trying to measure/log the running time of a task.

I've looked into "wrapping" a task by adding one task before and one task after but this would not work every time as sbt only guarantees a partial order.

A better wrapping would be something along these lines:

wrappedTask := {
  startMeasuringTime()
  somehowInvoke(myTaskKey in SomeContext)
  endMeasuringTime()
}

What should this "somehowInvoke" be?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...