任务挂钩之前/之后的 SBT [英] SBT before/after hooks for a task

查看:31
本文介绍了任务挂钩之前/之后的 SBT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(转自此处)

我正在尝试测量/记录任务的运行时间.

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

我研究了通过在之前和之后添加一个任务来包装"一个任务,但这不会每次都起作用,因为 sbt 只能保证部分顺序.

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()
}

这个somehowInvoke"应该是什么?

What should this "somehowInvoke" be?

推荐答案

测量任务所用的时间需要任务执行者的支持.正如您所暗示的,您不能仅通过使用任务原语来做到这一点.我已经推送了一些示例代码,我在不久前写的展示了这个想法.

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.

示例代码没有处理的一个复杂问题是,用户在概念上认为是一个任务(例如编译)的内容实际上可能被实现为多个任务,并且需要组合这些时间.此外,像 internalDependencyClasspath 这样的任务调用"其他任务(flatMap),因此其执行时间包括被调用"任务的执行时间.

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.

这是为 0.13.0 实现的,作为 602c18559 中的一项实验性功能1cc2f57e158389759.ExecuteProgress 接口提供了足够的信息,表明前面描述的问题不是问题.

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.

这篇关于任务挂钩之前/之后的 SBT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