jdk/src/share/classes/sun/tools/jconsole/MemoryTab.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 12851 3334e1c781d0
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import static sun.tools.jconsole.Formatter.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import static sun.tools.jconsole.OverviewPanel.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import static sun.tools.jconsole.Resources.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
class MemoryTab extends Tab implements ActionListener, ItemListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    JComboBox plotterChoice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    TimeComboBox timeComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    JButton gcButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    PlotterPanel plotterPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    JPanel bottomPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    HTMLPane details;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    PoolChart poolChart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    ArrayList<Plotter> plotterList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    Plotter heapPlotter, nonHeapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private MemoryOverviewPanel overviewPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final String usedKey        = "used";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final String committedKey   = "committed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final String maxKey         = "max";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final String thresholdKey   = "threshold";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final String usedName        = Resources.getText("Used");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final String committedName   = Resources.getText("Committed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final String maxName         = Resources.getText("Max");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final String thresholdName   = Resources.getText("Threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final Color  usedColor      = Plotter.defaultColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final Color  committedColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final Color  maxColor       = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final Color  thresholdColor = Color.red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final String infoLabelFormat = "MemoryTab.infoLabelFormat";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      Hierarchy of panels and layouts for this tab:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        MemoryTab (BorderLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            North:  topPanel (BorderLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        Center: controlPanel (FlowLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                    plotterChoice, timeComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        East:   topRightPanel (FlowLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                    gcButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            Center: plotterPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        Center: plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            South:  bottomPanel (BorderLayout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                        Center: details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        East:   poolChart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static String getTabName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return getText("Memory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public MemoryTab(VMPanel vmPanel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        super(vmPanel, getTabName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        setLayout(new BorderLayout(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        setBorder(new EmptyBorder(4, 4, 3, 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        JPanel topPanel     = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
               plotterPanel = new PlotterPanel(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
               bottomPanel  = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        add(topPanel,     BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        add(plotterPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 20, 5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        topPanel.add(controlPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // Plotter choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        plotterChoice = new JComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        plotterChoice.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        controlPanel.add(new LabeledComponent(getText("Chart:"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                              getMnemonicInt("Chart:"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                              plotterChoice));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Range control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        timeComboBox = new TimeComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        controlPanel.add(new LabeledComponent(getText("Time Range:"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                              getMnemonicInt("Time Range:"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                              timeComboBox));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        gcButton = new JButton(getText("Perform GC"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        gcButton.setMnemonic(getMnemonicInt("Perform GC"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        gcButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        gcButton.setToolTipText(getText("Perform GC.toolTip"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        JPanel topRightPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        topRightPanel.setBorder(new EmptyBorder(0, 65-8, 0, 70));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        topRightPanel.add(gcButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        topPanel.add(topRightPanel, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        bottomPanel.setBorder(new CompoundBorder(new TitledBorder(getText("Details")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                                  new EmptyBorder(10, 10, 10, 10)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        details = new HTMLPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        setAccessibleName(details, getText("Details"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        bottomPanel.add(new JScrollPane(details), BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        poolChart = new PoolChart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        bottomPanel.add(poolChart, BorderLayout.AFTER_LINE_ENDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private void createPlotters() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        plotterList = new ArrayList<Plotter>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        heapPlotter = new Plotter(Plotter.Unit.BYTES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                return Resources.getText("Heap Memory Usage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        proxyClient.addWeakPropertyChangeListener(heapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        nonHeapPlotter = new Plotter(Plotter.Unit.BYTES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                return Resources.getText("Non-Heap Memory Usage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        setAccessibleName(heapPlotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                          getText("MemoryTab.heapPlotter.accessibleName"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        setAccessibleName(nonHeapPlotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                          getText("MemoryTab.nonHeapPlotter.accessibleName"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        proxyClient.addWeakPropertyChangeListener(nonHeapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        heapPlotter.createSequence(usedKey,         usedName,      usedColor,      true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        heapPlotter.createSequence(committedKey,    committedName, committedColor, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        heapPlotter.createSequence(maxKey,          maxName,       maxColor,       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        nonHeapPlotter.createSequence(usedKey,      usedName,      usedColor,      true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        nonHeapPlotter.createSequence(committedKey, committedName, committedColor, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        nonHeapPlotter.createSequence(maxKey,       maxName,       maxColor,       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        plotterList.add(heapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        plotterList.add(nonHeapPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // Now add memory pools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Map<ObjectName, MBeanInfo> mBeanMap = proxyClient.getMBeans("java.lang");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        Set<ObjectName> keys = mBeanMap.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        ObjectName[] objectNames = keys.toArray(new ObjectName[keys.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        ArrayList<PoolPlotter> nonHeapPlotters = new ArrayList<PoolPlotter>(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        for (ObjectName objectName : objectNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            String type = objectName.getKeyProperty("type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (type.equals("MemoryPool")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                String name = getText("MemoryPoolLabel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                      objectName.getKeyProperty("name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                // Heap or non-heap?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                boolean isHeap = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                AttributeList al =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    proxyClient.getAttributes(objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                              new String[] { "Type" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (al.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    isHeap = MemoryType.HEAP.name().equals(((Attribute)al.get(0)).getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                PoolPlotter poolPlotter = new PoolPlotter(objectName, name, isHeap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                proxyClient.addWeakPropertyChangeListener(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                poolPlotter.createSequence(usedKey,      usedName,      usedColor,      true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                poolPlotter.createSequence(committedKey, committedName, committedColor, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                poolPlotter.createSequence(maxKey,       maxName,       maxColor,       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                poolPlotter.createSequence(thresholdKey, thresholdName, thresholdColor, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                poolPlotter.setUseDashedTransitions(thresholdKey, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if (isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    plotterList.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    // Will be added to plotterList below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    nonHeapPlotters.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // Add non-heap plotters last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        for (PoolPlotter poolPlotter : nonHeapPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            plotterList.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void itemStateChanged(ItemEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (ev.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            plotterPanel.setPlotter(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void gc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        new Thread("MemoryPanel.gc") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    proxyClient.getMemoryMXBean().gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    // Ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public SwingWorker<?, ?> newSwingWorker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return new SwingWorker<Boolean, Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            private long[] used, committed, max, threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            private long timeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            private String detailsStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            private boolean initialRun = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            public Boolean doInBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                if (plotterList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        createPlotters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    } catch (final IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    initialRun = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                int n = plotterList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                used      = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                committed = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                max       = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                threshold = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                timeStamp = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                int poolCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    Plotter plotter = plotterList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    MemoryUsage mu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    used[i] = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    threshold[i] = -1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                            PoolPlotter poolPlotter = (PoolPlotter)plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                            ObjectName objectName = poolPlotter.objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                            AttributeList al =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                proxyClient.getAttributes(objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                                          new String[] { "Usage", "UsageThreshold" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            if (al.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                CompositeData cd = (CompositeData)((Attribute)al.get(0)).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                mu = MemoryUsage.from(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                if (al.size() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                    threshold[i] = (Long)((Attribute)al.get(1)).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        } else if (plotter == heapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            mu = proxyClient.getMemoryMXBean().getHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        } else if (plotter == nonHeapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                            mu = proxyClient.getMemoryMXBean().getNonHeapMemoryUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    } catch (UndeclaredThrowableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        proxyClient.markAsDead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        // Skip this plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    if (mu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        used[i]      = mu.getUsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        committed[i] = mu.getCommitted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        max[i]       = mu.getMax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                detailsStr = formatDetails();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            protected void done() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    if (!get()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                } catch (InterruptedException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                } catch (ExecutionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                if (initialRun) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    // Add Memory Pools
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    for (Plotter p : plotterList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        plotterChoice.addItem(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        timeComboBox.addPlotter(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    add(bottomPanel,  BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                int n = plotterList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                int poolCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    Plotter plotter = plotterList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    if (used[i] >= 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                        if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                            plotter.addValues(timeStamp, used[i], committed[i], max[i], threshold[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                            if (threshold[i] > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                plotter.setIsPlotted(thresholdKey, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                            poolChart.setValue(poolCount++, (PoolPlotter)plotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                               used[i], threshold[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                            plotter.addValues(timeStamp, used[i], committed[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        if (plotter == heapPlotter && overviewPanel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                            overviewPanel.getPlotter().addValues(timeStamp, used[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                            overviewPanel.updateMemoryInfo(used[i], committed[i], max[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                details.setText(detailsStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    private String formatDetails() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (proxyClient.isDead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        String text = "<table cellspacing=0 cellpadding=0>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (plotter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        //long time = plotter.getLastTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        long time = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        String timeStamp = formatDateTime(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        text += newRow(getText("Time"), timeStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        long used = plotter.getLastValue(usedKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        long committed = plotter.getLastValue(committedKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        long max = plotter.getLastValue(maxKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        long threshold = plotter.getLastValue(thresholdKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        text += newRow(getText("Used"), formatKBytes(used));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (committed > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            text += newRow(getText("Committed"), formatKBytes(committed));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (max > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            text += newRow(getText("Max"), formatKBytes(max));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            text += newRow(getText("Usage Threshold"), formatKBytes(threshold));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            Collection<GarbageCollectorMXBean> garbageCollectors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                proxyClient.getGarbageCollectorMXBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            boolean descPrinted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                String gcName = garbageCollectorMBean.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                long gcCount = garbageCollectorMBean.getCollectionCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                long gcTime = garbageCollectorMBean.getCollectionTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                String str = getText("GC time details", justify(formatTime(gcTime), 14),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                     gcName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                     String.format("%,d",gcCount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                if (!descPrinted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    text += newRow(getText("GC time"), str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    descPrinted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    text += newRow(null, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        Object src = ev.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        if (src == gcButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private class PoolPlotter extends Plotter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        ObjectName objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        boolean isHeap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        long value, threshold, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        int barX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        public PoolPlotter(ObjectName objectName, String name, boolean isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            super(Plotter.Unit.BYTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            this.objectName = objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            this.name       = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            this.isHeap     = isHeap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            setAccessibleName(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                              getText("MemoryTab.poolPlotter.accessibleName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                      name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    private class PoolChart extends BorderedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                            implements Accessible, MouseListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        final int height       = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        final int leftMargin   =  50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        final int rightMargin  =  23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        final int bottomMargin =  35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        final int barWidth     =  22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        final int barGap       =   3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        final int groupGap     =   8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        final int barHeight    = height * 2 / 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        final Color greenBar           = new Color(100, 255, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        final Color greenBarBackground = new Color(210, 255, 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        final Color redBarBackground   = new Color(255, 210, 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        Font smallFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        ArrayList<PoolPlotter> poolPlotters = new ArrayList<PoolPlotter>(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        int nHeapPools    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        int nNonHeapPools = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        Rectangle heapRect    = new Rectangle(leftMargin,            height - bottomMargin + 6, barWidth, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        Rectangle nonHeapRect = new Rectangle(leftMargin + groupGap, height - bottomMargin + 6, barWidth, 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        public PoolChart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            super(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            setFocusable(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        public void setValue(int poolIndex, PoolPlotter poolPlotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                             long value, long threshold, long max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            poolPlotter.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            poolPlotter.threshold = threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            poolPlotter.max = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (poolIndex == poolPlotters.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                poolPlotters.add(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                if (poolPlotter.isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    poolPlotter.barX = nHeapPools * (barWidth + barGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    nHeapPools++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    heapRect.width = nHeapPools * barWidth + (nHeapPools - 1) * barGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    nonHeapRect.x  = leftMargin + heapRect.width + groupGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    poolPlotter.barX = nonHeapRect.x - leftMargin + nNonHeapPools * (barWidth + barGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    nNonHeapPools++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    nonHeapRect.width = nNonHeapPools * barWidth + (nNonHeapPools - 1) * barGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                poolPlotters.set(poolIndex, poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        private void paintPoolBar(Graphics g, PoolPlotter poolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            Rectangle barRect = getBarRect(poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            g.setColor(Color.gray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            g.drawRect(barRect.x, barRect.y, barRect.width, barRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            long value = poolPlotter.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            long max   = poolPlotter.max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            if (max > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                g.translate(barRect.x, barRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                // Paint green background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                g.setColor(greenBarBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                g.fillRect(1, 1, barRect.width - 1, barRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                int greenHeight = (int)(value * barRect.height / max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                long threshold = poolPlotter.threshold;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                if (threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    int redHeight = (int)(threshold * barRect.height / max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    // Paint red background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    g.setColor(redBarBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    g.fillRect(1, 1, barRect.width - 1, barRect.height - redHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    if (value > threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        // Over threshold, paint red bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                        g.setColor(thresholdColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        g.fillRect(1, barRect.height - greenHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                   barRect.width - 1, greenHeight - redHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        greenHeight = redHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                // Paint green bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                g.setColor(greenBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                g.fillRect(1, barRect.height - greenHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                           barRect.width - 1, greenHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                g.translate(-barRect.x, -barRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            if (poolPlotters.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (smallFont == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                smallFont = g.getFont().deriveFont(9.0F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            // Paint background for chart area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            Rectangle r = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            g.fillRect(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            g.setFont(smallFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            FontMetrics fm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            int fontDescent = fm.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            // Paint percentage axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            g.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            for (int pc : new int[] { 0, 25, 50, 75, 100 }) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                String str = pc + "% --";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                g.drawString(str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                             leftMargin - fm.stringWidth(str) - 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                             height - bottomMargin - (pc * barHeight / 100) + fontDescent + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                paintPoolBar(g, poolPlotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            g.setColor(Color.gray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            g.drawRect(heapRect.x,    heapRect.y,    heapRect.width,    heapRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            g.drawRect(nonHeapRect.x, nonHeapRect.y, nonHeapRect.width, nonHeapRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            Color heapColor    = greenBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            Color nonHeapColor = greenBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                if (poolPlotter.threshold > 0L && poolPlotter.value > poolPlotter.threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    if (poolPlotter.isHeap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        heapColor = thresholdColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        nonHeapColor = thresholdColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            g.setColor(heapColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            g.fillRect(heapRect.x + 1,    heapRect.y + 1,    heapRect.width - 1,    heapRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            g.setColor(nonHeapColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            g.fillRect(nonHeapRect.x + 1, nonHeapRect.y + 1, nonHeapRect.width - 1, nonHeapRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            String str = getText("Heap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            int stringWidth = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            int x = heapRect.x + (heapRect.width - stringWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            int y = heapRect.y + heapRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            g.drawString(str, x-1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            g.drawString(str, x+1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            g.drawString(str, x-1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            g.drawString(str, x+1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            g.drawString(str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            str = getText("Non-Heap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            stringWidth = fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            x = nonHeapRect.x + (nonHeapRect.width - stringWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            y = nonHeapRect.y + nonHeapRect.height - 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            g.drawString(str, x-1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            g.drawString(str, x+1, y-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            g.drawString(str, x-1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            g.drawString(str, x+1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            g.drawString(str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            // Highlight current plotter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            g.setColor(Color.blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            Plotter plotter = (Plotter)plotterChoice.getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            if (plotter == heapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                r = heapRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            } else if (plotter == nonHeapPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                r = nonHeapRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            } else if (plotter instanceof PoolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                r = getBarRect((PoolPlotter)plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (r != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                g.drawRect(r.x - 1, r.y - 1, r.width + 2, r.height + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        private Rectangle getBarRect(PoolPlotter poolPlotter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            return new Rectangle(leftMargin + poolPlotter.barX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                 height - bottomMargin - barHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                 barWidth, barHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            return new Dimension(nonHeapRect.x + nonHeapRect.width + rightMargin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                                 height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            Plotter plotter = getPlotter(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (plotter != null && plotter != plotterChoice.getSelectedItem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                plotterChoice.setSelectedItem(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        public String getToolTipText(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            Plotter plotter = getPlotter(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            return (plotter != null) ? plotter.toString() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        private Plotter getPlotter(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            Plotter plotter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (heapRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                plotter = heapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            } else if (nonHeapRect.contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                plotter = nonHeapPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    if (getBarRect(poolPlotter).contains(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                        plotter = poolPlotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        public void mousePressed(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        public void mouseReleased(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        public void mouseEntered(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        public void mouseExited(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                accessibleContext = new AccessiblePoolChart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        protected class AccessiblePoolChart extends AccessibleJPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                String name = getText("MemoryTab.poolChart.accessibleName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                String keyValueList = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                for (PoolPlotter poolPlotter : poolPlotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                    String value = (poolPlotter.value * 100 / poolPlotter.max) + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    // Assume format string ends with newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    keyValueList +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                        getText("Plotter.accessibleName.keyAndValue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                                poolPlotter.toString(), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    if (poolPlotter.threshold > 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                        String threshold =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                            (poolPlotter.threshold * 100 / poolPlotter.max) + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                        if (poolPlotter.value > poolPlotter.threshold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                            keyValueList +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                                getText("MemoryTab.poolChart.aboveThreshold",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                                        threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                            keyValueList +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                getText("MemoryTab.poolChart.belowThreshold",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                                        threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                return name + "\n" + keyValueList + ".";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    OverviewPanel[] getOverviewPanels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (overviewPanel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            overviewPanel = new MemoryOverviewPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return new OverviewPanel[] { overviewPanel };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    private static class MemoryOverviewPanel extends OverviewPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        MemoryOverviewPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            super(getText("Heap Memory Usage"), usedKey, usedName, Plotter.Unit.BYTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        private void updateMemoryInfo(long used, long committed, long max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            getInfoLabel().setText(getText(infoLabelFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                                           formatBytes(used, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                                           formatBytes(committed, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                           formatBytes(max, true)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
}