river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sijs...@apache.org
Subject svn commit: r1466426 - /river/jtsk/skunk/sijskes/SimpleJeri/Heapdumper.java
Date Wed, 10 Apr 2013 11:14:30 GMT
Author: sijskes
Date: Wed Apr 10 11:14:30 2013
New Revision: 1466426

URL: http://svn.apache.org/r1466426
Log:
incomplete heapdumper code drop

Added:
    river/jtsk/skunk/sijskes/SimpleJeri/Heapdumper.java

Added: river/jtsk/skunk/sijskes/SimpleJeri/Heapdumper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/sijskes/SimpleJeri/Heapdumper.java?rev=1466426&view=auto
==============================================================================
--- river/jtsk/skunk/sijskes/SimpleJeri/Heapdumper.java (added)
+++ river/jtsk/skunk/sijskes/SimpleJeri/Heapdumper.java Wed Apr 10 11:14:30 2013
@@ -0,0 +1,72 @@
+/*
+ *  Heapdumper.java
+ * 
+ *  Created on 09-Nov-2012 11:44:07 by sim
+ * 
+ */
+
+package nl.qcg.util.debug;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import nl.qcg.util.logging.LogUtil;
+
+/**
+ *
+ * @author sim
+ */
+public class Heapdumper
+{
+    private final static Logger logger = LogUtil.getLogger();
+
+    public static void generate( boolean gc )
+    {
+        try {
+            generate0(gc);
+        } catch (Exception ex) {
+            logger.log(Level.SEVERE, null, ex);
+        }
+    }
+
+    public static void generate0( boolean gc ) throws Exception
+    {
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+        ObjectName nm = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
+
+        String filename = findFreeSlot() ;
+
+        mbs.invoke(nm, "dumpHeap", new Object[]{filename,gc}, new String[]{ String.class.getName(),
boolean.class.getName()} );
+
+        logger.log( Level.INFO, "heapdump to {0} succesfull ", filename);
+    }
+
+    public static void main(String[] args)
+    {
+        generate(true);
+    }
+
+    private static String findFreeSlot()
+    {
+        File dir = new File( "dumps" );
+
+        dir.mkdirs();
+
+        for(int i=0;i<3;i++) {
+            File f = new File(dir,"heapdump-"+i+".bin");
+            if( !f.exists() ) {
+                return f.getAbsolutePath();
+            }
+        }
+        throw new RuntimeException("slots exhausted");
+    }
+
+    private Heapdumper()
+    {
+    }
+
+}



Mime
View raw message