如何在 SBT 中分析任务花费的时间 [英] How to profile the time spent for a task in SBT
问题描述
我想知道为什么有时我的构建速度要慢得多.
所以我决定测量长时间运行的任务的时间.
运行纯 Scala 代码时,很容易做到:
def myMethod() = {val initTime = System.currentTimeMillis...val elapsedTime = System.currentTimeMillis-initTime}
但是对于像packageBin
或compile
这样的任务,我无法更改其源代码,我不知道如何衡量它,因为我无法控制何时someTask.value
正在运行.
有什么提示吗?
相关问题:
- <块引用>
每个输出行对应一个已执行的任务.
- 第一次是此任务运行的总时间.
- 以绿色显示的第二个时间是实际执行时间.
- 显示为红色的第三次是任务想要运行但正在等待全局常春藤锁的时间.
- 最后一次以青色显示的时间是任务被阻止等待 Ivy 下载的时间.
I'd like to know why sometimes my build is much slower.
So I've decided to measure the time of long-running taks.
When running pure Scala code, it is quite easy to do so:
def myMethod() = { val initTime = System.currentTimeMillis ... val elapsedTime = System.currentTimeMillis-initTime }
But for tasks like
packageBin
orcompile
, whose source code I cannot change, I don't know how to measure it, because I cannot control whensomeTask.value
is run.Any hint?
Related questions:
解决方案For a more complete analysis, you can also use
jrudolph/sbt-optimizer/
sbt-optimizer
is an experimental plugin that hooks into sbt's task execution engine and offers a graphical ASCII report once a tree of tasks has been runAdd the plugin to
project/plugins.sbt
:addSbtPlugin("net.virtual-void" % "sbt-optimizer" % "0.1.2")
and enable it in a project with:
enablePlugins(net.virtualvoid.optimizer.SbtOptimizerPlugin)
Each output line corresponds to one task that has been executed.
- The first time is the total time this task was running.
- The second time displayed in green is the actual execution time.
- The third time displayed in red is time the task wanted to run but was waiting for the global ivy lock.
- The last time displayed in cyan is the time the task was blocked waiting for Ivy downloads.
这篇关于如何在 SBT 中分析任务花费的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!