Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to profile the time spent for a task in SBT

Tags:

scala

sbt

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 or compile, whose source code I cannot change, I don't know how to measure it, because I cannot control when someTask.value is run.

Any hint?

Related questions:

  • Profiling sbt builds
like image 430
david.perez Avatar asked Sep 15 '15 14:09

david.perez


2 Answers

add -Dsbt.task.timings=true to your JAVA_OPTS when launching sbt

like image 104
pfn Avatar answered Oct 14 '22 19:10

pfn


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 run

Add 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)

https://raw.githubusercontent.com/jrudolph/sbt-optimizer/master/docs/example-line.png

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.
like image 25
VonC Avatar answered Oct 14 '22 19:10

VonC