public static void dumpTo ( Resource res , boolean live ) throws IOException { MBeanServer mbserver = ManagementFactory . getPlatformMBeanServer ( ) ; HotSpotDiagnosticMXBean mxbean = ManagementFactory . newPlatformMXBeanProxy ( mbserver , "com.sun.management:type=HotSpotDiagnostic" , HotSpotDiagnosticMXBean . class ) ; String path ; Resource tmp = null ; if ( res instanceof FileResource ) path = res . getAbsolutePath ( ) ; else { tmp = SystemUtil . getTempFile ( "hprof" , false ) ; path = tmp . getAbsolutePath ( ) ; } try { // it only mxbean . dumpHeap ( path , live ) ; } finally { if ( tmp != null && tmp . exists ( ) ) { tmp . moveTo ( res ) ; } } }
Dumps the heap to the outputFile file in the same format as the hprof heap dump . If this method is called remotely from another process the heap dump output is written to a file named outputFile on the machine where the target VM is running . If outputFile is a relative path it is relative to the working directory where the target VM was started .