From b7fcc7c73e41b326fe4d85d81c49c50fa954c990 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 16 Nov 2010 23:08:45 +0000 Subject: Some profiling infrastructure. I avoided creating any dependency on yourkit. In addition, there was no way to give arguments to the JVM without losing the ones defined in ANT_OPTS, which has been a massive pain for a while. So there is now "jvm.opts" which is simply appended to ANT_OPTS, e.g. % ant -Djvm.opts=-verbose [echo] Forking with JVM opts: -Xms1536M -Xmx2g -Xss1M -XX:MaxPermSize=192M -XX:+UseParallelGC -verbose There is a minimal stub defining a profiler interface: scala.tools.util.Profiling Then the yourkit wrapper implements that interface. Once your locker has been rebuilt once, you can do this: ant yourkit.run And it will build quick.lib/comp with profiling enabled, assuming it can find the necessary files. See the yourkit.init target for values to change: or ant -Dyourkit.home=/path/to/it might be enough. Review by dragos. --- .../scala/tools/util/YourkitProfiling.scala | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/yourkit/scala/tools/util/YourkitProfiling.scala (limited to 'src/yourkit') diff --git a/src/yourkit/scala/tools/util/YourkitProfiling.scala b/src/yourkit/scala/tools/util/YourkitProfiling.scala new file mode 100644 index 0000000000..d66cdc9ee1 --- /dev/null +++ b/src/yourkit/scala/tools/util/YourkitProfiling.scala @@ -0,0 +1,36 @@ +package scala.tools +package util + +import com.yourkit.api._ +import nsc.io._ + +class YourkitProfiling extends Profiling { + @volatile private var active = false + private var recordAllocation = false + lazy val controller = new Controller + + def startProfiling(): Unit = { + if (isActive) + return + + active = true + daemonize(true) { + controller.startCPUProfiling(ProfilingModes.CPU_SAMPLING, Controller.DEFAULT_FILTERS) + if (recordAllocation) + controller.startAllocationRecording(true, 100, false, 0) + } + } + + def captureSnapshot() = + daemonize(false)(controller.captureSnapshot(ProfilingModes.SNAPSHOT_WITH_HEAP)) + + def stopProfiling() = { + if (recordAllocation) + controller.stopAllocationRecording() + + controller.stopCPUProfiling() + active = false + } + + def isActive = active +} \ No newline at end of file -- cgit v1.2.3