diff options
author | Paul Phillips <paulp@improving.org> | 2011-01-04 01:17:32 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-01-04 01:17:32 +0000 |
commit | 234ee6d56bdbf4234f8f6f0f2ebc0560f25701ee (patch) | |
tree | 336171608f51da71ef600db63b27b265c871b373 /src/yourkit/scala/tools/util | |
parent | 266a2ca1c4ed1c655989c2435a9e83650b06f79a (diff) | |
download | scala-234ee6d56bdbf4234f8f6f0f2ebc0560f25701ee.tar.gz scala-234ee6d56bdbf4234f8f6f0f2ebc0560f25701ee.tar.bz2 scala-234ee6d56bdbf4234f8f6f0f2ebc0560f25701ee.zip |
Some profiler changes.
after each phase, so all the allocations are partitionable by phase
in the profiler. I also changed the name of -Yprofile-resident to
-Yprofile-memory and had it snapshot after the run instead of between
them, so it is usable for regular scalac usage as well.
Added tools/profile_scalac which can be used as a drop-in replacement
which handles some tedious setup. Review by dragos.
Diffstat (limited to 'src/yourkit/scala/tools/util')
-rw-r--r-- | src/yourkit/scala/tools/util/YourkitProfiling.scala | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/yourkit/scala/tools/util/YourkitProfiling.scala b/src/yourkit/scala/tools/util/YourkitProfiling.scala index 9d166d9a03..fb07eb1101 100644 --- a/src/yourkit/scala/tools/util/YourkitProfiling.scala +++ b/src/yourkit/scala/tools/util/YourkitProfiling.scala @@ -2,34 +2,57 @@ package scala.tools package util import com.yourkit.api._ +import com.yourkit.runtime._ import nsc.io._ class YourkitProfiling extends Profiling { @volatile private var active = false - private var recordAllocation = false + @volatile private var freq: Option[Int] = None lazy val controller = new Controller + def defaultFreq = 100 + def allocationFreq = freq + def setAllocationFreq(x: Int) = freq = if (x <= 0) None else Some(x) + + def startRecordingAllocations() = { + controller.startAllocationRecording(true, freq getOrElse defaultFreq, false, 0) + } + def stopRecordingAllocations() = { + controller.stopAllocationRecording() + } + 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) + try { + controller.startCPUProfiling(ProfilingModes.CPU_SAMPLING, Controller.DEFAULT_FILTERS) + if (freq.isDefined) + startRecordingAllocations() + } + catch { + case _: PresentableException => () // if it's already running, no big deal + } } } - def captureSnapshot() = - daemonize(false)(controller.captureSnapshot(ProfilingModes.SNAPSHOT_WITH_HEAP)) + def captureSnapshot() = { + daemonize(true)(controller.captureSnapshot(ProfilingModes.SNAPSHOT_WITH_HEAP)) + } def stopProfiling() = { - if (recordAllocation) - controller.stopAllocationRecording() + try { + if (freq.isDefined) + stopRecordingAllocations() - controller.stopCPUProfiling() - active = false + controller.stopCPUProfiling() + } + catch { + case _: PresentableException => () // if it's already running, no big deal + } + finally active = false } def advanceGeneration(desc: String) { @@ -37,4 +60,4 @@ class YourkitProfiling extends Profiling { } def isActive = active -}
\ No newline at end of file +} |