12

How do I run hprof from sbt?

Are there different options to profile the CPU vs. the heap?

Moritz
  • 14,144
  • 2
  • 56
  • 55
dsg
  • 12,924
  • 21
  • 67
  • 111

2 Answers2

3

I assume you don't want to profile sbt itself so you'd have to use the fork mechanism and combine with the hprof options:

override def fork = forkRun("-agentlib:hprof=heap=sites" :: Nil)

or

override def fork = Some(new ForkScalaRun { 
  override def runJVMOptions = super.runJVMOptions ++
    Seq("-Xmx1999m", "-agentlib:hprof=heap=sites") 
  override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile)
})

Here are some sample options (use -agentlib:hprof=help for more help):

Option Name and Value  Description                    Default
---------------------  -----------                    -------
heap=dump|sites|all    heap profiling                 all
cpu=samples|times|old  CPU usage                      off
huynhjl
  • 41,520
  • 14
  • 105
  • 158
  • Cool, thanks for picking this up. This is what I currently have: `override def fork = Some(new ForkScalaRun { override def runJVMOptions = super.runJVMOptions ++ Seq("-Xmx1999m") override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile) })` where would your code go? – dsg May 21 '11 at 07:12
  • 2
    @dsg - `-agentlib` is a JVM option and goes where the rest of the JVM options like `-Xmx` go. – huynhjl May 21 '11 at 13:59
1

For the sake of completeness: If you are using a traditional build.sbt, you can also use

fork in run := true

javaOptions in run += "-agentlib:hprof=heap=sites"
bluenote10
  • 23,414
  • 14
  • 122
  • 178