Skip to main content

[memorypoolview~source-code-repository:7a041dce] Added new view for garbage collecter statistics

  • From:
  • To:
  • Subject: [memorypoolview~source-code-repository:7a041dce] Added new view for garbage collecter statistics
  • Date: Tue, 16 Apr 2013 16:04:02 +0000

Project:    memorypoolview
Repository: source-code-repository
Revision:   7a041dce11ffdb8227a0651f713e085e1dc769cc
Author:     kcpeppe
Date:       2013-04-16 15:59:05 UTC
Link:       

Log Message:
------------
Added new view for garbage collecter statistics


Revisions:
----------
7a041dce11ffdb8227a0651f713e085e1dc769cc


Modified Paths:
---------------
src/com/kodewerk/visualvm/memorypools/Installer.java
src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java


Added Paths:
------------
src/com/kodewerk/visualvm/memorypools/MemoryPoolPanelPositions.java
src/com/kodewerk/visualvm/memorypools/gc/GCView.java
src/com/kodewerk/visualvm/memorypools/gc/GCViewProvider.java


Diffs:
------
diff --git a/src/com/kodewerk/visualvm/memorypools/Installer.java 
b/src/com/kodewerk/visualvm/memorypools/Installer.java
index b417cfe..cca15d4 100644
--- a/src/com/kodewerk/visualvm/memorypools/Installer.java
+++ b/src/com/kodewerk/visualvm/memorypools/Installer.java
@@ -17,6 +17,7 @@
  */
 package com.kodewerk.visualvm.memorypools;
 
