JvmTestHeapDumper.kt
TLDR
This file JvmTestHeapDumper.kt
contains a single object named JvmTestHeapDumper
with a method dumpHeap
that dumps the JVM heap to a file.
Methods
dumpHeap
This method takes a fileName
parameter and dumps the Java Virtual Machine (JVM) heap to a file using the HotSpotDiagnosticMXBean
provided by the com.sun.management
package.
Classes
package shark
import com.sun.management.HotSpotDiagnosticMXBean
import java.lang.management.ManagementFactory
object JvmTestHeapDumper {
private val hotspotMBean: HotSpotDiagnosticMXBean by lazy {
val mBeanServer = ManagementFactory.getPlatformMBeanServer()
ManagementFactory.newPlatformMXBeanProxy(
mBeanServer,
"com.sun.management:type=HotSpotDiagnostic",
HotSpotDiagnosticMXBean::class.java
)
}
fun dumpHeap(
fileName: String
) {
val live = true
hotspotMBean.dumpHeap(fileName, live)
}
}