+import com.kodewerk.visualvm.memorypools.gc.GCViewProvider;
 import org.openide.modules.ModuleInstall;
 
 /**
@@ -28,11 +29,13 @@ public class Installer extends ModuleInstall {
     @Override
     public void restored() {
         MemoryPoolViewProvider.initialize();
+        GCViewProvider.initialize();
     }
 
     @Override
     public void uninstalled() {
         MemoryPoolViewProvider.unregister();
+        GCViewProvider.unregister();
     }
 
 }
diff --git 
a/src/com/kodewerk/visualvm/memorypools/MemoryPoolPanelPositions.java 
b/src/com/kodewerk/visualvm/memorypools/MemoryPoolPanelPositions.java
new file mode 100644
index 0000000..e2addd8
--- /dev/null
+++ b/src/com/kodewerk/visualvm/memorypools/MemoryPoolPanelPositions.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2011-2013, Kirk Pepperdine.
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at 
http://www.opensource.org/licenses/CDDL-1.0.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ */
+
+package com.kodewerk.visualvm.memorypools;
+
+import com.kodewerk.visualvm.memorypools.gc.GarbageCollector;
+import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
+
+import java.awt.*;
+import java.util.HashMap;
+
+public class MemoryPoolPanelPositions {
+    private final HashMap<String, Point> positions = new HashMap<String, 
Point>();
+
+    private int corner = DataViewComponent.TOP_LEFT;
+    private int order = 1;
+
+    public MemoryPoolPanelPositions() {
+        // Hotspot Memory Pool Names
+        positions.put("Par Eden Space", new 
Point(DataViewComponent.TOP_LEFT, 10));
+        positions.put("PS Eden Space", new Point(DataViewComponent.TOP_LEFT, 
10));
+        positions.put("Eden Space", new Point(DataViewComponent.TOP_LEFT, 
10));
+        positions.put("G1 Eden", new Point(DataViewComponent.TOP_LEFT, 10));
+        positions.put("G1 Eden Space", new Point(DataViewComponent.TOP_LEFT, 
10));
+        positions.put("Par Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
+        positions.put("PS Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
+        positions.put("Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
+        positions.put("G1 Survivor", new Point(DataViewComponent.TOP_LEFT, 
20));
+        positions.put("G1 Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
+        
+        positions.put("Code Cache", new Point(DataViewComponent.BOTTOM_LEFT, 
10));
+        
+        positions.put("CMS Old Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
+        positions.put("PS Old Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
+        positions.put("Tenured Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
+        positions.put("G1 Old Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
+        positions.put("CMS Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
15));
+        positions.put("Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
15));
+        positions.put("PS Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
15));
+        positions.put("G1 Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
15));
+
+        //IBM Memory Pool Names
+        positions.put("Java heap", new Point(DataViewComponent.TOP_LEFT, 
10));
+        
+        positions.put("class storage", new 
Point(DataViewComponent.TOP_RIGHT, 10));
+        positions.put("miscellaneous non-heap storage", new 
Point(DataViewComponent.TOP_RIGHT, 15));
+        
+        positions.put("JIT code cache", new 
Point(DataViewComponent.BOTTOM_LEFT, 10));
+        positions.put("JIT data cache", new 
Point(DataViewComponent.BOTTOM_LEFT, 20));
+
+        // Hotspot Garbage Collectors
+        positions.put(GarbageCollector.PS_SCAVENGE.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.PS_MARK_SWEEP.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.SERIAL.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.MARK_SWEEP_COMPACT.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.PAR_NEW.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.CMS.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.G1_YOUNG.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+        positions.put(GarbageCollector.G1_OLD.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+
+    }
+
+    /**
+     * For the current Oracle JVM 5 charts are displayed. Names seem to be
+     * fixed for the moment but can change. They are also different for other
+     * JVM OEMs. So if a name cannot be found in positions the solution is 
to stack
+     * the unknown charts  in the top left. This is under the assumption that
+     * if one is unknown, the lot is likely to be unknown and any attempt
+     * to come up with a semantically reasonable ordering will most likely
+     * fail.
+     *
+     * @param name the name of the GC
+     * @return the associated position
+     */
+    public Point of(String name) {
+        Point point = positions.get(name);
+        if (point == null) {
+            point = new Point(corner, order++);
+            corner = (corner == 5) ? 1 : corner++;
+        }
+        return point;
+    }
+}
diff --git a/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java 
b/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
index 1f439a8..4e4d5d0 100644
--- a/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
+++ b/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
@@ -99,7 +99,7 @@ class MemoryPoolView extends DataSourceView {
 
     private void findMemoryPoolsAndCreatePanels() {
         findMemoryPools();
-        PanelPositions positions = new PanelPositions();
+        MemoryPoolPanelPositions positions = new MemoryPoolPanelPositions();
         for (MemoryPoolModel model : memoryPoolModels) {
             createMemoryPoolPanelFor(model, positions);
         }
@@ -116,7 +116,7 @@ class MemoryPoolView extends DataSourceView {
         }
     }
 
-    private void createMemoryPoolPanelFor(MemoryPoolModel model, 
PanelPositions positions) {
+    private void createMemoryPoolPanelFor(MemoryPoolModel model, 
MemoryPoolPanelPositions positions) {
         MemoryPoolPanel panel = new MemoryPoolPanel(model.getName());
         model.registerView(panel);
         Point position = positions.of(model.getName());
@@ -136,7 +136,7 @@ class MemoryPoolView extends DataSourceView {
 
     private void findGarbageCollectorsAndCreatePanels() {
         findGarbageCollectors();
-        PanelPositions positions = new PanelPositions();
+        MemoryPoolPanelPositions positions = new MemoryPoolPanelPositions();
         for (GarbageCollectorModel model : garbageCollectorModels) {
             createGarbageCollectorPanelFor(model, positions);
         }
@@ -153,7 +153,7 @@ class MemoryPoolView extends DataSourceView {
         }
     }
 
-    private void createGarbageCollectorPanelFor(GarbageCollectorModel model, 
PanelPositions positions) {
+    private void createGarbageCollectorPanelFor(GarbageCollectorModel model, 
MemoryPoolPanelPositions positions) {
         GarbageCollectorPanel panel = new GarbageCollectorPanel();
         model.registerView(panel);
         Point position = positions.of(model.getName());
diff --git a/src/com/kodewerk/visualvm/memorypools/PanelPositions.java 
b/src/com/kodewerk/visualvm/memorypools/PanelPositions.java
deleted file mode 100644
index 3c8b908..0000000
--- a/src/com/kodewerk/visualvm/memorypools/PanelPositions.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2011-2013, Kirk Pepperdine.
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at 
http://www.opensource.org/licenses/CDDL-1.0.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- */
-
-package com.kodewerk.visualvm.memorypools;
-
-import com.kodewerk.visualvm.memorypools.gc.GarbageCollector;
-import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
-
-import java.awt.*;
-import java.util.HashMap;
-
-public class PanelPositions {
-    private final HashMap<String, Point> positions = new HashMap<String, 
Point>();
-
-    private int corner = DataViewComponent.TOP_LEFT;
-    private int order = 1;
-
-    public PanelPositions() {
-        // Hotspot Memory Pool Names
-        positions.put("Par Eden Space", new 
Point(DataViewComponent.TOP_LEFT, 10));
-        positions.put("PS Eden Space", new Point(DataViewComponent.TOP_LEFT, 
10));
-        positions.put("Eden Space", new Point(DataViewComponent.TOP_LEFT, 
10));
-        positions.put("G1 Eden", new Point(DataViewComponent.TOP_LEFT, 10));
-        positions.put("G1 Eden Space", new Point(DataViewComponent.TOP_LEFT, 
10));
-        positions.put("Par Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
-        positions.put("PS Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
-        positions.put("Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
-        positions.put("G1 Survivor", new Point(DataViewComponent.TOP_LEFT, 
20));
-        positions.put("G1 Survivor Space", new 
Point(DataViewComponent.TOP_LEFT, 20));
-        positions.put("CMS Old Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("PS Old Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("Tenured Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("G1 Old Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("CMS Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("PS Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("G1 Perm Gen", new Point(DataViewComponent.TOP_RIGHT, 
10));
-        positions.put("Code Cache", new Point(DataViewComponent.BOTTOM_LEFT, 
10));
-
-        //IBM Memory Pool Names
-        positions.put("Java heap", new Point(DataViewComponent.TOP_LEFT, 
10));
-        positions.put("class storage", new 
Point(DataViewComponent.TOP_RIGHT, 10));
-        positions.put("miscellaneous non-heap storage", new 
Point(DataViewComponent.TOP_RIGHT, 10));
-        positions.put("JIT code cache", new 
Point(DataViewComponent.BOTTOM_LEFT, 10));
-        positions.put("JIT data cache", new 
Point(DataViewComponent.BOTTOM_LEFT, 20));
-
-        // Hotspot Garbage Collectors
-        positions.put(GarbageCollector.PS_SCAVENGE.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.PS_MARK_SWEEP.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.SERIAL.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.MARK_SWEEP_COMPACT.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.PAR_NEW.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.CMS.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.G1_YOUNG.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-        positions.put(GarbageCollector.G1_OLD.getName(), new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
-
-    }
-
-    /**
-     * For the current Oracle JVM 5 charts are displayed. Names seem to be
-     * fixed for the moment but can change. They are also different for other
-     * JVM OEMs. So if a name cannot be found in positions the solution is 
to stack
-     * the unknown charts  in the top left. This is under the assumption that
-     * if one is unknown, the lot is likely to be unknown and any attempt
-     * to come up with a semantically reasonable ordering will most likely
-     * fail.
-     *
-     * @param name the name of the GC
-     * @return the associated position
-     */
-    public Point of(String name) {
-        Point point = positions.get(name);
-        if (point == null) {
-            point = new Point(corner, order++);
-            corner = (corner == 5) ? 1 : corner++;
-        }
-        return point;
-    }
-}
diff --git a/src/com/kodewerk/visualvm/memorypools/gc/GCView.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GCView.java
new file mode 100644
index 0000000..ab6114e
--- /dev/null
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GCView.java
@@ -0,0 +1,64 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.kodewerk.visualvm.memorypools.gc;
+
+import com.sun.tools.visualvm.application.Application;
+import com.sun.tools.visualvm.core.ui.DataSourceView;
+import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
+import com.sun.tools.visualvm.tools.jmx.JmxModel;
+import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.swing.ImageIcon;
+import org.openide.util.ImageUtilities;
+
+/**
+ *
+ * @author kirk
+ */
+public class GCView extends DataSourceView {
+    
+    private final static ObjectName GARBAGE_COLLECTOR_WILDCARD_PATTERN = 
createGarbageCollectorWilcardPattern();
+    private final static ObjectName MEMORY_POOL_WILDCARD_PATTERN = 
createMemoryPoolWilcardPattern();
+    private static final String IMAGE_PATH = 
"com/kodewerk/visualvm/memorypools/resources/monitor.png";
+
+    //private final ArrayList<MemoryPoolModel> memoryPoolModels = new 
ArrayList<MemoryPoolModel>();
+    private final Set<GarbageCollectorModel> garbageCollectorModels = new 
TreeSet<GarbageCollectorModel>(GarbageCollectorModel.compareOnGeneration());
+    private DataViewComponent dvc;
+
+    public static MBeanServerConnection getMBeanServerConnection(Application 
application) {
+        JmxModel jmx = JmxModelFactory.getJmxModelFor(application);
+        return jmx == null ? null : jmx.getMBeanServerConnection();
+    }
+
+    private static ObjectName createGarbageCollectorWilcardPattern() {
+        try {
+            return new ObjectName("java.lang:type=GarbageCollector,name=*");
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
+    private static ObjectName createMemoryPoolWilcardPattern() {
+        try {
+            return new ObjectName("java.lang:type=MemoryPool,name=*");
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
+    public GCView(Application application) {
+        super(application, "Garbage Collector Activity", new 
ImageIcon(ImageUtilities.loadImage(IMAGE_PATH, true)).getImage(), 60, false);
+    }
+
+    @Override
+    protected DataViewComponent createComponent() {
+
+        return null;
+    }
+    
+}
diff --git a/src/com/kodewerk/visualvm/memorypools/gc/GCViewProvider.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GCViewProvider.java
new file mode 100644
index 0000000..ea1ea80
--- /dev/null
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GCViewProvider.java
@@ -0,0 +1,58 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.kodewerk.visualvm.memorypools.gc;
+
+import com.sun.tools.visualvm.application.Application;
+import com.sun.tools.visualvm.core.ui.DataSourceView;
+import com.sun.tools.visualvm.core.ui.DataSourceViewProvider;
+import com.sun.tools.visualvm.core.ui.DataSourceViewsManager;
+import com.sun.tools.visualvm.tools.jmx.JmxModel;
+import com.sun.tools.visualvm.tools.jmx.JmxModelFactory;
+import java.io.IOException;
+import java.util.Set;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author kirk
+ */
+public class GCViewProvider extends DataSourceViewProvider<Application> {
+    
+    private static DataSourceViewProvider<Application> instance =  new 
GCViewProvider();
+
+    @Override
+    public boolean supportsViewFor(final Application application) {
+        return false;
+        /*
+        JmxModel jmx = JmxModelFactory.getJmxModelFor(application);
+        if (jmx != null && jmx.getConnectionState() == 
JmxModel.ConnectionState.CONNECTED) {
+            MBeanServerConnection connection = 
jmx.getMBeanServerConnection();
+            try {
+                Set<ObjectName> objectNames = 
connection.queryNames(ObjectName.WILDCARD, null);
+                return ! objectNames.isEmpty();
+            } catch (IOException e) {
+                Exceptions.printStackTrace(e);
+            }
+        }
+        return false; */
+    }
+
+    @Override
+    public synchronized DataSourceView createView(final Application 
application) {
+        return new GCView(application);
+
+    }
+
+    public static void initialize() {
+        DataSourceViewsManager.sharedInstance().addViewProvider(instance, 
Application.class);
+    }
+
+    public static void unregister() {
+        DataSourceViewsManager.sharedInstance().removeViewProvider(instance);
+    }
+    
+}




[memorypoolview~source-code-repository:7a041dce] Added new view for garbage collecter statistics

kcpeppe 04/16/2013
 
 
Close
loading
Please Confirm
Close